52 #ifndef SHARK_ALGORITHMS_KERNELBUDGETEDSGDTRAINER_H 53 #define SHARK_ALGORITHMS_KERNELBUDGETEDSGDTRAINER_H 96 template <
class InputType,
class CacheType =
float>
135 const LossType* loss,
138 bool unconstrained =
false,
158 throw(
SHARKEXCEPTION(
"KernelBudgetedSGDTrainer: No budget maintenance strategy provided!"));
219 return "KernelBudgetedSGDTrainer";
271 preinitializedBudgetVectors.element(j) = dataset.
element(b);
299 RealMatrix &budgetAlpha = budgetModel.
alpha();
305 std::size_t iterations;
310 iterations =
std::max(10 * ell, std::size_t (std::ceil(
m_C * ell)));
320 size_t c = preinitializedBudgetVectors.labels().element(j);
321 budgetAlpha(j, c) = 1 / (1 +
lambda);
322 budgetAlpha(j, (c + 1) % classes) = -1 / (1 +
lambda);
334 RealVector predictions(classes, 0.0);
335 RealVector derivative(classes, 0.0);
341 for(std::size_t iter = 0; iter < iterations; iter++)
359 RealVector predictionsCopy = predictions;
360 unsigned int trueClass = y[b];
361 double scoreOfTrueClass = predictions[trueClass];
362 predictions[trueClass] = -std::numeric_limits<double>::infinity();
363 unsigned int runnerupClass = (
unsigned int)
arg_max(predictions);
364 double scoreOfRunnerupClass = predictions[runnerupClass];
369 budgetModel.
alpha() *= ((
long double)(1.0 - 1.0 / (iter + 1.0)));
372 if(scoreOfTrueClass - scoreOfRunnerupClass <
m_minMargin)
382 predictions[trueClass] = 1.0 / ((
long double)(iter + 1.0) *
lambda);
385 predictions[runnerupClass] = -1.0 / ((
long double)(iter + 1.0) *
lambda);
457 RealVector ret(kp + 1);