MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / svm_predict_values

Function svm_predict_values

ml/src/svm.cpp:2842–2924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2840}
2841
2842double
2843svm_predict_values(const svm_model* model, const svm_node* x, double* dec_values)
2844{
2845 if (model->param.svm_type == ONE_CLASS || model->param.svm_type == EPSILON_SVR ||
2846 model->param.svm_type == NU_SVR) {
2847 double* sv_coef = model->sv_coef[0];
2848 double sum = 0;
2849
2850 for (int i = 0; i < model->l; i++)
2851 sum += sv_coef[i] * Kernel::k_function(x, model->SV[i], model->param);
2852
2853 sum -= model->rho[0];
2854
2855 *dec_values = sum;
2856
2857 if (model->param.svm_type == ONE_CLASS)
2858 return (sum > 0) ? 1 : -1;
2859 return sum;
2860 }
2861
2862 int nr_class = model->nr_class;
2863 int l = model->l;
2864
2865 double* kvalue = Malloc(double, l);
2866
2867 for (int i = 0; i < l; i++)
2868 kvalue[i] = Kernel::k_function(x, model->SV[i], model->param);
2869
2870 int* start = Malloc(int, nr_class);
2871
2872 start[0] = 0;
2873
2874 for (int i = 1; i < nr_class; i++)
2875 start[i] = start[i - 1] + model->nSV[i - 1];
2876
2877 int* vote = Malloc(int, nr_class);
2878
2879 for (int i = 0; i < nr_class; i++)
2880 vote[i] = 0;
2881
2882 int p = 0;
2883
2884 for (int i = 0; i < nr_class; i++)
2885 for (int j = i + 1; j < nr_class; j++) {
2886 double sum = 0;
2887 int si = start[i];
2888 int sj = start[j];
2889 int ci = model->nSV[i];
2890 int cj = model->nSV[j];
2891
2892 double* coef1 = model->sv_coef[j - 1];
2893 double* coef2 = model->sv_coef[i];
2894
2895 for (int k = 0; k < ci; k++)
2896 sum += coef1[si + k] * kvalue[si + k];
2897
2898 for (int k = 0; k < cj; k++)
2899 sum += coef2[sj + k] * kvalue[sj + k];

Callers 3

svm_predictFunction · 0.85
svm_predict_probabilityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected