资源简介
指数平滑用来做时间序列预测,数据是单个时间序列,输入数据格式为二维数据,
一维数据,只需定义一个一行多列的数组即可
代码片段和文件信息
import java.util.ArrayList;
import java.util.List;
public class Expones {
public static double[] get1_value(double data[][]) {
double a = 0.76;//指数平滑系数
List S_1 = new ArrayList();
double[] pre_values = new double[data.length];
double s1 = 0.0;
double st=0.0;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[0].length; j++) {
if (j < 4) {
s1 += data[i][j];
if (data[0].length < 20)
st=s1/3;
else
st=data[i][0];
}
}
S_1.add(st);
for (int k = 0; k S_1.add(a*data[i][k]+(1-a)*S_1.get(k));
}
pre_values[i]=S_1.get(S_1.size()-1);
}
return pre_values;
}
public static double[] get2_value(double data[][]int t) {
double a = 0.3;//指数平滑系数
List S_1 = new ArrayList();
List S2_1_new = new ArrayList();
List S2_2_new = new ArrayList();
double[] pre_values = new double[data.length];
double s1 = 0.0;
double st = 0.0;
double at =0.0;
double bt = 0.0;
double xt = 0.0;
for (int i = 0; i < data.length; i++) {
for (int j = 1; j < data[0].length; j++) {
if (j < 4) {
s1 += data[i][j - 1];
if (data[0].length < 20)
st = s1 / 3;
else
st = data[i][0];
}
}
S_1.add(st);//初始值
for (int k = 0; k < data[0].length; k++) {
if(k==0)
S2_1_new.add(a * data[i][k] + (1 - a) * S_1.get(k));
else
S2_1_new.add(a*data[i][k]+(1-a)*S2_1_new.get(k-1));
}
for (int l = 0; l if(l==0)
S2_2_new.add(a * S2_1_new.get(l) + (1 - a) * S_1.get(l));
else
S2_2_new.add(a*S2_1_new.get(l)+(1-a)*S2_2_new.get(l-1));
}
at=S2_1_new.get(S2_1_new.size()-1)*2-S2_2_new.get(S2_2_new.size()-1);
bt=a/(1-a)*(S2_1_new.get(S2_1_new.size()-1)-S2_2_new.
评论
共有 条评论