STK++ 0.9.13
STK_ILeastSquare.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
34
35
36#ifndef STK_ILEASTSQUARE_H
37#define STK_ILEASTSQUARE_H
38
39#include <Sdk.h>
40#include "STK_Algebra_Util.h"
41
42namespace STK
43{
56template<class Derived>
57class ILeastSquare: public IRunnerBase, public IRecursiveTemplate<Derived>
58{
59 protected:
66 ILeastSquare( ArrayB const& b, ArrayA const& a, bool isBref=false, bool isAref=false)
67 : b_(b, isBref), a_(a, isAref), rank_(0)
68 {
69 if (b.beginRows() != b.beginCols())
70 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: b.beginRows() must be equal to b.beginCols());
71 if (a.beginRows() != a.beginCols())
72 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to a.beginCols());
73 if (a.beginRows() != b.beginRows())
74 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to b.beginRows());
75 }
76
80 template<class OtherArrayB, class OtherArrayA>
82 : b_(b), a_(a), rank_(0)
83 {
84 if (b.beginRows() != b.beginCols())
85 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: b.beginRows() must be equal to b.beginCols());
86 if (a.beginRows() != a.beginCols())
87 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to a.beginCols());
88 if (a.beginRows() != b.beginRows())
89 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to b.beginRows());
90 }
91
92 public:
94 virtual ~ILeastSquare() {};
95 // getters
97 Integer const& rank() const { return rank_;}
99 inline ArrayA const& a() const { return a_;}
101 inline ArrayB const& b() const { return b_;}
103 inline ArrayB const& x() const { return x_;}
109 virtual bool run();
115 template<class VecWeights>
116 bool run(VecWeights const& weights);
117
118 protected:
127};
128
129template<class Derived>
131{
132 if (a_.empty()||b_.empty()) { return true;}
133 // compute Least Square
134 return(this->asDerived().runImpl());
135}
136
137template<class Derived>
138template<class Weights>
139bool ILeastSquare<Derived>::run(Weights const& weights)
140{
141 if (a_.empty()||b_.empty()) { return true;}
142 // compute Least Square
143 return(this->asDerived().runImpl(weights));
144}
145
146
147} // namespace STK
148#endif /* STK_ILEASTSQUARE_H */
In this file we define and implement utilies class and method for the Algebra project.
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
This file include all the other header files of the project Sdk.
base class for template evaluation expressions and visitors.
bool run(VecWeights const &weights)
Compute the weighted Least-Square solution.
ILeastSquare(ExprBase< OtherArrayB > const &b, ExprBase< OtherArrayA > const &a)
template constructor
hidden::AlgebraTraits< Derived >::ArrayB ArrayB
hidden::AlgebraTraits< Derived >::ArrayA ArrayA
virtual ~ILeastSquare()
Destructor.
ArrayB const & x() const
Integer const & rank() const
virtual bool run()
Compute the Least-Square solution.
ILeastSquare(ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
Default constructor.
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.
IRunnerBase()
default constructor
Definition STK_IRunner.h:68
int Integer
STK fundamental type of integer values.
The namespace STK is the main domain space of the Statistical ToolKit project.
traits class for the algebra methods.