package org.cloudbus.cloudsim.codes.arima;

import java.util.ArrayList;

/**
 * ClassName ARIMAPredictionValue
 * Description
 * Create by HW
 * Date 2021/6/26 10:50
 */
public class ARIMAPredictionValue {
    public static double getFinalPredictionValue(double[] oldList) {
       /* double[] data=new double[]{1435.5, 1419.5, 1712.5, 1583.5, 1817.2, 1621.3, 1605.1, 1589, 1553.6, 1575.5,
                1586.1, 1678.8, 1553.5, 1436.2, 1404, 1430.9, 1516.8};*/
        ARIMAModel arima = new ARIMAModel(oldList);

        ArrayList<int[]> list = new ArrayList<>();
        int period = 1;
        int modelCnt = 5, cnt = 0;            //通过多次预测的平均值作为预测值
        double[] oldlist = new double[modelCnt];
        double[] tmpPredict = new double[modelCnt];
        for (int k = 0; k < modelCnt; ++k)            //控制通过多少组参数进行计算最终的结果
        {
            int[] bestModel = arima.getARIMAModel(period, list, k != 0);
            if (bestModel.length == 0) {
                tmpPredict[k] = oldList[oldList.length - period];
                cnt++;
                break;
            } else {
                double predictDiff = arima.predictValue(bestModel[0], bestModel[1], period);
                tmpPredict[k] = arima.aftDeal(predictDiff, period);
                oldlist[k] = tmpPredict[k];
                cnt++;
            }
            list.add(bestModel);
        }
        double sumPredict = 0.0;
        for (int k = 0; k < cnt; ++k) {
            sumPredict += (double) tmpPredict[k] / (double) cnt;
        }
       // System.out.println("预测值为："+sumPredict);
        return sumPredict;
    }
}
