Feat C++ API
A feature engineering automation tool
MyLibLinear.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 
6 #include "MyLibLinear.h"
7 
8 namespace shogun {
9 
10 
11  CMyLibLinear::CMyLibLinear(LIBLINEAR_SOLVER_TYPE l) : CLibLinear()
12  {
13  set_liblinear_solver_type(l);
14  }
15 
17  {
18  set_liblinear_solver_type(L2R_L1LOSS_SVC_DUAL);
19  set_bias_enabled(false);
20  set_C(1, 1);
21  set_max_iterations();
22  set_epsilon(1e-5);
24  set_compute_bias(false);
25 
26  SG_ADD(&C1, "C1", "C Cost constant 1.", MS_AVAILABLE);
27  SG_ADD(&C2, "C2", "C Cost constant 2.", MS_AVAILABLE);
28  SG_ADD(
29  &use_bias, "use_bias", "Indicates if bias is used.", MS_NOT_AVAILABLE);
30  SG_ADD(&epsilon, "epsilon", "Convergence precision.", MS_NOT_AVAILABLE);
31  SG_ADD(
32  &max_iterations, "max_iterations", "Max number of iterations.",
33  MS_NOT_AVAILABLE);
34  SG_ADD(&m_linear_term, "linear_term", "Linear Term", MS_NOT_AVAILABLE);
35  SG_ADD(
36  (machine_int_t*)&liblinear_solver_type, "liblinear_solver_type",
37  "Type of LibLinear solver.", MS_NOT_AVAILABLE);
38  }
39 
40  // WGL: updated definitions to allow probabilities to be calculated
41  void CMyLibLinear::set_probabilities(CLabels* labels, CFeatures* data)
42  {
43  // get probabilities for each output
44  if (liblinear_solver_type == L1R_LR ||
45  liblinear_solver_type == L2R_LR_DUAL ||
46  liblinear_solver_type == L2R_LR )
47  {
48  SGVector<float64_t> outputs = apply_get_outputs(data);
49  predict_probability(labels,outputs);
50  }
51  else
52  dynamic_cast<CBinaryLabels*>(labels)->scores_to_probabilities();
53  }
54 
55  void CMyLibLinear::predict_probability(CLabels* labels, const SGVector<float64_t>& outputs)
56  {
57  /* cout << "outputs:\n"; */
58  /* outputs.display_vector(); */
59 
60  for (int i = 0; i < outputs.size(); ++i)
61  {
62  labels->set_value(1/(1+exp(-outputs[i])),i);
63  }
64  }
65 
66 } /* namespace shogun */
67 
68 
void predict_probability(CLabels *labels, const SGVector< float64_t > &outputs)
Definition: MyLibLinear.cc:55
CMyLibLinear(LIBLINEAR_SOLVER_TYPE liblinear_solver_type)
Definition: MyLibLinear.cc:11
void set_probabilities(CLabels *labels, CFeatures *data)
Definition: MyLibLinear.cc:41
int i
Definition: params.cc:552