⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1.m

📁 隐马尔科夫模型对文本信息进行抽取利用MATLAB实现
💻 M
字号:
% Example of fixed lag smoothingS = 2;O = 2;T = 5;data = sample_discrete([0.5 0.5], 1, T);transmat = mk_stochastic(rand(S,S));obsmat = mk_stochastic(rand(S,O));B = mk_dhmm_obs_mat(data, obsmat);prior = [0.5 0.5]';% window width 2, i.e., filteringalpha0 = forwards(prior, transmat, B);w = 2;alpha1 = zeros(S, T);t = 1;alpha1(:,t) = normalise(prior .* B(:,t));for t=2:T  [alpha1(:,t-1:t), gamma1(:,t-1:t), xi1(:,:,t-1)] = fixed_lag_smoother(w, alpha1(:,t-1), B(:,t-1:t), transmat);endassert(approxeq(alpha0, alpha1));% lag 1[alpha0, beta0, gamma0, xi0] = forwards_backwards(prior, transmat, B);D = 1;alpha1 = zeros(S, T);t = 1;alpha1(:,t) = normalise(prior .* B(:,t));for t=2:T  [alpha1(:,t-1:t), gamma1(:,t-1:t), xi1(:,:,t-1)] = fixed_lag_smoother(D, alpha1(:,t-1), B(:,t-1:t), transmat);endw = 3;alpha1 = zeros(S, T);gamma1 = zeros(S, T);xi1 = zeros(S, S, T-1);t = 1;y = data(t);b = obsmat(:, y);bwindow = b;alpha_window = normalise(prior .* b);alpha1(:,t) = alpha_window;for t=2:w  y = data(t);  b = obsmat(:, y);  bwindow = [bwindow b];  [alpha_window, gamma_window, xi_window] = fixed_lag_smoother(w, alpha_window, bwindow, transmat);  alpha1(:,1:t) = alpha_window;  gamma1(:,1:t) = gamma_window;  xi1(:,:,1:t-1) = xi_window;    endfor t=w+1:T  y = data(t);  b = obsmat(:, y);  bwindow = [bwindow(:,2:end) b];  [alpha_window, gamma_window, xi_window] = fixed_lag_smoother(D, alpha_window(:,2:end), bwindow, transmat);  alpha1(:,t-D:t) = alpha_window;  gamma1(:,t-D:t) = gamma_window;  xi1(:,:,t-D:t-1) = xi_window;    end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -