31 using namespace KKMLL;
34 using namespace SVM289_MFS;
37 #pragma warning(disable : 4996
) 47 const double* dec_values,
66 double** pairwiseProbs,
86 T* dest =
new T[newSize];
87 while (zed < origSize) {dest[zed] = src[zed]; zed++;}
88 while (zed < newSize) {dest[zed] = (T)0; zed++;}
96 double tmp = base, ret = 1.0;
98 for (
kkint32 t = times; t > 0; t /= 2)
124 clone (y, _prob.y, numTrainExamples);
139 numTrainExamples = _x.QueueSize ();
172 return x.FileDesc ();
251 cerr << endl <<
"VM289::svm_parameter::svm_parameter Not Doing anything with 'paramStr'" << endl << endl;
306 cmdStr <<
"-CalcProb " << ((
probability == 1) ?
"Yes" :
"No") <<
" " 309 <<
"-e " <<
eps <<
" " 310 <<
"-g " <<
gamma <<
" " 313 <<
"-n " <<
nu <<
" " 314 <<
"-p " <<
p <<
" ";
317 cmdStr <<
"-ProbParam " <<
probParam <<
" ";
319 cmdStr <<
"-r " <<
coef0 <<
" " 390 weight_label = (kkint32 *) realloc (weight_label,
sizeof (kkint32) * nr_weight);
391 weight = (
double *) realloc (weight,
sizeof (
double) * nr_weight);
392 weight_label[nr_weight - 1] = atoi (cmd.SubStrPart (2).Str ());
414 <<
"degree" <<
"\t" <<
degree <<
"\t" 415 <<
"gamma" <<
"\t" <<
gamma <<
"\t" 416 <<
"coef0" <<
"\t" <<
coef0 <<
"\t" 418 <<
"eps" <<
"\t" <<
eps <<
"\t" 419 <<
"C" <<
"\t" <<
C <<
"\t" 420 <<
"nr_weight" <<
"\t" <<
nr_weight <<
"\t";
426 if (x > 0) result <<
",";
433 if (x > 0) result <<
",";
439 result <<
"nu" <<
"\t" <<
nu <<
"\t" 440 <<
"p" <<
"\t" <<
p <<
"\t" 441 <<
"shrinking" <<
"\t" <<
shrinking <<
"\t" 445 result <<
"\t" <<
"ProbParam" <<
"\t" <<
probParam;
465 if (field
== "svm_type")
468 else if (field
== "kernel_type")
471 else if (field
== "degree")
474 else if (field
== "gamma")
477 else if (field
== "coef0")
479 else if (field
== "cache_size")
482 else if (field
== "eps")
485 else if (field
== "C")
488 else if (field
== "nr_weight")
512 else if (field
== "nu")
515 else if (field
== "p")
518 else if (field
== "shrinking")
521 else if (field
== "probability")
606 static void info(
const char *fmt,...)
613 vsprintf_s(buf, BUFSIZ, fmt, ap);
615 vsprintf(buf,fmt,ap);
619 (*SVM289_MFS::svm_print_string)(buf);
622 static void info(
const char *fmt,...) {}
659 head_t (): prev (NULL), next (NULL), data (NULL), len (0) {}
670 void lru_delete (head_t * h);
671 void lru_insert (head_t * h);
682 head =
new head_t[l];
684 size -= l *
sizeof (head_t) /
sizeof (
Qfloat);
685 size = Max (size, 2 * (kkint32) l);
686 lru_head.next = lru_head.prev = &lru_head;
693 for (head_t* h = lru_head.next; h != &lru_head; h = h->next)
694 {
delete (h->data); h->data = NULL;}
695 delete head; head = NULL;
700 void Cache::lru_delete (head_t *h)
703 h->prev->next = h->next;
704 h->next->prev = h->prev;
709 void Cache::lru_insert (head_t *h)
713 h->prev = lru_head.prev;
725 head_t* h = &head[index];
736 head_t* old = lru_head.next;
738 delete old->data; old->data = NULL;
745 h->data = (Qfloat *)realloc(h->data,
sizeof (Qfloat) * len);
747 SVM289_MFS::swap (h->len, len);
763 lru_delete (&head[i]);
766 lru_delete(&head[j]);
769 SVM289_MFS::swap (head[i].data, head[j].data);
771 SVM289_MFS::swap (head[i].len, head[j].len);
774 lru_insert(&head[i]);
777 lru_insert(&head[j]);
780 SVM289_MFS::swap(i, j);
783 for (head_t* h = lru_head.next; h != &lru_head; h = h->next)
789 SVM289_MFS::swap (h->data[i], h->data[j]);
795 delete h->data; h->data = NULL;
853 x->SwapIndexes (i, j);
855 swap (x_square[i], x_square[j]);
865 FeatureVectorListPtr x;
883 return dot ((*x)[i], (*x)[j]);
889 return powi (gamma * dot((*x)[i], (*x)[j]) + coef0, degree);
895 return exp (-gamma * (x_square[i] + x_square[j] - 2 * dot ((*x)[i], (*x)[j])));
901 return tanh (gamma * dot ((*x)[i], (*x)[j]) + coef0);
908 return preComputed[i][j];
937 selFeatures =
new kkint32[numSelFeatures];
938 for (
kkint32 zed = 0; zed < numSelFeatures; zed++)
939 selFeatures[zed] = _selFeatures
[zed];
953 preComputed =
new float*[l];
954 for (z1 = 0; z1 < l; z1++)
956 preComputed[z1] =
new float[l];
957 for (z2 = 0; z2 < l; z2++)
958 preComputed[z1][z2] = 0.0f;
966 x_square =
new double[l];
967 for (kkint32 i = 0; i < l; i++)
968 x_square[i] = dot ((*x)[i], (*x)[i]);
982 delete[] selFeatures; selFeatures = NULL;
983 delete[] x_square; x_square = NULL;
989 for (z1 = 0; z1 < l; z1++)
990 delete preComputed[z1];
1013 for (idx = 0; idx < numSelFeatures; idx++)
1015 fn = selFeatures[idx];
1016 sum += fvX[fn] * fvY[fn];
1038 for (idx = 0; idx < numFeatures; idx++)
1040 fn = selFeatures
[idx];
1041 sum += fvX[fn] * fvY[fn];
1076 for (idx = 0; idx < numSelFeatures; idx++)
1078 fn = selFeatures
[idx];
1079 double d = fvX[fn] - fvY[fn];
1083 return exp (-param
.gamma * sum);
1092 <<
"SVM289_MFS::Kernel::k_function ***ERROR*** does not support 'PRECOMPUTED'." << endl
1170 return (
y[i] > 0) ?
Cp :
Cn;
1179 else if(
alpha[i] <= 0)
1214 SVM289_MFS::swap (y[i], y[j]);
1215 SVM289_MFS::swap (G[i], G[j]);
1216 SVM289_MFS::swap (alpha_status[i], alpha_status[j]);
1217 SVM289_MFS::swap (alpha[i], alpha[j]);
1218 SVM289_MFS::swap (p[i], p[j]);
1219 SVM289_MFS::swap (active_set[i],active_set[j]);
1220 SVM289_MFS::swap (G_bar[i], G_bar[j]);
1245 info("\nWarning: using -h 0 may be faster\n");
1255 G[i] +=
alpha[j] * Q_i[j];
1266 double alpha_i =
alpha[i];
1268 G[j] += alpha_i * Q_i[j];
1295 clone(alpha,alpha_,l);
1304 for (
kkint32 i = 0; i < l; i++)
1311 for (
kkint32 i = 0; i < l; i++)
1319 G_bar =
new double[l];
1321 for (i = 0; i < l; i++)
1332 double alpha_i =
alpha[i];
1334 for (j = 0; j < l; j++)
1335 G[j] += alpha_i*Q_i[j];
1339 for (j = 0; j < l; j++)
1349 kkint32 counter = Min (l, 1000) + 1;
1357 counter = Min (l, 1000);
1387 double old_alpha_i =
alpha[i];
1388 double old_alpha_j =
alpha[j];
1392 double quad_coef = Q_i[i] + Q_j[j] +2 *Q_i[j];
1396 double delta = (-
G[i] -
G[j]) / quad_coef;
1417 if (diff > C_i - C_j)
1422 alpha[j] = C_i - diff;
1430 alpha[i] = C_j + diff;
1436 double quad_coef = Q_i[i] + Q_j[j] - 2 * Q_i[j];
1441 double delta = (
G[i] -
G[j]) / quad_coef;
1451 alpha[j] = sum - C_i;
1467 alpha[i] = sum - C_j;
1482 double delta_alpha_i =
alpha[i] - old_alpha_i;
1483 double delta_alpha_j =
alpha[j] - old_alpha_j;
1487 G[k] += Q_i[k] * delta_alpha_i + Q_j[k] * delta_alpha_j;
1503 for (k = 0; k < l; k++)
1504 G_bar[k] -= C_i * Q_i[k];
1508 for (k = 0; k < l; k++)
1509 G_bar[k] += C_i * Q_i[k];
1518 for (k = 0; k < l; k++)
1519 G_bar[k] -= C_j * Q_j[k];
1523 for (k = 0; k < l; k++)
1524 G_bar[k] += C_j * Q_j[k];
1537 for (i = 0; i < l; i++)
1538 v +=
alpha[i] * (
G[i] +
p[i]);
1545 for (
kkint32 i = 0; i < l; i++)
1588 double Gmax2 = -
INF;
1591 double obj_diff_min =
INF;
1621 const Qfloat *Q_i = NULL;
1631 double grad_diff=Gmax+
G[j];
1638 double quad_coef = Q_i[i] +
QD[j] - 2.0 *
y[i] * Q_i[j];
1641 obj_diff = -(grad_diff*grad_diff)/quad_coef;
1643 obj_diff = -(grad_diff*grad_diff)/
TAU;
1645 if (obj_diff <= obj_diff_min)
1648 obj_diff_min = obj_diff;
1657 double grad_diff= Gmax-
G[j];
1663 double quad_coef=Q_i[i]+
QD[j]+2.0*
y[i]*Q_i[j];
1665 obj_diff = -(grad_diff*grad_diff)/quad_coef;
1667 obj_diff = -(grad_diff*grad_diff)/
TAU;
1669 if (obj_diff <= obj_diff_min)
1672 obj_diff_min = obj_diff;
1679 if (Gmax + Gmax2 <
eps)
1691 bool SVM289_MFS::
Solver::be_shrunk(
kkint32 i,
double Gmax1,
double Gmax2)
1696 return (-
G[i] > Gmax1);
1698 return (-
G[i] > Gmax2);
1704 return (
G[i] > Gmax2);
1706 return (
G[i] > Gmax1);
1721 double Gmax1 = -
INF;
1722 double Gmax2 = -
INF;
1757 if ((
unshrink ==
false) && ((Gmax1 + Gmax2) <= (
eps * 10)))
1767 if (be_shrunk(i, Gmax1, Gmax2))
1792 double sum_free = 0;
1796 double yG =
y[i] *
G[i];
1821 r = sum_free / nr_free;
1863 double calculate_rho ();
1872 void do_shrinking ();
1888 double Gmaxp = -
INF;
1889 double Gmaxp2 = -
INF;
1892 double Gmaxn = -
INF;
1893 double Gmaxn2 = -
INF;
1897 double obj_diff_min =
INF;
1928 const Qfloat *Q_ip = NULL;
1929 const Qfloat *Q_in = NULL;
1941 double grad_diff=Gmaxp+
G[j];
1947 double quad_coef = Q_ip[ip]+
QD[j]-2*Q_ip[j];
1949 obj_diff = -(grad_diff*grad_diff)/quad_coef;
1951 obj_diff = -(grad_diff*grad_diff)/
TAU;
1953 if (obj_diff <= obj_diff_min)
1956 obj_diff_min = obj_diff;
1965 double grad_diff=Gmaxn-
G[j];
1966 if (-
G[j] >= Gmaxn2)
1971 double quad_coef = Q_in[in] +
QD[j]- 2 * Q_in[j];
1973 obj_diff = -(grad_diff*grad_diff)/quad_coef;
1975 obj_diff = -(grad_diff*grad_diff)/
TAU;
1977 if (obj_diff <= obj_diff_min)
1980 obj_diff_min = obj_diff;
1987 if (Max (Gmaxp + Gmaxp2, Gmaxn + Gmaxn2) < eps)
1990 if (
y[Gmin_idx] == +1)
2012 return (-
G[i] > Gmax1);
2014 return (-
G[i] > Gmax4);
2020 return (
G[i] > Gmax2);
2022 return (
G[i] > Gmax3);
2033 void SVM289_MFS::
Solver_NU::do_shrinking ()
2035 double Gmax1 = -
INF;
2036 double Gmax2 = -
INF;
2037 double Gmax3 = -
INF;
2038 double Gmax4 = -
INF;
2051 else if(-
G[i] > Gmax4) Gmax4 = -
G[i];
2058 if (
G[i] > Gmax2) Gmax2 =
G[i];
2060 else if (
G[i] > Gmax3)
2067 if (unshrink ==
false && Max (Gmax1 + Gmax2, Gmax3 + Gmax4) <= eps * 10)
2070 reconstruct_gradient();
2076 if (be_shrunk (i, Gmax1, Gmax2, Gmax3, Gmax4))
2081 if (!be_shrunk (
active_size, Gmax1, Gmax2, Gmax3, Gmax4))
2094 double SVM289_MFS::
Solver_NU::calculate_rho ()
2102 double sum_free1 = 0;
2103 double sum_free2 = 0;
2110 lb1 = Max (lb1, G[i]);
2113 ub1 = Min (ub1, G[i]);
2124 lb2 = Max (lb2, G[i]);
2127 ub2 = Min (ub2, G[i]);
2139 r1 = sum_free1 / nr_free1;
2144 r2 = sum_free2 / nr_free2;
2148 si
->r = (r1+r2) / 2;
2149 return (r1 - r2) / 2;
2157 class SVM289_MFS::
SVC_Q:
public SVM289_MFS::Kernel
2169 clone (y, y_, prob.numTrainExamples);
2186 for (j = start; j < len; j++)
2204 SVM289_MFS::swap (y[i],y[j]);
2205 SVM289_MFS::swap (QD[i],QD[j]);
2248 for (j=start; j < len; j++)
2265 SVM289_MFS::swap(QD[i],QD[j]);
2284 class SVM289_MFS::
SVR_Q:
public SVM289_MFS::Kernel
2296 sign =
new schar [2 * l];
2299 for (
kkint32 k = 0; k < l; k++)
2310 buffer [0] =
new Qfloat [2 * l];
2311 buffer [1] =
new Qfloat [2 * l];
2318 SVM289_MFS::swap (sign [i], sign [j]);
2319 SVM289_MFS::swap (index [i], index [j]);
2320 SVM289_MFS::swap (QD [i], QD [j]);
2332 for (j = 0; j < l; j++)
2337 Qfloat *buf = buffer [next_buffer];
2338 next_buffer = 1 - next_buffer;
2340 for (j = 0; j < len; j++)
2341 buf[j] = (
Qfloat) si * (
Qfloat) sign[j] * data[index[j]];
2376 namespace SVM289_MFS
2425 double* minus_ones =
new double[numTrainExamples];
2430 for (i = 0; i < numTrainExamples; ++i)
2458 double sum_alpha =0;
2460 for (i = 0; i < numTrainExamples; i++)
2461 sum_alpha += alpha[i];
2466 for (i = 0; i < numTrainExamples; i++)
2469 delete[] minus_ones;
2485 double nu = param
->nu;
2489 for (i = 0; i < numTrainExamples; i++)
2498 double sum_pos = nu * numTrainExamples / 2;
2499 double sum_neg = nu * numTrainExamples / 2;
2501 for (i = 0; i < numTrainExamples; i++)
2505 alpha[i] = Min(1.0, sum_pos);
2506 sum_pos -= alpha[i];
2510 alpha[i] = Min(1.0,sum_neg);
2511 sum_neg -= alpha[i];
2515 double *zeros =
new double[numTrainExamples];
2517 for (i = 0; i < numTrainExamples; i++)
2543 for (i = 0; i < numTrainExamples; ++i)
2544 alpha[i] *= y[i] / r;
2567 double* zeros =
new double [numTrainExamples];
2573 for (i = 0; i < n; i++)
2579 for (i = n + 1; i < numTrainExamples; i++)
2582 for (i = 0; i < numTrainExamples; i++)
2621 double* alpha2 =
new double [2 * numTrainExamples];
2622 double* linear_term =
new double [2 * numTrainExamples];
2626 for (i = 0; i < numTrainExamples; ++i)
2629 linear_term[i] = param
->p - prob
->y[i];
2632 alpha2 [i + numTrainExamples] = 0;
2633 linear_term [i + numTrainExamples] = param
->p + prob
->y[i];
2634 y [i + numTrainExamples] = -1;
2655 double sum_alpha = 0;
2656 for (i = 0; i < numTrainExamples; i++)
2658 alpha[i] = alpha2[i] - alpha2[i + numTrainExamples];
2659 sum_alpha += fabs (alpha[i]);
2662 info ("nu = %f\n", sum_alpha / (param
->C * numTrainExamples)
);
2665 delete[] linear_term;
2680 double C = param
->C;
2682 double* alpha2 =
new double [2 * numTrainExamples];
2683 double* linear_term =
new double [2 * numTrainExamples];
2687 double sum = C * param
->nu * numTrainExamples / 2;
2689 for (i = 0; i < numTrainExamples; i++)
2691 alpha2[i] = alpha2[i + numTrainExamples] = Min (sum, C);
2694 linear_term[i] = - prob
->y[i];
2697 linear_term[i + numTrainExamples] = prob
->y[i];
2698 y [i + numTrainExamples] = -1;
2720 for (i = 0; i < numTrainExamples; i++)
2721 alpha[i] = alpha2[i] - alpha2[i + numTrainExamples];
2724 delete[] linear_term;
2764 KKStr errMsg =
"SVM289_MFS::svm_train_one ***ERROR*** Invalid Solver Defined.";
2765 errMsg <<
" Solver[" << (
int)param
.svm_type <<
"]";
2766 _log.Level (-1) << endl << endl << errMsg << endl << endl;
2775 std::vector<kkint32> SVIndex;
2781 if (fabs (alpha[i]) > 0)
2784 SVIndex.push_back (i);
2787 if (fabs (alpha[i]) >= si.upper_bound_p)
2795 if (fabs (alpha[i]) >= si.upper_bound_n)
2810 std::vector<kkint32>::iterator it,it2;
2811 double kvalue = 0.0;
2813 for (it = SVIndex.begin(); it < SVIndex.end(); it++)
2815 for (it2 = SVIndex.begin(); it2 < SVIndex.end(); it2++)
2820 kvalue = Kernel::k_function (prob.x[k], prob.x[kk], param, prob.SelFeatures ());
2822 sum += prob
.y[k] * prob
.y[kk] * alpha[k] * alpha[kk] * kvalue;
2826 sum /= SVIndex.size();
2829 for (it = SVIndex.begin(); it < SVIndex.end(); it++)
2851 const double* dec_values,
2852 const double* labels,
2861 for (i = 0; i < numExamples; ++i)
2870 double min_step = 1e-10;
2871 double sigma = 1e-12;
2873 double hiTarget = (prior1 + 1.0) / (prior1 + 2.0);
2874 double loTarget = 1 / (prior0 + 2.0);
2875 double* t =
new double[numExamples];
2876 double fApB, p, q, h11, h22, h21, g1, g2, det, dA, dB, gd, stepsize;
2877 double newA, newB, newf, d1, d2;
2882 B = log ((prior0 + 1.0) / (prior1 + 1.0));
2885 for (i = 0; i < numExamples; ++i)
2892 fApB = dec_values[i] * A + B;
2895 fval += t[i] * fApB + log (1 + exp (-fApB));
2897 fval += (t[i] - 1) * fApB + log (1 + exp (fApB));
2900 for (iter=0; iter < max_iter; iter++)
2908 for (i = 0; i < numExamples; i++)
2910 fApB = dec_values[i] * A + B;
2913 p = exp (-fApB) / (1.0 + exp(-fApB));
2914 q = 1.0 / (1.0 + exp(-fApB));
2918 p = 1.0 / (1.0 + exp (fApB));
2919 q = exp (fApB) / (1.0 + exp (fApB));
2923 h11 += dec_values[i] * dec_values[i] * d2;
2925 h21 += dec_values[i] * d2;
2927 g1 += dec_values[i] * d1;
2932 if ((fabs (g1) < eps) && (fabs(g2) < eps))
2936 det = h11 * h22 - h21 * h21;
2937 dA = -(h22*g1 - h21 * g2) / det;
2938 dB = -(-h21 * g1 + h11 * g2) / det;
2939 gd = g1 * dA + g2 * dB;
2943 while (stepsize >= min_step)
2945 newA = A + stepsize * dA;
2946 newB = B + stepsize * dB;
2950 for (i = 0; i < numExamples; i++)
2952 fApB = dec_values[i] * newA + newB;
2954 newf += t[i] * fApB + log (1 + exp (-fApB));
2956 newf += (t[i] - 1) * fApB + log (1 + exp (fApB));
2960 if (newf < fval + 0.0001 * stepsize * gd)
2968 stepsize = stepsize / 2.0;
2971 if (stepsize < min_step)
2973 info("Line search fails in two-class probability estimates\n");
2978 if (iter >= max_iter)
2979 info ("Reaching maximal iterations in two-class probability estimates\n");
2981 delete[] t; t = NULL;
2991 double fApB = decision_value * A + B;
2993 return exp (-fApB) / (1.0 + exp (-fApB));
2995 return 1.0 / (1 + exp (fApB));
3010 double** pairwiseProbs,
3016 kkint32 max_iter = Max (100, numClasses);
3018 double** Q =
new double*[numClasses];
3019 double* Qp =
new double[numClasses];
3021 double eps = 0.005 / numClasses;
3023 for (t = 0; t < numClasses; ++t)
3025 classProb[t] = 1.0 / numClasses;
3026 Q[t] =
new double[numClasses];
3027 for (
kkint32 i = 0; i < numClasses; ++i)
3031 for (j = 0; j < t; j++)
3033 Q[t][t] += pairwiseProbs[j][t] * pairwiseProbs[j][t];
3037 for (j = t + 1; j < numClasses; ++j)
3039 Q[t][t] += pairwiseProbs[j][t] * pairwiseProbs[j][t];
3040 Q[t][j] =- pairwiseProbs[j][t] * pairwiseProbs[t][j];
3044 for (iter = 0; iter < max_iter; iter++)
3048 for (t = 0; t < numClasses; t++)
3051 for (j = 0; j < numClasses; j++)
3052 Qp[t] += Q[t][j] * classProb[j];
3053 pQp += classProb[t] * Qp[t];
3055 double max_error = 0;
3056 for (t = 0; t < numClasses; ++t)
3058 double error = fabs (Qp[t] - pQp);
3059 if (error > max_error)
3063 if (max_error < eps)
3066 for (t = 0; t < numClasses; ++t)
3068 double diff = (-Qp[t] +pQp) / Q[t][t];
3069 classProb[t] += diff;
3070 pQp = (pQp + diff * (diff * Q[t][t] + 2 * Qp[t])) / (1 + diff) / (1 + diff);
3071 for (j = 0; j < numClasses; ++j)
3073 Qp[j] = (Qp[j] + diff * Q[t][j]) / (1 + diff);
3074 classProb[j] /= (1 + diff);
3078 if (iter >= max_iter)
3079 info ("Exceeds max_iter in multiclass_prob\n");
3081 for (t = 0; t < numClasses; ++t)
3082 {
delete Q[t]; Q[t] = NULL;}
3084 delete[] Q; Q = NULL;
3085 delete[] Qp; Qp = NULL;
3105 FeatureVectorPtr* subX = NULL;
3116 kkint32 j = i + rand() % (prob->numTrainExamples - i);
3117 SVM289_MFS::swap (perm[i], perm[j]);
3120 for (i = 0; i < nr_fold; i++)
3127 subX =
new FeatureVectorPtr[subL];
3128 for (j = 0; j < subL; j++)
3130 float* subY =
new float[subL];
3133 for (j = 0; j < begin; j++)
3135 subX[k] = prob->x.IdxToPtr (perm[j]);
3136 subY[k] = (
float)prob
->y[perm[j]];
3142 subX[k] = prob->x.IdxToPtr (perm[j]);
3143 subY[k] = (
float)prob
->y[perm[j]];
3148 FeatureVectorListPtr subXX =
new FeatureVectorList (prob->x.FileDesc (),
false);
3149 for (j = 0; j < k; j++)
3155 kkint32 p_count=0, n_count = 0;
3157 for (j = 0; j < k; j++)
3166 if ((p_count == 0) && (n_count == 0))
3168 for (j = begin; j < end; j++)
3169 dec_values[perm[j]] = 0;
3172 else if ((p_count > 0) && (n_count == 0))
3174 for (j = begin; j < end; j++)
3175 dec_values[perm[j]] = 1;
3178 else if ((p_count == 0) && (n_count > 0))
3180 for (j = begin; j < end; j++)
3181 dec_values[perm[j]] = -1;
3191 subparam
.weight =
new double[2];
3198 for (j = begin; j < end; j++)
3200 svm_predict_values (submodel, prob->x[perm[j]], &(dec_values[perm[j]]));
3202 dec_values[perm[j]] *= submodel
->label[0];
3205 delete submodel; submodel = NULL;
3209 delete subProb; subProb = NULL;
3210 delete[] subX; subX = NULL;
3211 delete[] subY; subY = NULL;
3215 delete[] dec_values; dec_values = NULL;
3216 delete[] perm; perm = NULL;
3242 ymv[i] = prob
.y[i] - ymv[i];
3243 mae += fabs (ymv[i]);
3247 double std = sqrt (2 * mae * mae);
3252 if (fabs(ymv[i]) > (5 * std))
3255 mae += fabs (ymv[i]);
3260 info("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma= %g\n", mae
);
3261 delete ymv; ymv = NULL;
3289 for (i = 0; i < l; i++)
3293 for (j = 0; j < nr_class; j++)
3295 if (this_label == label[j])
3305 if (nr_class == max_nr_class)
3308 label = (kkint32 *)realloc (label, max_nr_class *
sizeof(kkint32));
3309 count = (kkint32 *)realloc (count, max_nr_class *
sizeof(kkint32));
3311 label[nr_class] = this_label;
3312 count[nr_class] = 1;
3319 for (i = 1; i < nr_class; i++)
3320 start[i] = start[i - 1] + count[i - 1];
3322 for (i = 0; i < l; i++)
3324 perm[start[data_label[i]]] = i;
3325 ++start[data_label[i]];
3329 for (i = 1; i < nr_class; i++)
3330 start[i] = start[i - 1] + count[i - 1];
3332 *nr_class_ret = nr_class;
3336 delete data_label; data_label = NULL;
3374 model
->rho =
new double[1];
3381 if (fabs(f.alpha[i]) > 0)
3388 model->SV.Owner (
true);
3393 if (fabs (f.alpha[i]) > 0)
3396 model->SV.PushOnBack (
new FeatureVector (prob.x[i]));
3397 model->sv_coef[0][j] = f.alpha[i];
3423 kkint32 numBinaryCombos = nr_class * (nr_class - 1) / 2;
3429 for (i = 0; i < l; i++)
3432 x.PushOnBack (prob.x.IdxToPtr (perm[i]));
3436 double* weighted_C =
new double[nr_class];
3437 for (i = 0; i < nr_class; i++)
3438 weighted_C[i] = param
.C;
3443 for (j = 0; j < nr_class; j++)
3450 fprintf(stderr,
"warning: class label %d specified in weight is not found\n", param.weight_label[i]);
3452 weighted_C[j] *= param
.weight[i];
3457 bool *nonzero =
new bool[l];
3459 for (i = 0; i < l; i++)
3464 double* probA = NULL;
3465 double* probB = NULL;
3469 probA =
new double[numBinaryCombos];
3470 probB =
new double[numBinaryCombos];
3474 for (i = 0; i < nr_class; i++)
3476 for (
kkint32 j = i + 1; j < nr_class; j++)
3479 kkint32 si = start[i], sj = start[j];
3480 kkint32 ci = count[i], cj = count[j];
3485 for (k = 0; k < ci; k++)
3488 sub_prob.x.PushOnBack (x.IdxToPtr (si + k));
3491 for (k = 0; k < cj; k++)
3494 sub_prob.x.PushOnBack (x.IdxToPtr (sj + k));
3495 sub_prob
.y[ci + k] = -1;
3504 for (k = 0; k < ci; k++)
3506 if (!nonzero[si + k] && fabs(f[p].alpha[k]) > 0)
3507 nonzero[si + k] =
true;
3510 for (k = 0; k < cj; k++)
3512 if (!nonzero[sj + k] && fabs(f[p].alpha[ci+k]) > 0)
3513 nonzero[sj + k] =
true;
3531 for (i = 0; i < nr_class; i++)
3534 model
->rho =
new double[numBinaryCombos];
3535 for (i = 0; i < numBinaryCombos; i++)
3540 model
->probA =
new double[numBinaryCombos];
3541 model
->probB =
new double[numBinaryCombos];
3542 for (i = 0; i < numBinaryCombos; i++)
3558 for (i = 0; i < nr_class; i++)
3561 for (
kkint32 j = 0; j < count[i]; j++)
3563 if (nonzero[start[i] + j])
3569 model
->nSV[i] = nSV;
3573 info("Total nSV = %d\n",total_sv
);
3577 model->SV.DeleteContents ();
3578 model->SV.Owner (
false);
3582 for (i = 0; i < l; i++)
3587 model->SV.PushOnBack (x.IdxToPtr (i));
3594 for (i = 1; i < nr_class; i++)
3595 nz_start[i] = nz_start[i - 1] + nz_count[i - 1];
3597 model
->sv_coef =
new double*[nr_class - 1];
3598 for (i = 0; i < nr_class - 1; i++)
3599 model
->sv_coef[i] =
new double[total_sv];
3602 for (i = 0; i < nr_class; i++)
3604 for (
kkint32 j = i + 1; j < nr_class; j++)
3618 for (k = 0; k < ci; k++)
3620 if (nonzero[si + k])
3625 for (k = 0; k < cj; k++)
3627 if (nonzero[sj + k])
3634 delete label; label = NULL;
3635 delete probA; probA = NULL;
3636 delete probB; probB = NULL;
3637 delete count; count = NULL;
3638 delete perm; perm = NULL;
3639 delete start; start = NULL;
3641 delete weighted_C; weighted_C = NULL;
3642 delete nonzero; nonzero = NULL;
3643 for (i = 0; i < numBinaryCombos; i++)
3649 delete nz_count; nz_count = NULL;
3650 delete nz_start; nz_start = NULL;
3677 (nr_fold < numTrainExamples)
3689 for (i = 0; i < numTrainExamples; i++)
3692 for (c = 0; c < nr_class; c++)
3694 for (i = 0; i < count[c]; i++)
3696 kkint32 j = i + rand() % (count[c]-i);
3697 SVM289_MFS::swap (index[start[c]+j], index[start[c]+i]);
3701 for (i = 0; i < nr_fold; ++i)
3704 for (c = 0; c < nr_class; ++c)
3705 fold_count[i] += (i + 1) * count[c] / nr_fold - i * count[c] / nr_fold;
3709 for (i = 1; i <= nr_fold; i++)
3710 fold_start[i] = fold_start[i-1] + fold_count[i-1];
3712 for (c=0; c<nr_class;c++)
3714 for(i=0;i<nr_fold;i++)
3716 kkint32 begin = start[c]+i*count[c]/nr_fold;
3717 kkint32 end = start[c]+(i+1)*count[c]/nr_fold;
3718 for(
kkint32 j=begin;j<end;j++)
3720 perm[fold_start[i]] = index[j];
3727 for (i=1;i<=nr_fold;i++)
3728 fold_start[i] = fold_start[i-1]+fold_count[i-1];
3730 delete start; start = NULL;
3731 delete label; label = NULL;
3732 delete count; count = NULL;
3733 delete index; index = NULL;
3734 delete fold_count; fold_count = NULL;
3738 for (i = 0; i < numTrainExamples; ++i)
3741 for (i = 0; i < numTrainExamples; ++i)
3743 kkint32 j = i + rand() % (numTrainExamples - i);
3744 SVM289_MFS::swap (perm[i], perm[j]);
3746 for (i = 0; i <= nr_fold; i++)
3747 fold_start[i] = i * numTrainExamples / nr_fold;
3750 for (i = 0; i < nr_fold; i++)
3752 kkint32 begin = fold_start[i];
3753 kkint32 end = fold_start[i+1];
3764 for (j = 0; j < begin; j++)
3767 subprob.x.PushOnBack (prob.x.IdxToPtr (perm[j]));
3768 subprob
.y[k] = prob
.y[perm[j]];
3772 for (j = end; j < numTrainExamples; j++)
3775 subprob.x.PushOnBack (prob.x.IdxToPtr (perm[j]));
3776 subprob
.y[k] = prob
.y[perm[j]];
3787 for (j = begin; j < end; j++)
3788 target[perm[j]] = svm_predict_probability (submodel, prob.x[perm[j]], prob_estimates, votes);
3789 delete prob_estimates;
3790 prob_estimates = NULL;
3796 for (j = begin; j < end; j++)
3797 target[perm[j]] = svm_predict (submodel, prob.x[perm[j]]);
3805 delete subprob
.y; subprob
.y = NULL;
3808 delete fold_start; fold_start = NULL;
3809 delete perm; perm = NULL;
3848 fprintf(stderr,
"Model doesn't contain information for SVR probability inference\n");
3868 for (kkint32 i = 0; i < model->numSVs; i++)
3869 sum += sv_coef[i] * Kernel::k_function (x,
3874 sum -= model
->rho[0];
3883 double *kvalue =
new double[numSVs];
3884 for (i = 0; i < numSVs; i++)
3885 kvalue[i] = Kernel::k_function (x, model->SV[i], model->param, model->selFeatures);
3889 for (i = 1; i < nr_class; i++)
3890 start[i] = start[i-1]+model
->nSV[i-1];
3893 for (i = 0; i < nr_class; i++)
3895 for (
kkint32 j = i + 1; j < nr_class; j++)
3906 for (k = 0; k < ci; k++)
3907 sum += coef1[si + k] * kvalue[si + k];
3910 for (k = 0; k < cj; k++)
3911 sum += coef2[sj + k] * kvalue[sj + k];
3913 sum -= model
->rho[p];
3914 dec_values[p] = sum;
3919 delete kvalue; kvalue = NULL;
3920 delete start; start = NULL;
3943 return (res > 0) ? 1:-1;
3951 double *dec_values =
new double[nr_class * (nr_class - 1) / 2];
3955 for (i = 0; i < nr_class; i++)
3959 for (i = 0; i < nr_class; i++)
3961 for (
kkint32 j = i + 1; j < nr_class; j++)
3963 if (dec_values[pos++] > 0)
3971 for(i=1;i<nr_class;i++)
3973 if (vote[i] > vote[vote_max_idx])
3977 delete vote; vote = NULL;
3978 delete dec_values; dec_values = NULL;
3980 return model
->label[vote_max_idx];
3990 double* classProbabilities,
3997 ((model
->probA != NULL && model
->probB != NULL) || (probParam > 0.0))
4007 for (i = 0; i < nr_class; ++i)
4012 double min_prob = 1e-7;
4015 for (i = 0; i < nr_class; ++i)
4017 for (
kkint32 j = i + 1; j < nr_class; ++j)
4019 if (probParam > 0.0)
4021 double probability = (
double)(1.0 / (1.0 + exp (-1.0 * probParam * dec_values[k])));
4022 pairwise_prob[i][j] = Min (Max (probability, min_prob), 1.0 - min_prob);
4023 pairwise_prob[j][i] = 1.0 - pairwise_prob[i][j];
4027 pairwise_prob[i][j] = Min (Max (sigmoid_predict (dec_values[k], model->probA[k], model->probB[k]), min_prob), 1.0 - min_prob);
4028 pairwise_prob[j][i] = 1.0 - pairwise_prob[i][j];
4031 if (pairwise_prob[i][j] > 0.5)
4048 for (i = 1; i < nr_class; i++)
4050 if (prob_estimates[i] > prob_estimates[prob_max_idx])
4054 for (i = 0; i < nr_class; i++)
4055 classProbabilities[model
->label[i]] = prob_estimates[i];
4057 return model
->label[prob_max_idx];
4116 FeatureVectorList::const_iterator idx;
4117 SV.Owner (weOwnSupportVectors);
4118 for (idx = _model.SV.begin (); idx != _model.SV.end (); idx++)
4120 FeatureVectorPtr fv = *idx;
4121 if (weOwnSupportVectors)
4122 SV.push_back (
new FeatureVector (*fv));
4131 for (
kkint32 j = 0; j < m; j++)
4142 rho =
new double[numBinaryCombos];
4143 for (
kkint32 i = 0; i < numBinaryCombos; i++)
4149 probA =
new double[numBinaryCombos];
4150 for (
kkint32 i = 0; i < numBinaryCombos; i++)
4156 probB =
new double[numBinaryCombos];
4157 for (
kkint32 i = 0; i < numBinaryCombos; i++)
4237 if (weOwnSupportVectors)
4246 for (i = 0; i < (
nr_class - 1); i++)
4287 kkint32 memoryConsumedEstimated =
sizeof (*
this) + SV.MemoryConsumedEstimated ();
4290 if (
rho) memoryConsumedEstimated +=
sizeof (
double) * numBinaryClassCombos;
4291 if (
probA) memoryConsumedEstimated +=
sizeof (
double) * numBinaryClassCombos;
4292 if (
probB) memoryConsumedEstimated +=
sizeof (
double) * numBinaryClassCombos;
4296 if (
dec_values) memoryConsumedEstimated +=
sizeof (
double) * numBinaryClassCombos;
4298 return memoryConsumedEstimated;
4352 XmlElementDouble::WriteXML (
param.gamma,
"gamma", o);
4355 XmlElementDouble::WriteXML (
param.coef0,
"coef0", o);
4359 XmlElementInt32::WriteXML (
nr_class,
"nr_class", o);
4363 XmlElementInt32::WriteXML (
numSVs,
"numSVs", o);
4365 XmlElementArrayDouble::WriteXML (numBinaryCombos,
rho,
"rho", o);
4367 XmlElementArrayInt32::WriteXML (
nr_class,
label,
"label", o);
4370 XmlElementArrayDouble::WriteXML (numBinaryCombos,
probA,
"probA", o);
4373 XmlElementArrayDouble::WriteXML (numBinaryCombos,
probB,
"probB", o);
4376 XmlElementArrayInt32::WriteXML (
nr_class,
nSV,
"nSV", o);
4389 svStr <<
"\t" << buff;
4429 KKStr svmParametersStr;
4431 while (t && (!cancelFlag))
4440 double valueDouble = 0.0;
4444 valueStr = *(
dynamic_cast<XmlElementKKStrPtr> (e)->Value ());
4446 else if (
typeid(*e) ==
typeid(XmlElementInt32))
4447 valueInt32 =
dynamic_cast<XmlElementInt32Ptr> (e)->Value ();
4449 else if (
typeid(*e) ==
typeid(XmlElementDouble))
4450 valueDouble =
dynamic_cast<XmlElementDoublePtr> (e)->Value ();
4455 SV.ResetFileDesc (fileDesc);
4474 selFeatures = *(
dynamic_cast<XmlElementFeatureNumListPtr> (e)->Value ());
4488 rho =
dynamic_cast<XmlElementArrayDoublePtr> (e)->TakeOwnership ();
4495 label =
dynamic_cast<XmlElementArrayInt32Ptr> (e)->TakeOwnership ();
4501 probA =
dynamic_cast<XmlElementArrayDoublePtr> (e)->TakeOwnership ();
4507 probB =
dynamic_cast<XmlElementArrayDoublePtr> (e)->TakeOwnership ();
4513 nSV =
dynamic_cast<XmlElementArrayInt32Ptr> (e)->TakeOwnership ();
4524 for (i = 0; i < m; i++)
4527 for (j = 0; j <
numSVs; j++)
4532 if (SV.QueueSize () >= numSVs)
4534 KKStr errorMsg =
"SVM289_MFS::Svm_Model::Read ***ERROR*** To many Support Vector's Defined.";
4535 log.Level (-1) << endl << errorMsg << endl << endl;
4539 KKStrParser p (valueStr);
4540 p.TrimWhiteSpace (
" ");
4541 KKStr imageFileName = p.GetNextToken (
"\t");
4542 kkint32 numOffeatures = p.GetNextTokenInt (
"\t");
4544 FeatureVectorPtr fv =
new FeatureVector (numOffeatures);
4546 for (kkint32 j = 0; (j < (nr_class - 1)) && p.MoreTokens (); ++j)
4547 sv_coef[j][i] = p.GetNextTokenDouble (
"\t");
4549 if (param.kernel_type == Kernel_Type::PRECOMPUTED)
4551 log.Level (-1) << endl << endl
4552 <<
"SVM289_MFS::Svm_Model::Read ***ERROR*** PRECOMPUTED Can not Handle." << endl
4557 for (kkint32 zed = 0; (zed < numOffeatures) && (p.MoreTokens ()); ++zed)
4559 KKStr featureField = p.GetNextToken (
"\t");
4560 kkint32 featureNumber = featureField.ExtractTokenInt (
":");
4561 double featureValue = featureField.ExtractTokenDouble (
"\t");
4562 fv->FeatureData (featureNumber, (
float)featureValue);
4591 double totalProb = 0.0;
4615 if (model->weOwnSupportVectors)
4616 model->SV.Owner (
true);
4618 model->SV.Owner (
false);
4650 return "unknown svm type";
4662 return "unknown kernel type";
4665 return "degree of polynomial kernel < 0";
4670 return "cache_size <= 0";
4672 if (param
->eps <= 0)
4686 if ((param
->nu <= 0) || (param
->nu > 1))
4687 return "nu <= 0 or nu > 1";
4696 return "shrinking != 0 and shrinking != 1";
4699 return "probability != 0 and probability != 1";
4702 return "one-class SVM probability output not supported yet";
4716 for (i = 0; i < l; i++)
4720 for (j = 0; j < nr_class; j++)
4722 if (this_label == label[j])
4731 if (nr_class == max_nr_class)
4733 kkint32 oldMaxNrClass = max_nr_class;
4735 label = GrowAllocation (label, oldMaxNrClass, max_nr_class);
4736 count = GrowAllocation (count, oldMaxNrClass, max_nr_class);
4738 label[nr_class] = this_label;
4739 count[nr_class] = 1;
4745 for (i = 0; i < nr_class; i++)
4748 for (
kkint32 j = i + 1; j < nr_class; j++)
4751 if ((param->nu * (n1 + n2) / 2) > Min (n1, n2))
4753 delete[] label; label = NULL;
4754 delete[] count; count = NULL;
4755 return "specified nu is infeasible";
4760 delete[] label; label = NULL;
4761 delete[] count; count = NULL;
double svm_predict_probability(Svm_Model *model, const FeatureVector &x, double *prob_estimates, kkint32 *votes)
virtual void do_shrinking()
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
XmlTag(const KKStr &_name, TagTypes _tagType)
void PushOnBack(FeatureVectorPtr image)
Overloading the PushOnBack function in KKQueue so we can monitor the Version and Sort Order...
SVC_Q(const svm_problem &prob, const svm_parameter ¶m, const schar *y_, RunLog &_log)
static void solve_nu_svr(const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, RunLog &_log)
bool EqualIgnoreCase(const char *s2) const
Svm_Model * svm_train(const svm_problem &prob, const svm_parameter ¶m, RunLog &log)
void solve_c_svc(const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, double Cp, double Cn, RunLog &_log)
FileDescPtr FileDesc() const
bool is_upper_bound(kkint32 i)
FeatureVectorList(const FeatureVectorList &examples, bool _owner)
Create a duplicate list, depending on the '_owner' parameter may also duplicate the contents...
void Solve(kkint32 l, QMatrix &Q, const double *p, const schar *y, double *alpha, double Cp, double Cn, double eps, SolutionInfo *si, kkint32 shrinking)
bool is_lower_bound(kkint32 i)
void reconstruct_gradient()
const float * FeatureData() const
Returns as a pointer to the feature data itself.
float FeatureData(kkint32 featureNum) const
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
Keeps track of selected features.
FeatureNumList(FileDescPtr _fileDesc)
static void print_string_stdout(const char *s)
void swap_index(kkint32 i, kkint32 j)
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
kkint32 SPRINTF(char *buff, kkint32 buffSize, char const *formatSpec, double d)
void swap_index(kkint32 i, kkint32 j)
virtual void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
void svm_binary_svc_probability(const svm_problem *prob, const svm_parameter *param, double Cp, double Cn, double &probA, double &probB, RunLog &log)
bool operator==(const char *rtStr) const
void svm_cross_validation(const svm_problem &prob, const svm_parameter ¶m, kkint32 nr_fold, double *target, RunLog &log)
void solve_nu_svc(const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, RunLog &_log)
Qfloat * get_Q(kkint32 i, kkint32 len) const
FeatureNumList selFeatures
Svm_Model(const Svm_Model &_model, FileDescPtr _fileDesc)
static double k_function(const FeatureVector &x, const FeatureVector &y, const svm_parameter ¶m, const FeatureNumList &selFeatures)
FeatureNumList(const FeatureNumList &featureNumList)
Copy constructor.
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector's.
void(* svm_print_string)(const char *)
kkint32 get_data(const kkint32 index, Qfloat **data, kkint32 len)
void svm_get_labels(const Svm_Model *model, kkint32 *label)
KKStr Kernel_Type_ToStr(Kernel_Type kernelType)
virtual Qfloat * get_Q(kkint32 column, kkint32 len) const =0
double svm_svr_probability(const svm_problem &prob, const svm_parameter ¶m, RunLog &log)
Kernel(const FeatureVectorList &_x, const FeatureNumList &_selFeatures, const svm_parameter &_param, RunLog &_log)
virtual kkint32 select_working_set(kkint32 &i, kkint32 &j)
Svm_Model(FileDescPtr _fileDesc)
Container class for FeatureVector derived objects.
Qfloat * get_Q(kkint32 i, kkint32 len) const
static void info(const char *fmt,...)
double(Kernel::* kernel_function)(kkint32 i, kkint32 j) const
void swap_index(kkint32 i, kkint32 j)
Qfloat * get_Q(kkint32 i, kkint32 len) const
kkuint16 operator[](kkint32 idx) const
Returns back the selected feature.
void solve_epsilon_svr(const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, RunLog &_log)
void Solve(kkint32 l, QMatrix &Q, const double *p_, const schar *y_, double *alpha_, double Cp, double Cn, double eps, SolutionInfo *si, kkint32 shrinking)
double ExtractTokenDouble(const char *delStr)
double svm_predict(const struct Svm_Model *model, const FeatureVector &x)
void ParseTabDelStr(const KKStr &_str)
XmlElement * XmlElementPtr
svm_parameter(const svm_parameter &_param)
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
double powi(double base, kkint32 times)
virtual Qfloat * get_QD() const =0
KKStr ToCmdLineStr() const
XmlTag const * XmlTagConstPtr
FeatureNumList selFeatures
void NormalizeProbability()
Derives multi-class probability.
SVM_Type SVM_Type_FromStr(KKStr s)
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
void ProcessSvmParameter(const KKStr &cmd, const KKStr &value, bool &parmUsed)
void update_alpha_status(kkint32 i)
void svm_destroy_param(svm_parameter *¶m)
const char * svm_check_parameter(const svm_problem *prob, const svm_parameter *param)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void svm_destroy_model(struct Svm_Model *&model)
void Upper()
Converts all characters in string to their Upper case equivalents via 'toupper'.
KKStr ToTabDelStr() const
kkint32 svm_check_probability_model(const Svm_Model *model)
virtual void swap_index(kkint32 i, kkint32 j)
ONE_CLASS_Q(const svm_problem &prob, const svm_parameter ¶m, RunLog &_log)
void sigmoid_train(kkint32 numExamples, const double *dec_values, const double *labels, double &A, double &B)
SVR_Q(const svm_problem &prob, const svm_parameter ¶m, RunLog &_log)
Cache(kkint32 l, kkint32 size)
decision_function svm_train_one(const svm_problem &prob, const svm_parameter ¶m, double Cp, double Cn, RunLog &_log)
static double DotStatic(const FeatureVector &px, const FeatureVector &py, const FeatureNumList &selFeatures)
kkint32 svm_get_nr_class(const struct Svm_Model *model)
Kernel_Type Kernel_Type_FromStr(KKStr s)
void swap_index(kkint32 i, kkint32 j)
virtual Qfloat * get_QD() const =0
Svm_Model(const svm_parameter &_param, const FeatureNumList &_selFeatures, FileDescPtr _fileDesc)
virtual void swap_index(kkint32 i, kkint32 j)=0
void WriteXML(const KKStr &varName, std::ostream &o) const
kkint32 ExtractTokenInt(const char *delStr)
virtual Qfloat * get_Q(kkint32 column, kkint32 len) const =0
kkint32 NumSelFeatures() const
virtual double calculate_rho()
svm_problem(const FeatureVectorList &_x, const float *_y, const FeatureNumList &_selFeatures)
kkint32 MemoryConsumedEstimated() const
void swap_index(kkint32 i, kkint32 j)
double sigmoid_predict(double decision_value, double A, double B)
svm_parameter & operator=(const svm_parameter &right)
svm_problem(const FeatureNumList &_selFeatures, FileDescPtr _fileDesc, RunLog &_log)
void WriteXML(std::ostream &o)
void multiclass_probability(kkint32 numClasses, double **pairwiseProbs, double *classProb)
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
void svm_group_classes(const svm_problem *prob, kkint32 *nr_class_ret, kkint32 **label_ret, kkint32 **start_ret, kkint32 **count_ret, kkint32 *perm)
const FeatureNumList & SelFeatures() const
void solve_one_class(const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, RunLog &_log)
double svm_get_svr_probability(const Svm_Model *model)
kkint32 svm_get_svm_type(const Svm_Model *model)
virtual TokenTypes TokenType()=0
FileDescPtr Value() const
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
void CancelFlag(bool cancelFlag)
T * GrowAllocation(T *src, kkint32 origSize, kkint32 newSize)
KKException(const KKStr &_exceptionStr)
bool ToBool() const
Returns the bool equivalent of the string, ex 'Yes' = true, 'No' = false, 'True' = true...
KKStr SVM_Type_ToStr(SVM_Type svmType)
virtual void WriteXML(const KKStr &varName, ostream &o) const
svm_parameter(KKStr ¶mStr)
Represents a Feature Vector of a single example, labeled or unlabeled.
void WriteXML(const KKStr &varName, std::ostream &o) const
virtual const KKStr & VarName() const
#define XmlFactoryMacro(NameOfClass)
void WriteXML(const KKStr &varName, std::ostream &o) const
svm_problem(const svm_problem &_prob)
const KKStr & ExampleFileName() const
Name of file that this FeatureVector was computed from.
XmlElementFileDesc * XmlElementFileDescPtr
volatile const bool VolConstBool
void svm_predict_values(const Svm_Model *model, const FeatureVector &x, double *dec_values)