?? movingaveragepredict.java
字號:
package com.eastcom.canicula.SHM.futurePredictor.predictAlgorithms;
import java.text.DecimalFormat;
/**
* @author jakcy_wu(wujichun)
*
* 預測分析--本算法只適用于受周期變化或者波動影響的數據
* 權值移動平均算法
* 本期預測值=(前期值*權數)求和/n
*
* 默認權值為{1,1,1},取最近3次的平均
* 注意權值和必須=權值集合.length
*/
public class movingAveragePredict extends predictBase {
private double[] historyArrayData;
private double[] weight={1,1,1};
public movingAveragePredict(double[] myHistoryArrayData){
int len=myHistoryArrayData.length ;
historyArrayData=new double[len];
for(int i=0;i<len;i++) historyArrayData[i]=myHistoryArrayData[i];
}
public movingAveragePredict(double[] myHistoryArrayData,double[] myWeight){
this(myHistoryArrayData);
int xLength=myWeight.length ;
weight=new double[xLength];
for(int i=0;i<xLength;i++) weight[i]=myWeight[i];
}
public double[][] predict(){
int len=historyArrayData.length +1;
int xLen=weight.length ;
if( xLen>len) return null;
DecimalFormat def=new DecimalFormat(".00");
double[][] result=new double[2][len];
for(int i=0;i<len;i++) result[0][i]=i;
for(int i=0;i<xLen;i++) result[1][i]=historyArrayData[i];
for(int i=xLen;i<len;i++) {
double temp=0;
//取前n次權值和求平均
for(int j=0;j<xLen;j++) temp+= historyArrayData[i-j-1]*weight[j];
//格式化
String abc=def.format(temp/xLen);
result[1][i]=Double.parseDouble(abc );
}
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -