Mercurial > hg > nnls-chroma
changeset 106:99b87ce4bb70 monophonicness
implemented loglikelihood stuff
author | matthiasm |
---|---|
date | Sun, 19 Dec 2010 21:55:01 +0900 |
parents | 2c4ee4d8e805 |
children | ea5d533536ab |
files | Chordino.cpp Chordino.h viterbi.cpp viterbi.h |
diffstat | 4 files changed, 39 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Chordino.cpp Sat Dec 18 21:41:40 2010 +0900 +++ b/Chordino.cpp Sun Dec 19 21:55:01 2010 +0900 @@ -217,6 +217,21 @@ list.push_back(d8); m_outputHarmonicChange = index++; + OutputDescriptor meanloglikelihood; + meanloglikelihood.identifier = "meanloglikelihood"; + meanloglikelihood.name = "chord estimate mean log-likelihood"; + meanloglikelihood.description = "."; + meanloglikelihood.unit = ""; + meanloglikelihood.hasFixedBinCount = true; + meanloglikelihood.binCount = 1; + meanloglikelihood.hasKnownExtents = false; + meanloglikelihood.isQuantized = false; + meanloglikelihood.sampleType = OutputDescriptor::FixedSampleRate; + meanloglikelihood.hasDuration = false; + // meanloglikelihood.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; + list.push_back(meanloglikelihood); + m_outputMeanloglikelihood = index++; + return list; } @@ -526,8 +541,9 @@ temp[iChord] = selftransprob; trans.push_back(temp); } - vector<int> chordpath = ViterbiPath(init, trans, chordogram, delta); - + vector<double> scale; + vector<int> chordpath = ViterbiPath(init, trans, chordogram, delta, &scale); + Feature chord_feature; // chord estimate chord_feature.hasTimestamp = true; @@ -568,6 +584,20 @@ } } + float logscale = 0; + for (int iFrame = 0; iFrame < nFrame; ++iFrame) { + logscale -= log(scale[iFrame]); + Feature loglikelihood; + loglikelihood.hasTimestamp = true; + loglikelihood.timestamp = timestamps[iFrame]; + loglikelihood.values.push_back(-log(scale[iFrame])); + // cerr << chordchange[iFrame] << endl; + fsOut[m_outputMeanloglikelihood].push_back(loglikelihood); + } + logscale /= nFrame; + cerr << "loglik" << logscale << endl; + + // cerr << chordpath[0] << endl; } else { /* Simple chord estimation
--- a/Chordino.h Sat Dec 18 21:41:40 2010 +0900 +++ b/Chordino.h Sun Dec 19 21:55:01 2010 +0900 @@ -48,6 +48,7 @@ mutable int m_outputChords; mutable int m_outputChordnotes; mutable int m_outputHarmonicChange; + mutable int m_outputMeanloglikelihood; vector<float> m_chorddict; vector<vector<int> > m_chordnotes; vector<string> m_chordnames;
--- a/viterbi.cpp Sat Dec 18 21:41:40 2010 +0900 +++ b/viterbi.cpp Sun Dec 19 21:55:01 2010 +0900 @@ -2,7 +2,7 @@ #include "viterbi.h" #include <iostream> -std::vector<int> ViterbiPath(std::vector<double> init, std::vector<vector<double> > trans, std::vector<vector<double> > obs, double *delta) { +std::vector<int> ViterbiPath(std::vector<double> init, std::vector<vector<double> > trans, std::vector<vector<double> > obs, double *delta, vector<double> *scale) { int nState = init.size(); int nFrame = obs.size(); @@ -16,7 +16,7 @@ // vector<vector<double> > delta; // "matrix" of conditional probabilities vector<vector<int> > psi; // "matrix" of remembered indices of the best transitions vector<int> path = vector<int>(nFrame, nState-1); // the final output path (current assignment arbitrary, makes sense only for Chordino, where nChord-1 is the "no chord" label) - vector<double> scale = vector<double>(nFrame, 0); // remembers by how much the vectors in delta are scaled. + // vector<double> scale = vector<double>(nFrame, 0); // remembers by how much the vectors in delta are scaled. double deltasum = 0; @@ -27,7 +27,7 @@ deltasum += delta[iState]; } for (int iState = 0; iState < nState; ++iState) delta[iState] /= deltasum; // normalise (scale) - scale.push_back(1.0/deltasum); + scale->push_back(1.0/deltasum); psi.push_back(vector<int>(nState,0)); /* rest of the forward step */ @@ -57,12 +57,12 @@ for (int iState = 0; iState < nState; ++iState) { delta[iFrame * nState + iState] /= deltasum; // normalise (scale) } - scale.push_back(1.0/deltasum); + scale->push_back(1.0/deltasum); } else { for (int iState = 0; iState < nState; ++iState) { delta[iFrame * nState + iState] = 1.0/nState; } - scale.push_back(1.0); + scale->push_back(1.0); } }
--- a/viterbi.h Sat Dec 18 21:41:40 2010 +0900 +++ b/viterbi.h Sun Dec 19 21:55:01 2010 +0900 @@ -23,6 +23,6 @@ #include <string> using namespace std; -extern std::vector<int> ViterbiPath(std::vector<double> init, std::vector<vector<double> > trans, std::vector<vector<double> > obs, double *delta); +extern std::vector<int> ViterbiPath(std::vector<double> init, std::vector<vector<double> > trans, std::vector<vector<double> > obs, double *delta, vector<double> *scale); #endif \ No newline at end of file