|
STK++ 0.9.13
|
It's very easy to center a data set using high level template expressions and statistical functors.
Consider the following code and its output:
| Example: | Output: |
|---|---|
#include "STKpp.h"
using namespace STK;
{
CArrayXX A(100, 5);
Law::Normal law(1,2);
A.rand(law);
// call column statistical functions
// center the array
A -= Const::VectorX(100) * Stat::mean(A);
// call column statistical functions with all the columns of A centered
}
This file include all the header files of the STK++ project. hidden::FunctorTraits< Derived, MaxOp >::Row max(Derived const &A) Compute the maximal(s) value(s) of A. Definition STK_Stat_Functors.h:753 hidden::FunctorTraits< Derived, MeanOp >::Row mean(Derived const &A) Compute the mean(s) value(s) of A. Definition STK_Stat_Functors.h:799 hidden::FunctorTraits< Derived, MinOp >::Row min(Derived const &A) Compute the minimal(s) value(s) of A. Definition STK_Stat_Functors.h:726 The namespace STK is the main domain space of the Statistical ToolKit project. CArray< Real, UnknownSize, UnknownSize, Arrays::by_col_ > CArrayXX Definition STK_CArray.h:50 | min(A) =-4.66112 -3.1092 -2.76891 -4.65294 -5.47609 max(A) =4.17889 5.89107 5.08115 6.39462 5.17813 max(A.abs()) =4.66112 5.89107 5.08115 6.39462 5.47609 mean(A) =0.963606 1.26585 1.26198 1.05056 0.723175 Centering... min(A) =-5.62472 -4.37505 -4.0309 -5.7035 -6.19926 max(A) =3.21529 4.62522 3.81916 5.34406 4.45495 max(A.abs()) =5.62472 4.62522 4.0309 5.7035 6.19926 mean(A) =2.57572e-16 -3.93019e-16 2.13163e-16 -3.4639e-16 -1.15463e-16 |
The expression
represents the matrix multiplication of a column vector of 1 with 100 rows and of row vector with the mean of each column of A.
A we can get the maximal value in absolute value using max(A.abs()). It is possible to use functors mixed with unary or binary operators.