import mikera.vectorz.AVector; //导入方法依赖的package包/类
private void calcResult() {
Vector u=Vector.createLength(n);
Vector w=Vector.createLength(m);
Vector t=Vector.createLength(n);
Vector t_old=Vector.createLength(n);
Vector q=Vector.createLength(p);
Vector pv=Vector.createLength(m);
// normalise X
for (int j=0; j
AVector col=X.getColumnView(j);
double mean=col.elementSum()/n;
col.add(-mean);
}
for (int i=0; i
// chose u as column in X with highest sum of squares
u.set(X.getColumn(selectMaxSSColumn(X)));
int maxIterations=10;
int iterations=0;
while (iterations++<=maxIterations) {
w.setInnerProduct(u, X);
w.normalise();
t.setInnerProduct(X, w);
t.normalise();
q.setInnerProduct(t, Y);
if (q.normalise()==0) break; // exit if q length is zero
u.setInnerProduct(Y, q);
double dist=t.distance(t_old);
if(dist<0.00000000001) {
break;
} else {
t_old.set(t);
}
}
U.setColumn(i, u);
W.setColumn(i, w);
T.setColumn(i, t);
Q.setColumn(i, q);
b.set(i,t.dotProduct(u));
// X factor loadings
pv.setInnerProduct(t, X);
P.setColumn(i, pv);
//double tss=t.elementSquaredSum();
//if (tss!=0.0) pv.multiply(1.0/tss);
// deflate X = X - t.p'
pv.negate();
X.addOuterProduct(t, pv);
}
B.getLeadingDiagonal().set(b);
AMatrix ptinv=PseudoInverse.calculate(P.getTranspose());
coefficients.setInnerProduct(ptinv,B.innerProduct(Q.getTranspose()));
//constant.setInnerProduct(B,Q.getColumn(0));
constant.set(Q.getColumn(0));
constant.addInnerProduct(P.getColumn(0), coefficients,-1);;
}