?? example1.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 + -