How to Use the Influence Model Toolbox for Matlab ?
- In matlab shell, execute the following command (without the '>' sign). The influence model toolbox should be ready to use
> addpath 'C:\MATLAB7\work\influence'
- Let us construct a latent structure influence process with 6 interacting sub-processes, 2 latent states and 2 output symbols per sub-process.
> bnet = mk_influence(2*ones(1,6), 2*ones(1,6));
> for i=1:bnet.nchains
> for j=1:bnet.nchains
> bnet.A{i,j} = [.99 .01;.08 .92];
> end
> end
> for i=1:bnet.nchains
> %bnet.B{i} = eye(2);
> bnet.B{i} = [.9 .1;.1 .9]; % add some noises
> end
> bnet.T = 0*bnet.T;
> bnet.T(1:3,1:3) = 1/3*ones(3);
> bnet.T(4:6,4:6) = 1/3*ones(3);
- We can sample the latent structure influence process constructed above.
> seq = sample_influence(bnet,1000);
> seq0 = permute(seq(2,:,:),[2 3 1]); % observations
> seq1 = cell2num(permute(seq(1,:,:),[2 3 1])); % latent states
> imagesc(cell2num(seq0))
- Parameter learning from the above sample sequence.
> bnet1 = mk_influence(2*ones(1,6), 2*ones(1,6));
> engine = influence_inf_engine(bnet1);
> bnet1 = learn_params_influence(engine,seq0,50);
> influence = influence_matrix(bnet1);
> imagesc(influence)
- Most probable latent state estimation from the above sample sequence
> engine1 = influence_inf_engine(bnet1);
> seq2 = influence_mpe(engine1,seq0);
> for i=1:size(seq2,1)
> if sum(seq2(i,:)==1)<sum(seq2(i,:)==2)
> seq2(i,:) = 3-seq2(i,:);
>
> tmp = influence(2*i-1,:);
> influence(2*i-1,:) = influence(2*i,:);
> influence(2*i,:) = tmp;
>
> tmp = influence(:,2*i-1);
> influence(:,2*i-1) = influence(:,2*i);
> influence(:,2*i) = tmp;
> end
> end
> imagesc(seq2)
- Another example with continuous 1-d Gaussian output.
> bnet = mk_influence(2*ones(1,6), 1*ones(1,6), 'cccccc');
> for i=1:bnet.nchains
> for j=1:bnet.nchains
> bnet.A{i,j} = [.99 .01;.08 .92];
> end
> end
> for i=1:bnet.nchains
> bnet.B{i} = [-.25;.25];
> bnet.cov{i} = repmat(eye(bnet.m_outputs(i)),[1 1 bnet.n_states(1)]);
> end
> bnet.T = 0*bnet.T;
> bnet.T(1:3,1:3) = 1/3*ones(3);
> bnet.T(4:6,4:6) = 1/3*ones(3);
> seq = sample_influence(bnet,1000);
> seq0 = permute(seq(2,:,:),[2 3 1]); % observations
> bnet1 = mk_influence(2*ones(1,6), 1*ones(1,6),'cccccc');
> bnet1 = initialize_mu(bnet1,seq0);
> engine = influence_inf_engine(bnet1);
> [bnet1,ll,engine1] = learn_params_influence(engine,seq0,500);
> seq2 = influence_mpe(engine1,seq0);