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 * <https://shark-ml.github.io/Shark/>
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
47
48namespace shark {
49
50
51/// \brief Linear Regression
52///
53/// Linear Regression builds an affine linear model
54/// \f$ f(x) = A x + b \f$ minimizing the squared
55/// error from a dataset of pairs of vectors (x, y).
56/// That is, the error
57/// \f$ \sum_i (f(x_i) - y_i)^2 \f$ is minimized.
58/// The solution to this problem is found analytically.
59/// \ingroup supervised_trainer
60class LinearRegression : public AbstractTrainer<LinearModel<> >, public IParameterizable<>
61{
62public:
64
65 /// \brief From INameable: return the class name.
66 std::string name() const
67 { return "LinearRegression"; }
68
69 double regularization() const{
70 return m_regularization;
71 }
76
77 RealVector parameterVector() const {
78 RealVector param(1);
79 param(0) = m_regularization;
80 return param;
81 }
82 void setParameterVector(const RealVector& param) {
83 SIZE_CHECK(param.size() == 1);
84 m_regularization = param(0);
85 }
86 size_t numberOfParameters() const{
87 return 1;
88 }
89
91protected:
93};
94
95
96}
97#endif
98