Mercurial > hg > silvet
comparison src/EM.cpp @ 85:64b08cc12da0 timing
Merge loops
author | Chris Cannam |
---|---|
date | Tue, 06 May 2014 12:39:19 +0100 |
parents | a0dedcbfa628 |
children | 6075e92d63ab |
comparison
equal
deleted
inserted
replaced
84:6df1fade65af | 85:64b08cc12da0 |
---|---|
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_pitches; |
164 Grid newShifts = m_shifts; | |
165 Grid newSources = m_sources; | |
164 | 166 |
165 for (int n = 0; n < m_noteCount; ++n) { | 167 for (int n = 0; n < m_noteCount; ++n) { |
168 | |
169 const double pitch = m_pitches[n]; | |
166 newPitches[n] = epsilon; | 170 newPitches[n] = epsilon; |
167 if (n >= m_lowestPitch && n <= m_highestPitch) { | 171 |
168 const double pitch = m_pitches[n]; | 172 for (int f = 0; f < m_shiftCount; ++f) { |
173 | |
174 const double shift = m_shifts[f][n]; | |
175 newShifts[f][n] = epsilon; | |
176 | |
169 for (int i = 0; i < m_instrumentCount; ++i) { | 177 for (int i = 0; i < m_instrumentCount; ++i) { |
178 | |
170 const double source = m_sources[i][n]; | 179 const double source = m_sources[i][n]; |
171 for (int f = 0; f < m_shiftCount; ++f) { | 180 newSources[i][n] = epsilon; |
172 const float *w = templateFor(i, n, f); | 181 |
173 const double shift = m_shifts[f][n]; | 182 const float *w = templateFor(i, n, f); |
174 const double factor = pitch * source * shift; | 183 const double factor = pitch * source * shift; |
175 for (int j = 0; j < m_binCount; ++j) { | 184 |
176 newPitches[n] += w[j] * m_q[j] * factor; | 185 for (int j = 0; j < m_binCount; ++j) { |
186 | |
187 const double contribution = w[j] * m_q[j] * factor; | |
188 | |
189 if (n >= m_lowestPitch && n <= m_highestPitch) { | |
190 newPitches[n] += contribution; | |
191 } | |
192 | |
193 newShifts[f][n] += contribution; | |
194 | |
195 if (inRange(i, n)) { | |
196 newSources[i][n] += contribution; | |
177 } | 197 } |
178 } | 198 } |
179 } | 199 } |
180 } | 200 } |
201 } | |
202 | |
203 for (int n = 0; n < m_noteCount; ++n) { | |
181 if (m_pitchSparsity != 1.0) { | 204 if (m_pitchSparsity != 1.0) { |
182 newPitches[n] = pow(newPitches[n], m_pitchSparsity); | 205 newPitches[n] = pow(newPitches[n], m_pitchSparsity); |
183 } | 206 } |
184 } | 207 if (m_sourceSparsity != 1.0) { |
185 normaliseColumn(newPitches); | |
186 | |
187 Grid newShifts = m_shifts; | |
188 | |
189 for (int f = 0; f < m_shiftCount; ++f) { | |
190 for (int n = 0; n < m_noteCount; ++n) { | |
191 const double pitch = m_pitches[n]; | |
192 const double shift = m_shifts[f][n]; | |
193 newShifts[f][n] = epsilon; | |
194 for (int i = 0; i < m_instrumentCount; ++i) { | 208 for (int i = 0; i < m_instrumentCount; ++i) { |
195 const float *w = templateFor(i, n, f); | |
196 const double source = m_sources[i][n]; | |
197 const double factor = pitch * source * shift; | |
198 for (int j = 0; j < m_binCount; ++j) { | |
199 newShifts[f][n] += w[j] * m_q[j] * factor; | |
200 } | |
201 } | |
202 } | |
203 } | |
204 normaliseGrid(newShifts); | |
205 | |
206 Grid newSources = m_sources; | |
207 | |
208 for (int i = 0; i < m_instrumentCount; ++i) { | |
209 for (int n = 0; n < m_noteCount; ++n) { | |
210 const double pitch = m_pitches[n]; | |
211 const double source = m_sources[i][n]; | |
212 newSources[i][n] = epsilon; | |
213 if (inRange(i, n)) { | |
214 for (int f = 0; f < m_shiftCount; ++f) { | |
215 const float *w = templateFor(i, n, f); | |
216 const double shift = m_shifts[f][n]; | |
217 const double factor = pitch * source * shift; | |
218 for (int j = 0; j < m_binCount; ++j) { | |
219 newSources[i][n] += w[j] * m_q[j] * factor; | |
220 } | |
221 } | |
222 } | |
223 if (m_sourceSparsity != 1.0) { | |
224 newSources[i][n] = pow(newSources[i][n], m_sourceSparsity); | 209 newSources[i][n] = pow(newSources[i][n], m_sourceSparsity); |
225 } | 210 } |
226 } | 211 } |
227 } | 212 } |
213 | |
214 normaliseColumn(newPitches); | |
215 normaliseGrid(newShifts); | |
228 normaliseGrid(newSources); | 216 normaliseGrid(newSources); |
229 | 217 |
230 m_pitches = newPitches; | 218 m_pitches = newPitches; |
231 m_shifts = newShifts; | 219 m_shifts = newShifts; |
232 m_sources = newSources; | 220 m_sources = newSources; |