STK++ 0.9.13
STK_MultiLeastSquare.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Algebra
27 * created on: 1 avr. 2015
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_MULTILEASTSQUARE_H
37#define STK_MULTILEASTSQUARE_H
38
39#include "STK_ILeastSquare.h"
40#include "STK_SymEigen.h"
42
43namespace STK
44{
45// forward declaration
46template<class ArrayB, class ArrayA> class MultiLeastSquare;
47namespace hidden
48{
52template<class ArrayB_, class ArrayA_>
58
59} // namespace hidden
60
79template<class ArrayB, class ArrayA>
80class MultiLeastSquare: public ILeastSquare<MultiLeastSquare<ArrayB, ArrayA> >
81{
82 public:
84 using Base::b_;
85 using Base::a_;
86 using Base::x_;
87 using Base::rank_;
92 inline MultiLeastSquare( ArrayB const& b, ArrayA const& a, bool isBref=false, bool isAref=false)
93 : Base(b, a, isBref, isAref) {}
95 inline virtual ~MultiLeastSquare() {};
97 bool runImpl();
99 template<class Weights>
100 bool runImpl(Weights const& weights);
101};
102
103template<class ArrayB, class ArrayA>
105{
106 // compute a'a
107 ArraySquareX prod = a_.transpose() * a_;
108 // compute (a'a)^{-1}
109 SymEigen<ArraySquareX> decomp(prod);
110 decomp.run();
111 rank_ = decomp.rank();
112 // compute (a'a)^{-1}b'a
113 if (a_.sizeRows() < b_.sizeCols())
114 { x_ = (decomp.ginv(prod) * a_.transpose()) * b_;}
115 else
116 { x_ = decomp.ginv(prod) * (a_.transpose() * b_);}
117 return true;
118}
119
120/* compute the weighted multidimensional regression */
121template<class ArrayB, class ArrayA>
122template<class Weights>
124{
126 // compute a'a
127 CSquareX prod = a_.transpose() * weights.diagonalize() * a_;
128 // compute (a'a)^{-1}
129 SymEigen<CSquareX> decomp(prod);
130 decomp.run();
131 rank_ = decomp.rank();
132 // compute (a'a)^{-1}b'a
133 if (a_.sizeRows() < b_.sizeCols())
134 { x_ = (decomp.ginv(prod) * a_.transpose()) * weights.diagonalize() * b_;}
135 else
136 { x_ = decomp.ginv(prod) * (a_.transpose() * weights.diagonalize() * b_);}
137 return true;
138}
139
140} // namespace STK
141#endif /* STK_MULTILEASTSQUARE_H */
In this file we implement the final class CArraySquare.
In this file we define the interface class ILeastSquare.
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
In this file we define the SymEigen class (for a symmetric matrix).
TransposeOperator< Derived > const transpose() const
The class ILeastSquare is an interface class for the methods solving the least-square problem.
ArrayB b_
Array or vector of the left hand side.
hidden::AlgebraTraits< MultiLeastSquare< ArrayB, ArrayA > >::ArrayB ArrayB
ArrayB x_
Array of the solution (a vector if b is a vector, a matrix otherwise)
hidden::AlgebraTraits< MultiLeastSquare< ArrayB, ArrayA > >::ArrayA ArrayA
virtual bool run()
run the computations.
The class MultiLeastSQquare solve the least square problem when the response b is multidimensional.
MultiLeastSquare(ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
constructor
bool runImpl()
compute the multidimensional regression
ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > > Base
virtual ~MultiLeastSquare()
Destructor.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
The namespace STK is the main domain space of the Statistical ToolKit project.
traits class for the algebra methods.