37 #ifndef SHARK_ALGORITHMS_MCREINFORCEDSVMTRAINER_H 38 #define SHARK_ALGORITHMS_MCREINFORCEDSVMTRAINER_H 60 template <
class InputType,
class CacheType =
float>
75 : base_type(kernel, C, unconstrained)
80 {
return "McReinforcedSvmTrainer"; }
88 RealMatrix linear(ic, classes, 1.0);
98 linear(i, l) = classes - 1.0;
105 for (
unsigned int r=0, y=0; y<classes; y++)
107 for (
unsigned int p=0; p<classes; p++, r++)
109 nu.
add(r, p, (QpFloatType)((p == y) ? 1.0 : -1.0));
114 QpFloatType c_ne = (
QpFloatType)(-1.0 / (
double)classes);
116 for (
unsigned int r=0, yv=0; yv<classes; yv++)
118 for (
unsigned int pv=0; pv<classes; pv++)
120 QpFloatType sign =
QpFloatType((yv == pv) ? -1 : 1);
121 for (
unsigned int yw=0; yw<classes; yw++, r++)
126 M.
add(r, pv, -sign * c_eq);
130 M.
add(r, pv, sign * c_eq);
131 M.
add(r, yw, -sign * c_ne);
143 RealMatrix alpha(ic,classes,0.0);
144 RealVector bias(classes,0.0);
148 PrecomputedMatrixType matrix(&km);
160 alpha = problem.solution();
176 alpha = problem.solution();
182 for (std::size_t i=0; i<ic; i++)
184 unsigned int y = dataset.
element(i).label;
185 for (
unsigned int c=0; c<classes; c++)
188 unsigned int r = classes * y;
189 for (
unsigned int p=0; p<classes; p++, r++)
190 sum += nu(r, c) * alpha(i, p);
204 template <
class InputType>
215 {
return "LinearMcSvmReinforcedTrainer"; }