194 blas::vector<float> kernelRow(maxIndex, 0.0);
195 for(
size_t j = 0; j < maxIndex; j++)
205 double minDegradation = std::numeric_limits<double>::infinity();
207 double minAlphaMergedFirst = 0.0;
208 double minAlphaMergedSecond = 0.0;
209 size_t secondIndex = 0;
213 RealMatrix &alpha = model.
alpha();
214 for(
size_t currentIndex = 0; currentIndex < maxIndex; currentIndex++)
217 if(firstIndex == currentIndex)
224 for(
size_t c = 0; c < alpha.size2(); c++)
226 double d = std::min(0.00001, alpha(currentIndex, c) + alpha(firstIndex, c));
227 a += alpha(firstIndex, c) / d;
228 b += alpha(currentIndex, c) / d;
234 double k = kernelRow(currentIndex);
235 MergingProblemFunction mergingProblemFunction(a, b, k);
236 fret = mergingProblemFunction.evalDerivative(h,d);
240 lineSearch.
init(mergingProblemFunction);
241 lineSearch(h,fret,xi,d,1.0);
246 RealVector firstVector = model.
basis().
element(firstIndex);
247 RealVector currentVector = model.
basis().
element(currentIndex);
248 RealVector mergedVector = h(0) * firstVector + (1.0 - h(0)) * currentVector;
257 long double alphaMergedFirst = pow(k, (1.0 - h(0)) * (1.0 - h(0)));
258 long double alphaMergedCurrent = pow(k, h(0) * h(0));
263 double currentDegradation = 0.0f;
264 for(
size_t c = 0; c < alpha.size2(); c++)
266 double zAlpha = alphaMergedFirst * alpha(firstIndex, c) + alphaMergedCurrent * alpha(currentIndex, c);
268 currentDegradation += pow(alpha(firstIndex, c), 2) + pow(alpha(currentIndex, c), 2) +
269 2.0 * k * alpha(firstIndex, c) * alpha(currentIndex, c) - zAlpha * zAlpha;
273 if(currentDegradation < minDegradation)
275 minDegradation = currentDegradation;
277 minAlphaMergedFirst = alphaMergedFirst;
278 minAlphaMergedSecond = alphaMergedCurrent;
279 secondIndex = currentIndex;
284 RealVector firstVector = model.
basis().
element(firstIndex);
285 RealVector secondVector = model.
basis().
element(secondIndex);
286 RealVector mergedVector = minH * firstVector + (1.0 - minH) * secondVector;
292 for(
size_t c = 0; c < alpha.size2(); c++)
294 alpha(secondIndex, c) = minAlphaMergedFirst * alpha(firstIndex, c) + minAlphaMergedSecond * alpha(secondIndex, c);
299 row(alpha, firstIndex) = row(alpha, maxIndex - 1);
304 row(model.
alpha(), maxIndex - 1).clear();