偏最小二乘 非线性 matlab,求助:Matlab偏最小二乘程序哪错了

希望好心人帮我看看程序哪错了,不甚感激!

data1=importdata('200520063.txt');

Y=data1.data(1,:)';N by P

M=length(Y);

X=data1.data(2:end,:)';%N by K

iter=2;%主成分分数

%数据标准化

for i =1:M

X_M(i,:)=(X(i,:)-mean(X))./std(X);

Y_M(i)=(Y(i,:)-mean(Y))./std(Y);

end

std_Y=std(Y);

ave_Y_new=mean(Y);

[N,K]=size(X_M);

[N,P]=size(Y_M);

if iter > min(N,K)

iter = min(N,K);

end

% start algrithm: PLS

for counter = 1:iter; % extract 3 PLS components

pls_u = Y_M(:,1); % get any column from Y

t_old_n = 1.0;% the ini of t old

t_new_n = 0.0;% the ini of t new

pls_t = 0;

while ( abs( t_old_n - t_new_n )>0.0001)

pls_t_old = pls_t;

% in the X block

pls_w = (pls_u' * X_M / ( pls_u' * pls_u ))';

pls_w = pls_w/norm(pls_w);

pls_t = X_M * pls_w;

% in the Y block

if(P>1)

pls_q = (pls_t' * Y_M /(pls_t'*pls_t))';

pls_q = pls_q/norm(pls_q);

pls_u = Y_M*pls_q;

else

pls_q=1;

end

% compare t,check for convergence

t_old_n = norm( pls_t_old );

t_new_n = norm( pls_t);

end

pls_p = (pls_t'*X_M/(pls_t'*pls_t))';

pls_p_n=norm(pls_p);

pls_p = pls_p/pls_p_n;

pls_t = pls_t*pls_p_n;

pls_w = pls_w*pls_p_n;

pls_b = pls_u'*pls_t/(pls_t'*pls_t);

X_M = X_M - pls_t*pls_p';

Y_M = Y_M - pls_b*pls_t*pls_q';

% pls_U(:,counter)=pls_u;

% pls_T(:,counter)=pls_t;

pls_P(:,counter)=pls_p;

pls_Q(:,counter)=pls_q;

pls_W(:,counter)=pls_w;

pls_B(:,counter)=pls_b;

end

% Now that correction is completed, start validation.

Y_P = 0;

for counter = 1:iter

Y_P =Y_P + pls_B(:,counter)*t_p*pls_Q(:,counter)';

end

for i = 1:N

Y_P(i)=Y_P(i)*std_Y+ave_Y_new;

end

最后的预测值有问题!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值