35#ifndef STK_LOCALVARIANCE_H
36#define STK_LOCALVARIANCE_H
169 , nbNeighbor_(nbNeighbor)
202 , nbNeighbor_(nbNeighbor)
203 , neighbors_(data.rows(),
Range(1,nbNeighbor_))
228 , nbNeighbor_(
reducer.nbNeighbor_)
229 , neighbors_(
reducer.neighbors_)
245#ifdef STK_REDUCT_DEBUG
250 neighbors_.resize(p_data_->rows(),
Range(1,nbNeighbor_));
273#ifdef STK_REDUCT_DEBUG
278 computeCovarianceMatrices();
290#ifdef STK_REDUCT_DEBUG
295 computeCovarianceMatrices(
weights);
310 covariance_.move(
stats_.covariance());
312 const Real pond = 2* nbNeighbor_ * p_data_->sizeRows();
315 localCovariance_.resize(p_data_->cols());
316 for (
int j=p_data_->beginCols();
j<p_data_->endCols();
j++)
318 for (
int k=p_data_->beginCols(); k<p_data_->endCols(); k++)
321 for (
int i=p_data_->beginRows();
i<p_data_->endRows();
i++)
323 for (
int l = 1;
l <= nbNeighbor_; ++
l)
325 sum += ((*p_data_)(
i,
j) - (*p_data_)(neighbors_(
i,
l),
j))
326 * ((*p_data_)(
i, k) - (*p_data_)(neighbors_(
i,
l), k));
342 covariance_.move(
stats_.covariance());
345 const Real pond = 2* nbNeighbor_ * p_data_->sizeRows() ;
347 localCovariance_.resize(p_data_->cols());
348 for (
int i=p_data_->beginCols();
i<p_data_->endCols();
i++)
350 for (
int j=p_data_->beginCols();
j<p_data_->endCols();
j++)
353 for (
int k=p_data_->beginRows(); k<p_data_->endRows(); k++)
355 for (
int l = 1;
l <= nbNeighbor_; ++
l)
358 * ((*p_data_)(k,
i) - (*p_data_)(neighbors_(k,
l),
i))
359 * ((*p_data_)(k,
j) - (*p_data_)(neighbors_(k,
l),
j));
373 Range range(p_data_->beginCols(), std::min(
this->dim_, p_data_->sizeCols()));
386 axis_.resize(p_data_->cols(), range);
387 idx_values_.resize(range);
388 axis_ = decomp->rotation().col(range);
389 idx_values_ = decomp->eigenValues()[range];
398 const int begin_ind = p_data_->beginRows();
399 const int last_ind = p_data_->lastIdxRows();
444 dist_.resize(p_data_->rows(),
Range(1,nbNeighbor_));
447 const int begin_ind = p_data_->beginRows();
448 const int last_ind = p_data_->lastIdxRows();
460 if (dist_(
i, nbNeighbor_) > d )
463 int pos = nbNeighbor_;
464 while (dist_(
i, pos) > d && pos-- > 1) {}
467 for (
int k= nbNeighbor_ -1; k>= pos; k--)
469 dist_(
i, k+1) = dist_(
i, k);
470 neighbors_(
i, k+1) = neighbors_(
i, k);
474 neighbors_(
i, pos) =
j;
477 if (dist_(
j, nbNeighbor_) > d )
480 int pos = nbNeighbor_;
481 while (dist_(
j, pos) > d && pos-- > 1) {}
484 for (
int k= nbNeighbor_ -1; k>= pos; k--)
486 dist_(
j, k+1) = dist_(
j, k);
487 neighbors_(
j, k+1) = neighbors_(
j, k);
491 neighbors_(
j, pos) =
i;
In this file, we define the final class Array2D.
In this file we define the interface base class ILinearReduct.
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
In this file we define utilities enum and functions for the Reduct project.
In this file we specialize the class Multivariate to Real type.
In this file we define the SymEigen class (for a symmetric matrix).
void swap(int i, int j)
swap two elements: only for vectors and points
Derived & resize(Range const &I, Range const &J)
resize the array.
A ILinearReduct is an interface base class for reduction method using linear reduction.
Array * p_reduced_
The reduced data set.
Array axis_
The computed axis.
VectorX idx_values_
The values of the index for each axis.
virtual bool run()
run the computations.
virtual void setData(YArray_ const &y, XArray_ const &x)
set the data set.
Array const * p_data() const
get the data set
Array const * p_data_
A pointer on the original data set.
A LocalVariance is an implementation of the abstract ILinearReduct class.
ILinearReduct< Array, VectorX > Base
void minimalDistance()
compute the minimal distance graph
ArraySquareX const & localCovariance() const
virtual ~LocalVariance()
Destructor.
Reduct::TypeGraph type_
number of neighbors
void computeAxis()
compute the axis using the first eigenvectors of the matrix of covariance and local covariance
virtual LocalVariance * clone() const
clone pattern
ArrayXXi const & pred() const
LocalVariance(Reduct::TypeGraph type=Reduct::distance_, int nbNeighbor=1)
Default constructor.
LocalVariance(Array const *p_data, Reduct::TypeGraph type=Reduct::distance_, int nbNeighbor=1)
Constructor.
ArrayXXi neighbors_
Predecessor array : store the spanning tree or the minimal distance to the neighbors.
ArraySquareX localCovariance_
the local covariance Array
ArraySquareX covariance_
the covariance Array
hidden::Traits< Array >::Row RowVector
virtual void update()
Compute the proximity graph if the data set is modified.
ArraySquareX const & covariance() const
void computeCovarianceMatrices()
compute the covariances matrices of the data set
virtual void maximizeStep()
Compute the axis by maximizing the ratio of the local variance on the total variance of the data set.
void prim()
compute the minimal spanning tree
int nbNeighbor_
number of neighbors
ArrayXX dist_
distance matrix : store the minimal distance to the neighbors
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Computation of the multivariate statistics of a Variable.
Index sub-vector region: Specialization when the size is unknown.
Real dist(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y)
Compute the distance between two vectors.
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
double Real
STK fundamental type of Real values.
hidden::SliceVisitorSelector< Derived, hidden::MaxVisitor, Arrays::by_col_ >::type_result max(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
TypeGraph
Type of proximity graph to used in order to compute the local variance:
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.