LinearRegression.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Linear Regression
6  *
7  * \par
8  * This implementation is based on a class removed from the
9  * LinAlg package, written by M. Kreutz in 1998.
10  *
11  *
12  *
13  * \author T. Glasmachers
14  * \date 2007-2011
15  *
16  *
17  * \par Copyright 1995-2017 Shark Development Team
18  *
19  * <BR><HR>
20  * This file is part of Shark.
21  * <http://shark-ml.org/>
22  *
23  * Shark is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU Lesser General Public License as published
25  * by the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * Shark is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31  * GNU Lesser General Public License for more details.
32  *
33  * You should have received a copy of the GNU Lesser General Public License
34  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
35  *
36  */
37 //===========================================================================
38 
39 
40 #ifndef SHARK_ALGORITHMS_TRAINERS_LINEARREGRESSION_H
41 #define SHARK_ALGORITHMS_TRAINERS_LINEARREGRESSION_H
42 
43 #include <shark/Core/DLLSupport.h>
47 
48 namespace shark {
49 
50 
51 /*!
52  * \brief Linear Regression
53  *
54  * Linear Regression builds an affine linear model
55  * \f$ f(x) = A x + b \f$ minimizing the squared
56  * error from a dataset of pairs of vectors (x, y).
57  * That is, the error
58  * \f$ \sum_i (f(x_i) - y_i)^2 \f$ is minimized.
59  * The solution to this problem is found analytically.
60  */
61 class LinearRegression : public AbstractTrainer<LinearModel<> >, public IParameterizable<>
62 {
63 public:
65 
66  /// \brief From INameable: return the class name.
67  std::string name() const
68  { return "LinearRegression"; }
69 
70  double regularization() const{
71  return m_regularization;
72  }
74  RANGE_CHECK(regularization >= 0.0);
76  }
77 
78  RealVector parameterVector() const {
79  RealVector param(1);
80  param(0) = m_regularization;
81  return param;
82  }
83  void setParameterVector(const RealVector& param) {
84  SIZE_CHECK(param.size() == 1);
85  m_regularization = param(0);
86  }
87  size_t numberOfParameters() const{
88  return 1;
89  }
90 
92 protected:
94 };
95 
96 
97 }
98 #endif
99