#include "stdafx.h"
#include "orsci.h"
using namespace orsci;
using namespace orsci::vmt;
int main(int argc, _TCHAR* argv[])
{
cout << " orsci: PCA -- based SVD " << endl;
cout << endl;
cout << " orsci:Principal component analysis (PCA)" << endl
<< " --- http://www.orsci.cn" << endl;
cout << "Part1:进行主成分分析系数矩阵计算!" << endl;
mdouble X;
//randn(13, 5, X);
X = "148 41 72 78;"
"139 34 71 76;"
"160 49 77 86;"
"149 36 67 79;"
"159 45 80 86;"
"142 31 66 76;"
"153 43 76 83;"
"150 43 77 79;"
"151 42 77 80;"
"139 31 68 74;"
"140 29 64 74;"
"161 47 78 84;"
"158 49 78 83;"
"140 33 67 77;"
"137 31 66 73;"
"152 35 73 79;"
"149 47 82 79;"
"145 35 70 77;"
"160 47 74 87;"
"156 44 78 85;"
"151 42 73 82;"
"147 38 73 78;"
"157 39 68 80;"
"147 30 65 75;"
"157 48 80 88;"
"151 36 74 80;"
"144 36 68 76;"
"141 30 67 76;"
"139 32 68 73;"
"148 38 70 78;";
cout << "X = " << endl;
cout << X << endl;
cout << "sample count = " << X.rowCount() << endl;
mdouble coeff_out, score_out;
coldouble latent_out;
coldouble tsquared_out;
rowdouble mu;
rowdouble mstddev;
if (true)
{
const bool mFlag = princomp_svd(X, coeff_out, score_out, latent_out, tsquared_out, mu, 2);
cout << "成功标记:" << mFlag << endl;
}
else
{
coldouble sampleWeight;
sampleWeight.Resize(X.rowCount());
sampleWeight.fill(1, 1); //这里模拟样本权重,按照顺序递增权重模拟。
sampleWeight /= sampleWeight.maxv();
rowdouble variableWeight;
variableWeight.Resize(X.colCount());
variableWeight.fill(1, 1); //这里模拟属性权重,按照顺序递增权重模拟。
variableWeight /= variableWeight.maxv();
const bool mFlag = princomp_svd_Weighted(X, sampleWeight, variableWeight, coeff_out, score_out, latent_out, tsquared_out, mu, 2);
cout << "成功标记:" << mFlag << endl;
}
cout << "score=" << endl;
cout << score_out << endl;
cout << "coeff=" << endl;
cout << coeff_out << endl;
cout << "latent=" << endl;
cout << latent_out << endl;
cout << "tsquared=" << endl;
cout<< tsquared_out << endl;
cout << "Part2:对新数据进行映射计算!" << endl;
cout << princomp_svd_test(X, mu, coeff_out) << endl;
cout << endl;
cout << "press any key to stop..." << endl;
char pp;
cin >> pp;
return 0;
}
|