偏最小二乘灰色预测模型matlab代码
时间: 2023-09-03 10:15:41 浏览: 134
以下是偏最小二乘灰色预测模型的MATLAB代码:
```matlab
function [y_pred,coeff] = PLSGM(series,m)
% series: 输入的时间序列
% m: GM(1,1) 模型阶数
% y_pred: 预测的时间序列
% coeff: PLSGM 模型参数
n = length(series);
X = cumsum(series); % 构造累加序列
Y = X(2:end); % 一次累加后的序列
X = X(1:end-1); % 原始序列
W = ones(n-1,1); % 构造权重向量
for i = 2:n-1
W(i) = 1/2*(series(i)+series(i-1))/(sum(series(2:i))+sum(series(1:i-1)));
end
B = [W,-X]; % 矩阵 B
Y = log(Y); % 对 Y 取对数
[U,S,V] = svd(B,'econ'); % SVD 分解
V1 = V(:,1:m); % 取前 m 个特征向量
T = X*V1; % 得到 T 矩阵
coeff = pinv(T)*Y; % 计算 PLSGM 模型参数
t = (1:n)';
t_pred = (n+1:n+m)';
T_pred = t_pred*V1; % 预测阶段的 T 矩阵
Y_pred = exp(T_pred*coeff); % 预测阶段的 Y 值
y_pred = Y_pred - [series;zeros(m,1)]; % 得到预测阶段的 y 值
y_pred = y_pred(n+1:end); % 取最后 m 个预测值
end
```
使用示例:
```matlab
series = [20,22,25,28,31,35,40,45,50];
m = 2;
[y_pred,coeff] = PLSGM(series,m);
```
其中,`series` 是输入的时间序列,`m` 是 GM(1,1) 模型的阶数,`y_pred` 是预测的时间序列,`coeff` 是 PLSGM 模型的参数。
阅读全文
相关推荐


















