52 #ifndef SHARK_ALGORITHMS_KERNELBUDGETEDSGDTRAINER_H 53 #define SHARK_ALGORITHMS_KERNELBUDGETEDSGDTRAINER_H 96 template <
class InputType,
class CacheType =
float>
136 const LossType* loss,
139 bool unconstrained =
false,
221 return "KernelBudgetedSGDTrainer";
273 preinitializedBudgetVectors.element(j) = dataset.
element(b);
301 RealMatrix &budgetAlpha = budgetModel.
alpha();
307 std::size_t iterations;
312 iterations = std::max(10 * ell, std::size_t (std::ceil(
m_C * ell)));
322 size_t c = preinitializedBudgetVectors.labels().element(j);
323 budgetAlpha(j, c) = 1 / (1 +
lambda);
324 budgetAlpha(j, (c + 1) % classes) = -1 / (1 +
lambda);
336 RealVector predictions(classes, 0.0);
337 RealVector derivative(classes, 0.0);
343 for(std::size_t iter = 0; iter < iterations; iter++)
361 RealVector predictionsCopy = predictions;
362 unsigned int trueClass = y[b];
363 double scoreOfTrueClass = predictions[trueClass];
364 predictions[trueClass] = -std::numeric_limits<double>::infinity();
365 unsigned int runnerupClass = (
unsigned int)arg_max(predictions);
366 double scoreOfRunnerupClass = predictions[runnerupClass];
371 budgetModel.
alpha() *= ((
long double)(1.0 - 1.0 / (iter + 1.0)));
374 if(scoreOfTrueClass - scoreOfRunnerupClass <
m_minMargin)
384 predictions[trueClass] = 1.0 / ((
long double)(iter + 1.0) *
lambda);
387 predictions[runnerupClass] = -1.0 / ((
long double)(iter + 1.0) *
lambda);
469 m_C = newParameters.back();