%%Doug Van Nort   MUMT 611 Final Project
%
%We train our Violin Model Here, using Baum-Welch
%
%dhmm_em is from the HMM toolbox of Kevin Murphy


O = 73;  % we first quantize to 16 possible obervations
Q = 100; % we use 10 states: 1 for each analysis frame


% initial guess of parameters - random matrices
prior1 = [1 zeros(1,Q-1)];      %we use a left-to-right model, and so this is our initial state distribution
transmat1 = mk_stochastic(rand(Q,Q));
obsmat1 = mk_stochastic(rand(Q,O));

%2,4,5,13,17,22,27,32,37,41 - left out for testing later

trdata_V = [OVL(1,:);OVL(3,:);OVL(6:12,:);OVL(14:16,:);OVL(18:21,:);OVL(23:26,:);OVL(28:31,:);OVL(33:36,:);OVL(38:40,:);OVL(42,:);...
            OVR(1,:);OVR(3,:);OVR(6:12,:);OVR(14:16,:);OVR(18:21,:);OVR(23:26,:);OVR(28:31,:);OVR(33:36,:);OVR(38:40,:);OVR(42,:)];

% improve guess of parameters using EM (Baum-Welch)

[LL, prior_V, transmat_V, obsmat_V] = dhmm_em(trdata_V, prior1, transmat1, obsmat1, 'max_iter', 5);

