50 #ifndef SHARK_MODELS_MERGEBUDGETMAINTENANCESTRATEGY_H 51 #define SHARK_MODELS_MERGEBUDGETMAINTENANCESTRATEGY_H 83 template<
class InputType>
88 typedef typename DataType::element_type
ElementType;
110 throw(
SHARKEXCEPTION(
"MergeBudgetMaintenanceStrategy: There is no default merging strategy for the InputType you provided! Please specialize this class."));
116 {
return "MergeBudgetMaintenanceStrategy"; }
158 {
return "MergingProblemFunction"; }
191 virtual double eval(RealVector
const& pattern)
const 193 double h = pattern(0);
195 return (- (m_a * pow(m_k, (1.0 - h) * (1.0 - h)) + m_b * pow(m_k, h * h)));
211 derivative(0) = 2 * log(m_k) * (-m_a * (h - 1.0) * pow(m_k, (h - 1.0) * (h - 1.0))
212 - m_b * h * pow(m_k, (h * h)));
235 for(
size_t j = 0; j < maxIndex; j++)
244 double minDegradation = std::numeric_limits<double>::infinity();
246 double minAlphaMergedFirst = 0.0;
247 double minAlphaMergedSecond = 0.0;
248 size_t secondIndex = 0;
252 RealMatrix &alpha = model.
alpha();
253 for(
size_t currentIndex = 0; currentIndex < maxIndex; currentIndex++)
256 if(firstIndex == currentIndex)
263 for(
size_t c = 0; c < alpha.size2(); c++)
265 double d =
std::min(0.00001, alpha(currentIndex, c) + alpha(firstIndex, c));
266 a += alpha(firstIndex, c) / d;
267 b += alpha(currentIndex, c) / d;
274 double k = kernelRow(currentIndex);
275 MergingProblemFunction mergingProblemFunction(a, b, k);
279 detail::dlinmin(h, xi, fret, mergingProblemFunction, 0.0, 1.0);
284 RealVector firstVector = model.
basis().
element(firstIndex);
285 RealVector currentVector = model.
basis().
element(currentIndex);
286 RealVector mergedVector =
h(0) * firstVector + (1.0 -
h(0)) * currentVector;
295 long double alphaMergedFirst = pow(k, (1.0 -
h(0)) * (1.0 -
h(0)));
296 long double alphaMergedCurrent = pow(k,
h(0) *
h(0));
301 double currentDegradation = 0.0f;
302 for(
size_t c = 0; c < alpha.size2(); c++)
304 double zAlpha = alphaMergedFirst * alpha(firstIndex, c) + alphaMergedCurrent * alpha(currentIndex, c);
306 currentDegradation += pow(alpha(firstIndex, c), 2) + pow(alpha(currentIndex, c), 2) +
307 2.0 * k * alpha(firstIndex, c) * alpha(currentIndex, c) - zAlpha * zAlpha;
311 if(currentDegradation < minDegradation)
313 minDegradation = currentDegradation;
315 minAlphaMergedFirst = alphaMergedFirst;
316 minAlphaMergedSecond = alphaMergedCurrent;
317 secondIndex = currentIndex;
322 RealVector firstVector = model.
basis().
element(firstIndex);
323 RealVector secondVector = model.
basis().
element(secondIndex);
324 RealVector mergedVector = minH * firstVector + (1.0 - minH) * secondVector;
330 for(
size_t c = 0; c < alpha.size2(); c++)
332 alpha(secondIndex, c) = minAlphaMergedFirst * alpha(firstIndex, c) + minAlphaMergedSecond * alpha(secondIndex, c);
337 row(alpha, firstIndex) =
row(alpha, maxIndex - 1);
342 row(model.
alpha(), maxIndex - 1).clear();
370 model.
basis().
element(maxIndex - 1) = supportVector.input;
371 row(model.
alpha(), maxIndex - 1) = alpha;
377 size_t firstIndex = 0;
378 double firstAlpha = 0;
383 if(firstAlpha == 0.0f)
387 model.
basis().
element(firstIndex) = supportVector.input;
388 row(model.
alpha(), firstIndex) = alpha;
391 row(model.
alpha(), maxIndex - 1).clear();
401 reduceBudget(model, firstIndex);
407 {
return "MergeBudgetMaintenanceStrategy"; }