STK++ 0.9.13
STK_ILinearReduct.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::AAModels
27 * created on: 17 avr. 2010
28 * Purpose: Abstract class for the computation of the Index in the SLAAM.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
37#ifndef STK_ILINEAREDUCT_H
38#define STK_ILINEAREDUCT_H
39
40#include "STK_IReducer.h"
42
43namespace STK
44{
62template<class Array, class Weights>
63class ILinearReduct: public IReducer<Array, Weights>
64{
65 public:
67 using Base::p_data_;
68 using Base::p_reduced_;
74 ILinearReduct( Array const* p_data);
78 ILinearReduct( Array const& data);
84 virtual ~ILinearReduct();
86 inline VectorX const& criteriaValues() const { return idx_values_; }
88 inline Array const& axis() const { return axis_; }
92 virtual bool run();
97 virtual bool run(Weights const& weights);
98
99 protected:
103 Array axis_;
104
105 private:
107 virtual void maximizeStep() =0;
111 virtual void maximizeStep( Weights const& weights) =0;
114};
115
116/*
117 * Constructor.
118 * @param data the input data set
119 */
120template<class Array, class Weights>
122
123/*
124 * Constructor.
125 * @param data the input data set
126 */
127template<class Array, class Weights>
128ILinearReduct<Array, Weights>::ILinearReduct( Array const* p_data): Base(p_data) {}
129/*
130 * Constructor.
131 * @param data the input data set
132 */
133template<class Array, class Weights>
135/* copy Constructor.
136 * @param reducer the reducer to copy.
137 **/
138template<class Array, class Weights>
140 : Base(reducer)
141 , idx_values_(reducer.idx_values_)
142 , axis_(reducer.axis_)
143{}
144/* Destructor */
145template<class Array, class Weights>
147
148/* Compute the Index.
149 * @param nbAxis number of Axis to compute
150 */
151template<class Array, class Weights>
153{
154 if (!this->p_data_)
155 { this->msg_error_ = STKERROR_NO_ARG(MultivariateArray::run(),data is not set);
156 return false;
157 }
158 try
159 {
160 // maximize the Index and compute the axis
161 maximizeStep();
162 // project data
163 projectionStep();
164
165 } catch (Exception const& e)
166 {
167 this->msg_error_ = e.error();
168 return false;
169 }
170 return true;
171}
172
173/*
174 * Compute the weighted index.
175 * @param weights the weights to used
176 * @param nbAxis number of Axis to compute
177 */
178template<class Array, class Weights>
180{
181 if (!this->p_data_)
182 { this->msg_error_ = STKERROR_NO_ARG(MultivariateArray::run(),data is not set);
183 return false;
184 }
185 try
186 {
187 // maximize the Index and compute the axis
188 maximizeStep(weights);
189 // project data
190 projectionStep();
191
192 } catch (Exception const& e)
193 {
194 this->msg_error_ = e.error();
195 return false;
196 }
197 return true;
198}
199
200/* Compute the reduction of the data set on the Axis. */
201template<class Array, class Weights>
203{
204 // check if p_reduced exists
205 if (!p_reduced_) p_reduced_ = new Array;
206 // compute matrix multiplication
207 *p_reduced_ = (*p_data_) * axis_;
208}
209
210
211} // namespace STK
212
213#endif /* STK_ILINEARREDUCT_H */
A Array2DVector is a one dimensional horizontal container.
In this file we define the interface base class IReducer.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
Sdk class for all library Exceptions.
virtual const String error() const
Returns a C-style character string describing the general cause of the current error.
A ILinearReduct is an interface base class for reduction method using linear reduction.
virtual void maximizeStep()=0
Find the axis by maximizing the Index.
virtual ~ILinearReduct()
virtual destructor
virtual bool run(Weights const &weights)
Compute the projection matrix set by maximizing the weighted criteria and project the data set in ord...
Array const & axis() const
ILinearReduct()
Default Constructor.
Array axis_
The computed axis.
void projectionStep()
Compute the projection of the data set on the Axis.
virtual bool run()
Compute the projection matrix axis_ by maximizing the criteria and project the data set in order to o...
virtual void maximizeStep(Weights const &weights)=0
Find the axis by maximizing the weighted Index.
ILinearReduct(ILinearReduct const &reducer)
copy Constructor.
VectorX idx_values_
The values of the index for each axis.
VectorX const & criteriaValues() const
ILinearReduct(Array const *p_data)
Constructor.
ILinearReduct(Array const &data)
Constructor.
IReducer< Array, Weights > Base
Interface base class for reducing methods.
Array * p_reduced_
The reduced data set.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
Array const * p_data() const
get the data set
Array const * p_data_
A pointer on the original data set.
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.