annotate _dbn/inference.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function song = inference(song, bnet, param)
matthiasm@8 2
matthiasm@8 3
matthiasm@8 4 if param.dsp.separatenormalising % means that also bass and treble chroma are separate
matthiasm@8 5 evidence = cell(bnet.nnodes_per_slice,song.nBeat);
matthiasm@8 6 if param.dbn.nBass > 0
matthiasm@8 7 basschromanode = bnet.names('basschroma');
matthiasm@8 8 evidence(basschromanode,:) = ...
matthiasm@8 9 num2cell(song.segchroma.bass(:,1:param.dbn.nBass)',1);
matthiasm@8 10 end
matthiasm@8 11
matthiasm@8 12 treblechromanode = bnet.names('treblechroma');
matthiasm@8 13 evidence(treblechromanode,:) = ...
matthiasm@8 14 num2cell(song.segchroma.treble',1);
matthiasm@8 15
matthiasm@8 16 if param.dbn.inferencebypart
matthiasm@8 17 fprintf(2,' ');
matthiasm@8 18 song = integratesmallparts(song);
matthiasm@8 19 song.mpe = cell(size(evidence));
matthiasm@8 20 nIntegratedParts = numel(song.integratedparts);
matthiasm@8 21 if param.dbn.infermpe
matthiasm@8 22 for iIP = 1:nIntegratedParts
matthiasm@8 23 startind = song.integratedparts(iIP).indices; % only one index for integrated parts
matthiasm@8 24 endind = song.integratedparts(iIP).indices + song.integratedparts(iIP).n - 1;
matthiasm@8 25 leftoverlap = min(startind - 1, param.seg.inferenceoverlap);
matthiasm@8 26 rightoverlap = min(song.nBeat - endind, param.seg.inferenceoverlap);
matthiasm@8 27 currevidence = evidence(:,startind - leftoverlap:endind + rightoverlap);
matthiasm@8 28 engine = smoother_engine(jtree_2TBN_inf_engine(bnet));
matthiasm@8 29 fprintf(1,'\nFinding maximum probability path (part %1.0f of %1.0f, beats %1.0f to %1.0f)... \n', iIP, nIntegratedParts, startind, endind)
matthiasm@8 30 fprintf(2,'\b\b\b\b%3.0f%%',iIP/nIntegratedParts*100);
matthiasm@8 31 currmpe = find_mpeMM(engine, currevidence);
matthiasm@8 32 song.mpe(:,startind:endind) = currmpe(:,leftoverlap + 1:size(currmpe,2)-rightoverlap);
matthiasm@8 33 end
matthiasm@8 34 else
matthiasm@8 35 error('inference by part + mpe not yet supported');
matthiasm@8 36 end
matthiasm@8 37 else
matthiasm@8 38
matthiasm@8 39 if param.dbn.infermpe
matthiasm@8 40 engine = smoother_engine(jtree_2TBN_inf_engine(bnet));
matthiasm@8 41 fprintf(1,'\n__ Finding maximum probability path... _________\n')
matthiasm@8 42 song.mpe = find_mpeMM(engine, evidence);
matthiasm@8 43 else
matthiasm@8 44 engine = filter_engine(jtree_2TBN_inf_engine(bnet));
matthiasm@8 45 fprintf(1,'\n__ Inference... _________\n')
matthiasm@8 46 tic
matthiasm@8 47 for t = 1:song.nBeat
matthiasm@8 48 t
matthiasm@8 49 param.engine = enter_evidence(engine,[evidence{:,t}],t);
matthiasm@8 50 end
matthiasm@8 51 toc
matthiasm@8 52 song.inferred = cell(bnet.nnodes_per_slice, song.nBeat);
matthiasm@8 53 for iBeat = 1:song.nBeat
matthiasm@8 54 for iNode = 1:bnet.nnodes_per_slice-2
matthiasm@8 55 temp = marginal_nodes(engine,iNode,iBeat);
matthiasm@8 56 song.inferred{iNode, iBeat} = temp.T;
matthiasm@8 57 end
matthiasm@8 58 end
matthiasm@8 59 end
matthiasm@8 60 end
matthiasm@8 61 else
matthiasm@8 62 chromanode = bnet.names('chroma');
matthiasm@8 63
matthiasm@8 64 evidence = cell(bnet.nnodes_per_slice,song.nBeat);
matthiasm@8 65
matthiasm@8 66 evidence(chromanode,:) = ...
matthiasm@8 67 num2cell([song.segchroma.bass, song.segchroma.treble]',1);
matthiasm@8 68
matthiasm@8 69 if param.dbn.inferencebypart
matthiasm@8 70 else
matthiasm@8 71 engine = smoother_engine(jtree_2TBN_inf_engine(bnet));
matthiasm@8 72 if param.dbn.infermpe
matthiasm@8 73 fprintf(1,'\n__ Finding maximum probability path... _________\n')
matthiasm@8 74 song.mpe = find_mpe(engine, evidence);
matthiasm@8 75 else
matthiasm@8 76 fprintf(1,'\n__ Inference... _________\n')
matthiasm@8 77 tic
matthiasm@8 78 param.engine = enter_evidence(engine,evidence);
matthiasm@8 79 toc
matthiasm@8 80 song.inferred = cell(bnet.nnodes_per_slice, song.nBeat);
matthiasm@8 81 for iBeat = 1:beat.n
matthiasm@8 82 for iNode = 1:bnet.nnodes_per_slice-1
matthiasm@8 83 temp = marginal_nodes(engine,iNode,iBeat);
matthiasm@8 84 song.inferred{iNode, iBeat} = temp.T;
matthiasm@8 85 end
matthiasm@8 86 end
matthiasm@8 87 end
matthiasm@8 88 end
matthiasm@8 89 end