38 #ifndef FCL_TEST_LIBSVM_CLASSIFIER_H 39 #define FCL_TEST_LIBSVM_CLASSIFIER_H 41 #include "fcl/learning/classifier.h" 48 template<std::
size_t N>
128 virtual void learn(
const std::vector<Item<N> >& data)
130 if(data.size() == 0)
return;
145 for(std::size_t i = 0; i < data.size(); ++i)
148 Vecnf<N> q_scaled =
scaler.scale(data[i].q);
149 for(std::size_t j = 0; j < N; ++j)
151 cur_x_space[j].
index = j + 1;
152 cur_x_space[j].
value = q_scaled[j];
154 cur_x_space[N].
index = -1;
157 problem.
y[i] = (data[i].label ? 1 : -1);
165 virtual std::vector<PredictResult>
predict(
const std::vector<Vecnf<N> >& qs)
const 167 std::vector<PredictResult> predict_results;
170 double* prob_estimates = NULL;
174 prob_estimates = (
double*)malloc(nr_class *
sizeof(
double));
177 for(std::size_t i = 0; i < qs.size(); ++i)
180 for(std::size_t j = 0; j < N; ++j)
187 double predict_label;
192 predict_label = (predict_label > 0) ? 1 : 0;
193 predict_results.push_back(PredictResult(predict_label, *prob_estimates));
198 predict_label = (predict_label > 0) ? 1 : 0;
199 predict_results.push_back(PredictResult(predict_label));
206 return predict_results;
209 virtual PredictResult
predict(
const Vecnf<N>& q)
const 211 return (
predict(std::vector<Vecnf<N> >(1, q)))[0];
214 void save(
const std::string& filename)
const 222 std::vector<Item<N> > results;
224 for(std::size_t i = 0; i < (std::size_t)
model->
l; ++i)
226 for(std::size_t j = 0; j < N; ++j)
228 item.q =
scaler.unscale(item.q);
231 results.push_back(item);
FCL_DEPRECATED double FCL_REAL
int svm_save_model(const char *model_file_name, const svm_model *model)
svm_model * svm_train(const svm_problem *prob, const svm_parameter *param)
void setPositiveWeight(FCL_REAL c)
virtual std::vector< Item< N > > getSupportVectors() const
void setNegativeWeight(FCL_REAL c)
double svm_predict(const svm_model *model, const svm_node *x)
virtual void setScaler(const Scaler< N > &scaler_)
virtual void learn(const std::vector< Item< N > > &data)
int svm_get_nr_class(const svm_model *model)
void setLinearClassifier()
void save(const std::string &filename) const
void setGamma(FCL_REAL gamma)
void svm_free_and_destroy_model(svm_model **model_ptr_ptr)
double svm_predict_probability(const svm_model *model, const svm_node *x, double *prob_estimates)
void setProbability(bool use_probability)
double svm_hyper_w_normsqr_twoclass(const struct svm_model *model)
virtual PredictResult predict(const Vecnf< N > &q) const
virtual std::vector< PredictResult > predict(const std::vector< Vecnf< N > > &qs) const
void svm_destroy_param(svm_parameter *param)
void setNonLinearClassifier()