105 template<
class OutputMatrix>
109 assert (metric.rows() >= metric.cols());
110 assert (metric.rows() == metric.cols());
127 template<
class Matrix,
class OutputMatrix>
130 OutputMatrix& metric)
132 assert (data.
rows() >= data.
cols());
133 assert (metric.rows() == data.
cols());
134 assert (metric.rows() == metric.cols());
136 std::size_t nbvector = data.
rows();
137 std::size_t size = data.
cols();
138 std::size_t ncmetric = metric.cols();
139 value_type meanval = value_type(0.0);
140 value_type stddev = value_type(0.0);
141 for (std::size_t j = 0; j < size; ++j)
143 meanval = value_type(0.0);
144 for (std::size_t i = 0; i < nbvector; ++i)
146 meanval += data[i][j];
148 stddev = value_type(0.0);
149 for (std::size_t i = 0; i < nbvector; ++i)
151 stddev += (data[i][j] - meanval) * (data[i][j] - meanval);
154 for (std::size_t i = 0; i < ncmetric; ++i)
156 metric[i][j] = value_type(0.0);
158 metric[j][j] = value_type(1.0) /
std::sqrt(stddev);
175 template<
class Matrix,
class OutputMatrix>
178 OutputMatrix& centerdata,
179 const bool normalize_data =
false)
181 assert (data.
rows() >= data.
cols());
182 assert (data.
rows() == centerdata.rows());
183 assert (data.
cols() == centerdata.cols());
185 std::size_t nbvector = data.
rows();
186 std::size_t size = data.
cols();
191 value_type meanval = value_type(0.0);
192 value_type stddev = value_type(0.0);
193 for (std::size_t j = 0; j < size; ++j)
195 meanval = value_type(0.0);
196 for (std::size_t i = 0; i < nbvector; ++i)
198 meanval += data[i][j];
200 for (std::size_t i = 0; i < nbvector; ++i)
202 centerdata[i][j] -= meanval;
207 stddev = value_type(0.0);
208 for (std::size_t i = 0; i < nbvector; ++i)
210 stddev += (data[i][j] - meanval) * (data[i][j] - meanval);
213 for (std::size_t i = 0; i < nbvector; ++i)
215 centerdata[i][j] /= stddev;
238 template<
class Matrix,
class Matrix2,
class OutputMatrix,
class OutputVector>
242 const Matrix2& metric,
243 OutputVector & eigenval)
245 assert( acp.rows() == data.
rows());
246 assert( acp.cols() == data.
cols());
247 assert( data.
rows() >= data.
cols());
248 assert( eigenval.size() == data.
cols());
249 assert( metric.rows() == data.
cols());
250 assert( metric.rows() == metric.cols());
252 std::size_t nbvector = data.
rows();
253 std::size_t size = data.
cols();
260 for (std::size_t i = 0; i < nbvector; ++i)
262 P[i][i] = value_type(1.0) / ((value_type) nbvector);
293 template<
class Matrix,
class OutputMatrix>
296 OutputMatrix &result,
297 const std::size_t & nbaxis)
299 assert(acp.
rows() == result.rows());
300 assert(nbaxis <= acp.
cols());
302 std::size_t nbvector = acp.
rows();
303 for (std::size_t i = 0; i < nbvector; ++i)
305 for (std::size_t j = 0; j < nbaxis; ++j)
307 result[i][j] = acp[i][j];
329 template<
class Matrix,
class Matrix2,
class OutputMatrix>
332 const Matrix2& metric,
333 OutputMatrix &result,
334 const std::size_t & nbaxis,
335 const bool normalize_data =
false)
338 std::size_t nbvector = data.
rows();
339 std::size_t size = data.
cols();
378 template<
class Matrix,
class Matrix2,
class OutputMatrix>
381 const Matrix2& metric,
382 OutputMatrix &result,
383 const bool normalize_data =
false)
387 result, result.
cols(),normalize_data);
396 #endif //SLIP_PCA_HPP
iterator begin()
Returns a read/write iterator that points to the first element in the Matrix. Iteration is done in or...
size_type cols() const
Returns the number of columns (second dimension size) in the Matrix.
Provides common linear algebra algorithms.
void real(const Matrix1 &C, Matrix2 &R)
Extract the real Matrix of a complex Matrix. .
void pca_uniform_metric(OutputMatrix &metric)
Get uniform metric for PCA computation.
void pca_data_reduction(const Matrix &data, const Matrix2 &metric, OutputMatrix &result, const std::size_t &nbaxis, const bool normalize_data=false)
Data reduction using ACP.
void hermitian_eigen(const Matrix1 &A, Vector1 &EigenValues, Matrix2 &EigenVectors)
Eigen Values Computation of an hermitian semi-definite positive matrix.
Provides some statistics algorithms.
void pca_simple_data_reduction_axis(const Matrix &acp, OutputMatrix &result, const std::size_t &nbaxis)
Reduce ACP data.
Provides some algorithms to computes eigenvalues and eigenvectors.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Numerical Vector class. This container statisfies the RandomAccessContainer concepts of the Standard ...
Provides some mathematical functors and constants.
HyperVolume< T > sqrt(const HyperVolume< T > &M)
Matrix identity(const std::size_t nr, const std::size_t nc)
Returns an identity matrix which dimensions are nr*nc.
void matrix_matrix_multiplies(MatrixIterator1 M1_up, MatrixIterator1 M1_bot, MatrixIterator2 M2_up, MatrixIterator2 M2_bot, MatrixIterator3 R_up, MatrixIterator3 R_bot)
Computes the matrix matrix multiplication of 2 2d ranges.
Numerical matrix class. This container statisfies the BidirectionnalContainer concepts of the STL...
size_type rows() const
Returns the number of rows (first dimension size) in the Matrix.
iterator end()
Returns a read/write iterator that points one past the last element in the Matrix. Iteration is done in ordinary element order.
Provides a class to manipulate Numerical Matrix.
void pca_computation(const Matrix &data, OutputMatrix &acp, const Matrix2 &metric, OutputVector &eigenval)
Compute the PCA (data need to be centered)
void transpose(const Matrix1 &M, const std::size_t nr1, const std::size_t nc1, Matrix2 &TM, const std::size_t nr2, const std::size_t nc2)
Computes the transpose of a matrix .
void pca_center_data(const Matrix &data, OutputMatrix ¢erdata, const bool normalize_data=false)
Get uniform metric for PCA computation.
void pca_adaptative_metric(const Matrix &data, OutputMatrix &metric)
Get adaptative metric for PCA computation.
Provides a class to manipulate numerical vectors.