Пример #1
0
                    dataio.load_other_data(other_file_location, datatype = 'f')

    data, times = dataio.load_traffic_data(files[0])
    sd, st = strip_data_days(data, times, ["Sun"])

    sun_data, sun_times = strip_data_days(data, times, ["Sun"])
    sd, st = strip_data_std(sun_data, sun_times, 4)
    sun_avg = np.average(sd, axis=0)
    sun_res = sun_data - sun_avg

    sun_1d = np.reshape(sun_data, -1)
    sun_avg_1d = np.resize(sun_avg, sun_data.size)
    ps = arima(sun_1d)

    mase = analysis.mase(sun_1d, sun_avg_1d)
    mape = analysis.mape(sun_1d, sun_avg_1d)

    print "Mean Mase:", mase
    print "Mean Mape:", mape

    mase = analysis.mase(sun_1d, ps)
    mape = analysis.mape(sun_1d, ps)

    print "SARIMA Mase:", mase
    print "SARIMA Mape:", mape
    """
    xdata = range(24)
    mpl.subplot(111)
    
    for p in weekend_res[0:300]:
        mpl.plot(xdata, p, 'k', alpha = 0.2)
Пример #2
0
        resEventData.append(r[9:17])

    #Convert to list
    tmp = np.array(resEventData)
    resEventData = tmp.tolist()

    resEventData = pybb.data.stripZero(resEventData, threshold=6)

    #Train HMM
    m, mdata, mout = khmm.train(resEventData, 1, actLength, \
                                    iterations = 20, outliers = False, \
                                    clustering = "kmeans++",
                                    verbose = False)

    mase = analysis.mase(sunData1d, fData1d)
    mape = analysis.mape(sunData1d, fData1d)

    print "Mean Mase:", mase
    print "Mean Mape:", mape

    #Setup forecast
    model = []
    model.append(gaussian.Gaussian(resData.mean(), resData.std()))
    #model.append(gaussian.Gaussian(0, resData.std()))
    model.append(m[0])

    bf = bayesianforecast.BayesianForecast(model)
    bf.setStd(0, resData.std())
    bf.setStd(1, resData.std())

    bfData1d, probs, windowLens, models = bf.windowForecast(resData1d, \
Пример #3
0
                    dataio.load_other_data(other_file_location, datatype = 'f')

    data, times = dataio.load_traffic_data(files[0])
    sd, st = strip_data_days(data, times, ["Sun"])

    sun_data, sun_times = strip_data_days(data, times, ["Sun"])
    sd, st = strip_data_std(sun_data, sun_times, 4)
    sun_avg = np.average(sd, axis = 0)
    sun_res = sun_data - sun_avg

    sun_1d = np.reshape(sun_data, -1)
    sun_avg_1d = np.resize(sun_avg, sun_data.size)
    ps = arima(sun_1d)

    mase = analysis.mase(sun_1d, sun_avg_1d)
    mape = analysis.mape(sun_1d, sun_avg_1d)
    
    print "Mean Mase:", mase
    print "Mean Mape:", mape
    
    mase = analysis.mase(sun_1d, ps)
    mape = analysis.mape(sun_1d, ps)
    
    print "SARIMA Mase:", mase
    print "SARIMA Mape:", mape
    
    
    """
    xdata = range(24)
    mpl.subplot(111)
    
Пример #4
0
    st = time.time()
    ftd = R.r('ftd = forecast.Arima(tmod)')
    print "Forecast Time = " + str(time.time() - st)

    fTData1d = np.array(ftd[8])
    fTData = np.array(fTData1d)
    fTData = np.reshape(fTData, (len(ftd[8]) / periodLength, periodLength))

    tres1d = np.array(ftd[9])
    tres = np.array(tres1d)
    tres = np.reshape(tres, (len(ftd[9]) / periodLength, periodLength))

    print "Arima Training data Std:", mod[1][0]**0.5

    mase = analysis.mase(tdata1d, fTData1d)
    mape = analysis.mape(tdata1d, fTData1d)

    print "Testing Mase:", mase
    print "Testing Mape:", mape

    #Make residual events
    resEventData = []
    for a in tacts:
        resEventData.append(tres[a[0]][a[1]:a[1] + actLength])

    resEventData = np.array(resEventData)
    resEventData = resEventData.tolist()

    #Train HMM
    m, mdata, mout = khmm.train(resEventData, 1, actLength, \
                                    iterations = 20, outliers = False, \
Пример #5
0
        
    #Convert to list
    tmp = np.array(resEventData)
    resEventData = tmp.tolist()
        
    resEventData = pybb.data.stripZero(resEventData, threshold = 6)
    

    #Train HMM
    m, mdata, mout = khmm.train(resEventData, 1, actLength, \
                                    iterations = 20, outliers = False, \
                                    clustering = "kmeans++", 
                                    verbose = False)
    
    mase = analysis.mase(sunData1d, fData1d)
    mape = analysis.mape(sunData1d, fData1d)

    print "Mean Mase:", mase
    print "Mean Mape:", mape
    
    
    #Setup forecast
    model = []
    model.append(gaussian.Gaussian(resData.mean(), resData.std()))
    #model.append(gaussian.Gaussian(0, resData.std()))
    model.append(m[0])
    
    bf = bayesianforecast.BayesianForecast(model)
    bf.setStd(0, resData.std())
    bf.setStd(1, resData.std())
    
Пример #6
0
    st = time.time()
    ftd = R.r('ftd = forecast.Arima(tmod)')
    print "Forecast Time = " + str(time.time() - st)

    fTData1d = np.array(ftd[8])
    fTData = np.array(fTData1d)
    fTData = np.reshape(fTData, (len(ftd[8])/periodLength, periodLength))

    tres1d = np.array(ftd[9])
    tres = np.array(tres1d)
    tres = np.reshape(tres, (len(ftd[9])/periodLength, periodLength))
    
    print "Arima Training data Std:", mod[1][0]**0.5
    
    mase = analysis.mase(tdata1d, fTData1d)
    mape = analysis.mape(tdata1d, fTData1d)

    print "Testing Mase:", mase
    print "Testing Mape:", mape

    #Make residual events
    resEventData = []
    for a in tacts:
        resEventData.append(tres[a[0]][a[1]:a[1] + actLength])
        
    resEventData = np.array(resEventData)
    resEventData = resEventData.tolist()
    
    #Train HMM
    m, mdata, mout = khmm.train(resEventData, 1, actLength, \
                                    iterations = 20, outliers = False, \