comparison src/EM.cpp @ 89:a6e136aaa202 timing

Initialise new vectors with epsilon instead of copying and then overwriting
author Chris Cannam
date Tue, 06 May 2014 12:56:18 +0100
parents 97b77e7cb94c
children 2b0818a1c058 840c0d703bbb 91bb029a847a
comparison
equal deleted inserted replaced
88:97b77e7cb94c 89:a6e136aaa202
158 } 158 }
159 159
160 void 160 void
161 EM::maximisation(const V &column) 161 EM::maximisation(const V &column)
162 { 162 {
163 V newPitches = m_pitches; 163 V newPitches(m_noteCount, epsilon);
164 Grid newShifts = m_shifts; 164 Grid newShifts(m_shiftCount, V(m_noteCount, epsilon));
165 Grid newSources = m_sources; 165 Grid newSources(m_instrumentCount, V(m_noteCount, epsilon));
166 166
167 for (int n = 0; n < m_noteCount; ++n) { 167 for (int n = 0; n < m_noteCount; ++n) {
168 168
169 const double pitch = m_pitches[n]; 169 const double pitch = m_pitches[n];
170 newPitches[n] = epsilon;
171 170
172 for (int f = 0; f < m_shiftCount; ++f) { 171 for (int f = 0; f < m_shiftCount; ++f) {
173 172
174 const double shift = m_shifts[f][n]; 173 const double shift = m_shifts[f][n];
175 newShifts[f][n] = epsilon;
176 174
177 for (int i = 0; i < m_instrumentCount; ++i) { 175 for (int i = 0; i < m_instrumentCount; ++i) {
178 176
179 const double source = m_sources[i][n]; 177 const double source = m_sources[i][n];
180 newSources[i][n] = epsilon; 178 const double factor = pitch * source * shift;
181
182 const double *w = templateFor(i, n, f); 179 const double *w = templateFor(i, n, f);
183 const double factor = pitch * source * shift;
184 180
185 if (n >= m_lowestPitch && n <= m_highestPitch) { 181 if (n >= m_lowestPitch && n <= m_highestPitch) {
186 182
187 for (int j = 0; j < m_binCount; ++j) { 183 for (int j = 0; j < m_binCount; ++j) {
188 newPitches[n] += w[j] * m_q[j] * factor; 184 newPitches[n] += w[j] * m_q[j] * factor;