STK++ 0.9.13
STK_ProjectedVariance.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 * Purpose: Implementation of the ILinearReduct interface using the total variance.
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
31
32#ifndef STK_PROJECTEDVARIANCE_H
33#define STK_PROJECTEDVARIANCE_H
34
37#include "STK_ILinearReduct.h"
38
39namespace STK
40{
41
49template<class Array>
50class ProjectedVariance: public ILinearReduct<Array, VectorX>
51{
52 public:
54 using Base::p_data_;
55 using Base::p_reduced_;
56 using Base::axis_;
63 ProjectedVariance(Array const* p_data);
67 ProjectedVariance(Array const& data);
73 virtual ~ProjectedVariance();
77 inline virtual ProjectedVariance* clone() const
78 { return new ProjectedVariance(*this);}
79
80 protected:
83
84 private:
86 virtual void maximizeStep();
87
91 virtual void maximizeStep(VectorX const& weights);
93 void computeAxis();
95 virtual void update();
96};
97
98/* default constructor */
99template<class Array>
101/* Constructor.
102 * @param p_data a pointer on the constant data set to reduce.
103 **/
104template<class Array>
106 : Base(p_data)
107{}
108/* Constructor.
109 * @param data a constatn reference on the data set to reduce.
110 **/
111template<class Array>
113 : Base(data)
114{}
115/* Copy constructor.
116 * @param reducer the reducer to copy
117 **/
118template<class Array>
122
123 /* Destructor */
124template<class Array>
127
128/* Find the axis by maximizing the Index. */
129template<class Array>
131{
132#ifdef STK_REDUCT_DEBUG
133 if (!p_data_)
135#endif
136 covariance_.move(Stat::covariance(*p_data_, true));
137 computeAxis();
138}
139
140/* Find the axis by maximizing the weighed Index.
141 * @param weights the weights of the samples.
142 **/
143template<class Array>
145{
146#ifdef STK_REDUCT_DEBUG
147 if (!p_data_)
149#endif
150 covariance_.move(Stat::covariance(*p_data_, weights, true));
151 computeAxis();
152}
153
154/* compute axis and index. */
155template<class Array>
157{
158 SymEigen<ArraySquareX> eigen(covariance_);
159 eigen.run();
160
161 // compute the range of the axis
162 Range range(p_data_->beginCols(), std::min(this->dim_, p_data_->sizeCols()));
163 // copy axis and index values
164 axis_.resize(p_data_->cols(), range);
165 idx_values_.resize(range);
166 axis_ = eigen.rotation().col(range);
167 idx_values_ = eigen.eigenValues().sub(range);
168}
169
170/* update the class if a new data set is set */
171template<class Array>
173{
174 covariance_.clear();
175}
176
177
178} // namespace STK
179
180#endif /* STK_PROJECTEDVARIANCE_H_ */
In this file we define the interface base class ILinearReduct.
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
In this file we specialize the class Multivariate to Real type.
In this file we define the SymEigen class (for a symmetric matrix).
A ILinearReduct is an interface base class for reduction method using linear reduction.
Array * p_reduced_
The reduced data set.
VectorX idx_values_
The values of the index for each axis.
virtual bool run()
run the computations.
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...
A ProjectedVariance is an implementation of the abstract ILinearReduct interface.
void computeAxis()
compute axis and index.
virtual void maximizeStep()
Find the axis by maximizing the Index.
virtual ProjectedVariance * clone() const
clone pattern
ProjectedVariance()
default constructor
virtual void update()
update the class if a new data set is set.
ILinearReduct< Array, VectorX > Base
ArraySquareX covariance_
the covariance Array
virtual ~ProjectedVariance()
Destructor.
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
Real covariance(ExprBase< XArray > const &X, ExprBase< YArray > const &Y, bool unbiased=false)
Compute the covariance of the variables X and Y.
The namespace STK is the main domain space of the Statistical ToolKit project.