50 #ifndef SHARK_MODELS_MERGEBUDGETMAINTENANCESTRATEGY_H 51 #define SHARK_MODELS_MERGEBUDGETMAINTENANCESTRATEGY_H 82 template<
class InputType>
118 {
return "MergingProblemFunction"; }
151 virtual double eval(RealVector
const& pattern)
const 153 double h = pattern(0);
155 return (- (m_a * pow(m_k, (1.0 - h) * (1.0 - h)) + m_b * pow(m_k, h * h)));
171 derivative(0) = 2 * log(m_k) * (-m_a * (h - 1.0) * pow(m_k, (h - 1.0) * (h - 1.0))
172 - m_b * h * pow(m_k, (h * h)));
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();
332 model.
basis().
element(maxIndex - 1) = supportVector.input;
333 row(model.
alpha(), maxIndex - 1) = alpha;
339 size_t firstIndex = 0;
340 double firstAlpha = 0;
345 if(firstAlpha == 0.0f)
349 model.
basis().
element(firstIndex) = supportVector.input;
350 row(model.
alpha(), firstIndex) = alpha;
353 row(model.
alpha(), maxIndex - 1).clear();
363 reduceBudget(model, firstIndex);
369 {
return "MergeBudgetMaintenanceStrategy"; }