UFJF - Machine Learning Toolkit  0.51.8
PrimalRegressor.hpp
1 //
2 // Created by mateus558 on 03/11/18.
3 //
4 
5 #pragma once
6 
7 #include "Regressor.hpp"
8 
9 namespace mltk::regressor {
10  template<typename T>
11  class PrimalRegressor : public Regressor<T> {
12  // Attributes
13  protected :
15  std::vector<double> w;
16 
17  public:
18 
19  PrimalRegressor() = default;
20 
21  explicit PrimalRegressor(DataPointer<T> samples) : Regressor<T>(samples) {}
22 
23  double evaluate(const Point<T> &p, bool raw_value = false) override {
24  double func = 0.0;
25  size_t i, dim = this->solution.w.size();
26 
27  if (p.X().size() != dim) {
28  std::cerr << "The point must have the same dimension of the feature set!" << std::endl;
29  return 0;
30  }
31 
32  for (func = this->solution.bias, i = 0; i < dim; i++) {
33  func += this->solution.w[i] * p[i];
34  }
35 
36  return func;
37  }
38 
39  /*********************************************
40  * Getters *
41  *********************************************/
42 
43  std::string getFormulationString() override { return "Primal"; }
44 
45  /*********************************************
46  * Setters *
47  *********************************************/
48 
49  };
50  }
std::shared_ptr< Data< T > > samples
Samples used in the model training.
Definition: Learner.hpp:21
Rep const & X() const
Returns the attributes representation of the point (std::vector by default).
Definition: Point.hpp:139
std::size_t size() const
Returns the dimension of the point.
Definition: Point.hpp:133
double bias
Bias of the solution.
Definition: Solution.hpp:23
mltk::Point< double > w
Weights vector.
Definition: Solution.hpp:17
Definition: PrimalRegressor.hpp:11
double evaluate(const Point< T > &p, bool raw_value=false) override
Returns the class of a feature point based on the trained Learner.
Definition: PrimalRegressor.hpp:23
std::vector< double > w
Weights vector.
Definition: PrimalRegressor.hpp:15
std::string getFormulationString() override
getFormulationString Returns a string that represents the formulation of the learner (Primal or Dual)...
Definition: PrimalRegressor.hpp:43
Definition: regressor/Regressor.hpp:16
Solution solution
Regressor solution.
Definition: regressor/Regressor.hpp:19
Namespace for regression methods.
Definition: DualRegressor.hpp:10