itpp::mat cov(const itpp::mat inputMat)
	{
		itpp::mat l_oResult(inputMat.rows(),inputMat.rows());
		itpp::mat centeredMat(inputMat.rows(),inputMat.rows());
		centeredMat = itpp::repmat(itpp::sum(inputMat,2), 1, inputMat.cols(), false);
		centeredMat = centeredMat / ((double)inputMat.cols());
		centeredMat = inputMat-centeredMat;
		l_oResult = centeredMat*centeredMat.transpose();
		l_oResult = l_oResult / ((double)(inputMat.cols()-1));
		l_oResult = l_oResult / itpp::trace(l_oResult);
		return l_oResult;
	}
Пример #2
0
Файл: stc.cpp Проект: nvmd/itpp
itpp::mat STC::mat_pow(const itpp::mat &in_mat, int in_exp)
//square matrix power of integer exponent
{
    if (in_exp==0)
    {
        return itpp::eye(in_mat.rows());
    }
    itpp::mat out = in_mat;
    int abs_in_exp = std::abs(in_exp);
    register int n;
    for (n=1; n<abs_in_exp; n++)
    {
        out *= in_mat;
    }
    return (in_exp>0)?out:itpp::inv(out);
}