示例#1
0
                        )  # use ANN with the default layer structure "a"
                        # the default layer structure "a" is (# of attributes + # of classes) / 2, here is layers= [2]

                        if (steps != 0):
                            prediction = np.array(
                                result['predicted'][:] +
                                np.array(ARIMA_ts[mon - monlow])
                                [-steps - len(result['predicted'][:]):-steps])
                        else:
                            prediction = np.array(
                                result['predicted'][:] +
                                np.array(ARIMA_ts[mon - monlow])
                                [-len(result['predicted'][:]):])

                        error = weka._NorRMSE(
                            joined[mon - monlow]['ElNino_real']
                            [-len(result['predicted']):], prediction)
                        t = nn['t0'][-len(result['predicted']) - 1:-1]

                        if (i == 1 and j == 0 and k == 0 and l == 0):
                            res.append(prediction)
                            actual.append(joined[mon - monlow]['ElNino_real']
                                          [-len(result['predicted']):])
                            time.append(t)

                            avg_RMSE[mon - monlow] += error

                            if (mon == monhigh - 1):
                                res = np.array(res)
                                time = np.array(time)
                                actual = np.array(actual)
).astype(np.float)[:109]
ncep_timel6 = np.load(
    'C:/Users/User/Documents/Thesis/Hybrid_prediction_model/ClimateLearn/plotML/leadtimedata/2006-2012new/time6_2006to2015_NCEP.npy'
).astype(np.float)[:109]

ncep_obs = np.load(
    'C:/Users/User/Documents/Thesis/Hybrid_prediction_model/ClimateLearn/plotML/leadtimedata/2006-2012new/obs_2006to2015_NCEP.npy'
).astype(np.float)[:109]
ncep_obs_time = np.load(
    'C:/Users/User/Documents/Thesis/Hybrid_prediction_model/ClimateLearn/plotML/leadtimedata/2006-2012new/timeobs_2006to2015_NCEP.npy'
).astype(np.float)[:109]

#timen_ncep = ncep_time[(ncep_time[i]>=2005) & (ncep_time[i]<=maxtime)]
#ncep_monl3n = ncep_monl3[(ncep_time[i]>=2005) & (ncep_time[i]<=maxtime)]

rmse_ncep_3monl = weka._NorRMSE(ncep_monl3[15:], ncep_obs[15:])

cor3 = 0.32

mintimecor3 = 2004 + cor3
maxtimecor3 = 2014 + cor3
mintime3 = 2004 - cor3
maxtime3 = 2014

for i in range(1):
    bestresa = np.array(best_res3)[(time3 >= mintime3) & (time3 <= maxtime3)]
    timen = time3[(time3 >= mintime3) & (time3 <= maxtime3)] + cor3

    rmse_ncep_3monl = weka._NorRMSE(
        ncep_monl3[(ncep_timel3 >= timen[0])
                   & (ncep_timel3 <= timen[timen.shape[0] - 1])],
示例#3
0
                    ARIMA_ts[m] = np.append(
                        ARIMA_ts[m],
                        weka.forecasts(ARIMA_ninosq, steps, params, resids,
                                       ARIMA_ts[m])[-1])
                    ARIMA_ninosq = np.append(ARIMA_ninosq, (dic['ElNino'][i]))
                    if (i >= 1):
                        resids = np.append(
                            resids, ARIMA_ninosq[-1] - np.array(ARIMA_ts)[-1])
                    i += 1

                steps = steps - 1

                #Calculate Normalized Root Mean Squared Error
                if (steps != 0):
                    nrmse_ARIMA = weka._NorRMSE(
                        np.array(ARIMA_ts[m])[:-steps],
                        dicti['ElNino'][steps:])
                else:
                    nrmse_ARIMA = weka._NorRMSE(np.array(ARIMA_ts[m]),
                                                dicti['ElNino'])

                if (steps != 0):
                    plt.plot(np.array(ARIMA_ts[m])[:-steps])
                    plt.plot(dicti['ElNino'][steps:])
                else:
                    plt.plot(np.array(ARIMA_ts[m]))
                    plt.plot(dicti['ElNino'])
                plt.title('NRMSE:' + str(nrmse_ARIMA))
                plt.show()

                #Define the residual, to be predicted with ANN
示例#4
0
                        # the default layer structure "a" is (# of attributes + # of classes) / 2, here is layers= [2]

                        #Add ARIMA prediction and ANN prediction to get final prediction
                        if (steps != 0):
                            prediction = np.array(
                                result['predicted'][:] +
                                np.array(ARIMA_ts[mon - monlow])
                                [-steps - len(result['predicted'][:]):-steps])
                        else:
                            prediction = np.array(
                                result['predicted'][:] +
                                np.array(ARIMA_ts[mon - monlow])
                                [-len(result['predicted'][:]):])

                        error = weka._NorRMSE(
                            joined[mon - monlow]['ElNino_real']
                            [-len(result['predicted']):], prediction)
                        t = nn['t0'][-len(result['predicted']) - 1:-1]

                        if (ens10):
                            imax = np.where(RMSE == max(RMSE))[0][0]
                            if (RMSE[imax] > error
                                    and (np.absolute(prediction) < 5.).all()):
                                RMSE[imax] = error
                                ensemble10[imax]['prediction'] = prediction
                                ensemble10[imax]['NRMSE'] = error
                                ensemble10[imax]['s'] = s
                                ensemble10[imax]['actual'] = joined[
                                    mon - monlow]['ElNino_real'][
                                        -len(result['predicted']):]
                                ensemble10[imax]['time'] = t