STK++ 0.9.13
STK_MultidimRegression.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::Regress
27 * created on: 27 oct. 2010
28 * Purpose: .
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
37#ifndef STK_MULTIDIMREGRESSION_H
38#define STK_MULTIDIMREGRESSION_H
39
40#include <Arrays/include/STK_Array2D.h> // for coefs
42#include "STK_IRegression.h"
43
44namespace STK
45{
46
50template<class Array, class Weight>
51class MultidimRegression: public IRegression<Array, Array, Weight>
52{
53 public:
55 using Base::p_x_;
56 using Base::p_y_;
60 MultidimRegression( Array const* y =0, Array const* x =0);
64 inline Array const& coefs() const { return coefs_;}
70 virtual Array extrapolate(Array const& x) const;
71
72 protected:
74
75 private:
77 virtual bool regressionStep();
81 virtual bool regressionStep(Weight const& weights);
83 virtual bool predictionStep();
87 inline virtual int computeNbFreeParameter() const
88 { return coefs_.sizeCols() * coefs_.sizeRows(); }
89};
90
91template<class Array, class Weight>
93 : Base(y, x)
94 , coefs_()
95{}
96
97/* compute the regression function. */
98template<class Array, class Weight>
100{
101 // compute X'X
102 ArraySquareX prod;
103 prod.move(multLeftTranspose(p_x_->asDerived()));
104 // compute (X'X)^{-1}
105// GInvertSymMatrix<ArraySquareX>()(prod);
106 // compute (X'X)^{-1}X'Y
107 coefs_.move(mult(invert(prod.symmetrize()), multLeftTranspose(p_x_->asDerived(), p_y_->asDerived())));
108 //coefs_.move(mult(prod, multLeftTranspose(p_x_->asDerived(), p_y_->asDerived())));
109 return true;
110}
111
112/* compute the regression function. */
113template<class Array, class Weight>
115{
116 // compute X'WX
117 ArraySquareX prod;
118 prod.move(weightedMultLeftTranspose(p_x_->asDerived(), weights));
119 // compute (X'WX)^{-1}
120 //GInvertSymMatrix<ArraySquareX>()(prod);
121 // compute (X'WX)^{-1}X'WY
122 coefs_.move(mult(invert(prod.symmetrize()), wmultLeftTranspose(p_x_->asDerived(), p_y_->asDerived(), weights)));
123// coefs_.move(mult(prod, wmultLeftTranspose(p_x_->asDerived(), p_y_->asDerived(), weights)));
124 return true;
125}
126
127/* Compute the predicted outputs by the regression function. */
128template<class Array, class Weight>
131
132/* @brief Extrapolate the the values @c y from the value @c x.
133 * Given the data set @c x will compute the values \f$ y = \hat{f}(x) \f$.
134 * The regression function @e f have to be estimated previously.
135 */
136template<class Array, class Weight>
138{ return(mult(x, coefs_));}
139
140} // namespace STK
141
142#endif /* STK_MULTIDIMREGRESSION_H */
In this file, we define the final class Array2D.
In this file we define the Interface base class IRegression.
In this file we implement inversion method for general matrix.
SymmetrizeOperator< Derived > const symmetrize() const
int sizeRows() const
Derived & move(Derived const &T)
move T to this.
int sizeCols() const
Interface base class for Regression methods.
Array predicted_
Container of the predicted output.
YArray_ const * p_y_
A pointer on the y data set.
XArray_ const * p_x_
A pointer on the x data set.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
virtual ~MultidimRegression()
Destructor.
virtual bool predictionStep()
Compute the predicted outputs by the regression function.
IRegression< Array, Array, Weight > Base
virtual int computeNbFreeParameter() const
Compute the number of parameter of the regression function.
MultidimRegression(Array const *y=0, Array const *x=0)
Constructor.
virtual Array extrapolate(Array const &x) const
virtual bool regressionStep()
compute the regression function.
Array const & coefs() const
hidden::AlgebraTraits< InvertMatrix< Matrix, hidden::Traits< Matrix >::sizeRows_ > >::Result invert(Matrix const &mat)
Utility function allowing to compute the inverse of a matrix.
Array2DSquare< typename Derived::Type > weightedMultLeftTranspose(ExprBase< Derived > const &A, ExprBase< Weights > const &weights)
Weighted matrix multiplication by its transpose.
Arrays::MultOp< Lhs, Rhs >::result_type mult(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type wmultLeftTranspose(Lhs const &lhs, Rhs const &rhs, Weights const &weights)
convenience function for the multiplication of two matrices
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type multLeftTranspose(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices
The namespace STK is the main domain space of the Statistical ToolKit project.