matthiasm@8: function song = inference(song, bnet, param) matthiasm@8: matthiasm@8: matthiasm@8: if param.dsp.separatenormalising % means that also bass and treble chroma are separate matthiasm@8: evidence = cell(bnet.nnodes_per_slice,song.nBeat); matthiasm@8: if param.dbn.nBass > 0 matthiasm@8: basschromanode = bnet.names('basschroma'); matthiasm@8: evidence(basschromanode,:) = ... matthiasm@8: num2cell(song.segchroma.bass(:,1:param.dbn.nBass)',1); matthiasm@8: end matthiasm@8: matthiasm@8: treblechromanode = bnet.names('treblechroma'); matthiasm@8: evidence(treblechromanode,:) = ... matthiasm@8: num2cell(song.segchroma.treble',1); matthiasm@8: matthiasm@8: if param.dbn.inferencebypart matthiasm@8: fprintf(2,' '); matthiasm@8: song = integratesmallparts(song); matthiasm@8: song.mpe = cell(size(evidence)); matthiasm@8: nIntegratedParts = numel(song.integratedparts); matthiasm@8: if param.dbn.infermpe matthiasm@8: for iIP = 1:nIntegratedParts matthiasm@8: startind = song.integratedparts(iIP).indices; % only one index for integrated parts matthiasm@8: endind = song.integratedparts(iIP).indices + song.integratedparts(iIP).n - 1; matthiasm@8: leftoverlap = min(startind - 1, param.seg.inferenceoverlap); matthiasm@8: rightoverlap = min(song.nBeat - endind, param.seg.inferenceoverlap); matthiasm@8: currevidence = evidence(:,startind - leftoverlap:endind + rightoverlap); matthiasm@8: engine = smoother_engine(jtree_2TBN_inf_engine(bnet)); matthiasm@8: 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: fprintf(2,'\b\b\b\b%3.0f%%',iIP/nIntegratedParts*100); matthiasm@8: currmpe = find_mpeMM(engine, currevidence); matthiasm@8: song.mpe(:,startind:endind) = currmpe(:,leftoverlap + 1:size(currmpe,2)-rightoverlap); matthiasm@8: end matthiasm@8: else matthiasm@8: error('inference by part + mpe not yet supported'); matthiasm@8: end matthiasm@8: else matthiasm@8: matthiasm@8: if param.dbn.infermpe matthiasm@8: engine = smoother_engine(jtree_2TBN_inf_engine(bnet)); matthiasm@8: fprintf(1,'\n__ Finding maximum probability path... _________\n') matthiasm@8: song.mpe = find_mpeMM(engine, evidence); matthiasm@8: else matthiasm@8: engine = filter_engine(jtree_2TBN_inf_engine(bnet)); matthiasm@8: fprintf(1,'\n__ Inference... _________\n') matthiasm@8: tic matthiasm@8: for t = 1:song.nBeat matthiasm@8: t matthiasm@8: param.engine = enter_evidence(engine,[evidence{:,t}],t); matthiasm@8: end matthiasm@8: toc matthiasm@8: song.inferred = cell(bnet.nnodes_per_slice, song.nBeat); matthiasm@8: for iBeat = 1:song.nBeat matthiasm@8: for iNode = 1:bnet.nnodes_per_slice-2 matthiasm@8: temp = marginal_nodes(engine,iNode,iBeat); matthiasm@8: song.inferred{iNode, iBeat} = temp.T; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: else matthiasm@8: chromanode = bnet.names('chroma'); matthiasm@8: matthiasm@8: evidence = cell(bnet.nnodes_per_slice,song.nBeat); matthiasm@8: matthiasm@8: evidence(chromanode,:) = ... matthiasm@8: num2cell([song.segchroma.bass, song.segchroma.treble]',1); matthiasm@8: matthiasm@8: if param.dbn.inferencebypart matthiasm@8: else matthiasm@8: engine = smoother_engine(jtree_2TBN_inf_engine(bnet)); matthiasm@8: if param.dbn.infermpe matthiasm@8: fprintf(1,'\n__ Finding maximum probability path... _________\n') matthiasm@8: song.mpe = find_mpe(engine, evidence); matthiasm@8: else matthiasm@8: fprintf(1,'\n__ Inference... _________\n') matthiasm@8: tic matthiasm@8: param.engine = enter_evidence(engine,evidence); matthiasm@8: toc matthiasm@8: song.inferred = cell(bnet.nnodes_per_slice, song.nBeat); matthiasm@8: for iBeat = 1:beat.n matthiasm@8: for iNode = 1:bnet.nnodes_per_slice-1 matthiasm@8: temp = marginal_nodes(engine,iNode,iBeat); matthiasm@8: song.inferred{iNode, iBeat} = temp.T; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: end