% Function to compute starting valus for a multiple-regime Smooth
% Transition Regression (STR). The algorith is based on a grid search over
% the parameters gamma and c.
% Last update: October 4, 2006.
function [alphaf,betaf,lambdaf,gammaf,cf,bestcost]=startval(y,X,W,q,m,gamma,c)
% inputs:
% ------
% y: dependent variable.
% X: regressors.
% W: dummy regressors.
% q: transition variable.
% m: number of nonlinear terms (number of regimes - 1)
% gamma: gamma values for the previous nonlinear terms.
% c: c values for the previous nonlinear terms.
% outputs:
% -------
% alphaf: starting value for alpha.
% lambdaf: starting value for lambda.
% gammaf: starting value for gamma.
% cf: starting value for c.
% bestcost: cost function evaluated at the starting point.
bestcost=999999999999999999999999;
[T,nX] = size(X);
nW = size(W,2);
% Maximum and minimum values for gamma
% ------------------------------------
maxgamma = 50;
mingamma = 10;
rategamma = 1;
% Maximum and minumum values for c
% --------------------------------
minc=prctile(q,10);
maxc=prctile(q,90);
ratec=(maxc-minc)/200;
gamma(m,1) = 0;
c(m,1) = 0;
for newgamma=mingamma:rategamma:maxgamma
for newc=minc:ratec:maxc
gamma(m,1) = newgamma;
c(m,1) = newc;
Z = [X W];
for i=1:m
fX(:,i) = siglog(gamma(i)*(q-c(i)));
Z = [Z repmat(fX(:,i),1,nX).*X];
end
theta = pinv(Z'*Z)*Z'*y;
alpha = theta(1:nX);
if isempty(W)==1
beta=[];
else
beta = theta(nX+1:nX+nW);
end
lambda = reshape(theta(nX+nW+1:end),nX,m);
if isempty(W)==1
yhat = X*alpha + sum((fX*lambda').*X,2);
else
yhat = X*alpha + W*beta + sum((fX*lambda').*X,2);
end
e = y - yhat;
cost = sum(e.^2)/T;
if cost<=bestcost
bestcost = cost;
gammaf = gamma;
cf = c;
alphaf = alpha;
betaf = beta;
lambdaf = lambda;
end
end
end
Kinonoyomeo
- 粉丝: 94
- 资源: 1万+
最新资源
- 农场的农作物产量数据集(3K+ 记录,6特征)CSV
- 农作物产量推荐数据集(2K+记录,8特征)CSV
- 小飞兔:一键克隆网站的强大工具
- 中国科学技术大学大数据算法课程笔记2023.zip
- 帕金森病的神经活动数据集(400+记录,9特征)CSV
- 全球假期和旅行数据集(51K+记录,12特征)CSV
- 烹饪配方数据集(5k记录,20特征)CSV
- 基于java+springboot+mysql的穿戴搭配系统开题报告.docx
- 情绪和情感分析数据集(情绪:422k+句子,6类情绪,情感:3K+样本)CSV
- 税务风险识别数据集(1K记录,13特征)CSV
- 睡眠时间预测数据集(2K+ 记录,7特征)CSV
- 睡眠呼吸紊乱检测数据集(1K+记录,18特征,3文件)CSV
- 饮食推荐数据集(1K 记录,17特征)CSV
- 学生行为监测数据集(3K 记录,17特征)CSV
- 新能源汽车(NEV)故障诊断数据集(11K+ 记录,8特征)CSV
- 孕产妇健康和高危妊娠数据集(1K 记录,18特征)CSV
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0