LDA.h
Go to the documentation of this file.
1//===========================================================================
2/*!
3 *
4 *
5 * \brief LDA
6 *
7 *
8 *
9 * \author O. Krause
10 * \date 2010
11 *
12 *
13 * \par Copyright 1995-2017 Shark Development Team
14 *
15 * <BR><HR>
16 * This file is part of Shark.
17 * <https://shark-ml.github.io/Shark/>
18 *
19 * Shark is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published
21 * by the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * Shark is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31 *
32 */
33//===========================================================================
34#ifndef SHARK_ALGORITHMS_TRAINERS_LDA_H
35#define SHARK_ALGORITHMS_TRAINERS_LDA_H
36
41
42namespace shark {
43
44
45///
46/// \brief Linear Discriminant Analysis (LDA)
47///
48/// This classes implements the well known linear discriminant analysis. LDA assumes that
49/// every point is drawn from a multivariate normal distributions. Every class has its own mean
50/// but all classes have the same covariance.
51///
52/// An arbitrary number of classes is supported. The resulting model is of the form
53/// \f[ \arg \max_c \log(p(x|c)*P(c)) \f]
54/// where \f$ p(x|c) = \exp(-(x-m_c)^T(C+\alpha I)(x-m_c)) \f$.
55/// \f$ m_c\f$ are the means of class c, \f$ C \f$ is the covariance matrix formed by all data points.
56/// The regularization paramter \f$ \alpha \f$ is by default 0. The trainer is implemented such, that
57/// it still works when C is singular, in this case the singular directions are ignored.
58/// \ingroup supervised_trainer
59class LDA : public AbstractWeightedTrainer<LinearClassifier<>, unsigned int>, public IParameterizable<>
60{
61public:
62 /// constructor
66
67 /// \brief From INameable: return the class name.
68 std::string name() const
69 { return "Linear Discriminant Analysis (LDA)"; }
70
71 /// return the regularization constant
72 double regularization()const{
73 return m_regularization;
74 }
75
76 /// set the regularization constant. 0 means no regularization.
81
82 /// inherited from IParameterizable; read the regularization parameter
83 RealVector parameterVector() const {
84 RealVector param(1);
85 param(0) = m_regularization;
86 return param;
87 }
88 /// inherited from IParameterizable; set the regularization parameter
89 void setParameterVector(RealVector const& param) {
90 SIZE_CHECK(param.size() == 1);
91 m_regularization = param(0);
92 }
93 /// inherited from IParameterizable
94 size_t numberOfParameters() const {
95 return 1;
96 }
97
98 /// Compute the LDA solution for a multi-class problem.
100 /// Compute the LDA solution for a weighted multi-class problem.
102
103protected:
104 ///The regularization parameter \f$ \lambda \f$ adds
105 /// \f$ - \lambda I \f$ to the second moment matrix, where
106 /// \f$ I \f$ is the identity matrix
108};
109
110}
111#endif
112