Refactoring to help tasks automotion
This commit is contained in:
parent
26656153f4
commit
279679b3a4
@ -75,11 +75,16 @@ def allPointForecasters(data_train, data_test, partitions, max_order=3, statisti
|
||||
def getPointStatistics(data, models, externalmodels = None, externalforecasts = None, indexers=None):
|
||||
ret = "Model & Order & RMSE & SMAPE & Theil's U \\\\ \n"
|
||||
for count,model in enumerate(models,start=0):
|
||||
if indexers is not None:
|
||||
if indexers is not None and indexers[count] is not None:
|
||||
ndata = np.array(indexers[count].get_data(data[model.order:]))
|
||||
else:
|
||||
ndata = np.array(data[model.order:])
|
||||
|
||||
if model.isMultivariate or indexers is None:
|
||||
forecasts = model.forecast(data)
|
||||
elif not model.isMultivariate and indexers is not None:
|
||||
forecasts = model.forecast( indexers[count].get_data(data) )
|
||||
|
||||
if model.hasSeasonality:
|
||||
nforecasts = np.array(forecasts)
|
||||
else:
|
||||
|
@ -5,7 +5,6 @@ from pyFTS import fts, sfts, chen
|
||||
|
||||
class ContextualSeasonalFLRG(object):
|
||||
def __init__(self, seasonality):
|
||||
super(ContextualSeasonalFLRG, self).__init__(None,None)
|
||||
self.season = seasonality
|
||||
self.flrgs = {}
|
||||
|
||||
@ -43,7 +42,7 @@ class ContextualMultiSeasonalFTS(sfts.SeasonalFTS):
|
||||
|
||||
for flr in flrs:
|
||||
|
||||
if str(flr.index) not in self.flrgs:
|
||||
if str(flr.index) not in flrgs:
|
||||
flrgs[str(flr.index)] = ContextualSeasonalFLRG(flr.index)
|
||||
|
||||
flrgs[str(flr.index)].append(flr)
|
||||
@ -57,8 +56,11 @@ class ContextualMultiSeasonalFTS(sfts.SeasonalFTS):
|
||||
self.flrgs = self.generateFLRG(flrs)
|
||||
|
||||
def getMidpoints(self, flrg, data):
|
||||
ret = np.array([s.centroid for s in flrg.flrgs[data].RHS])
|
||||
if data.name in flrg.flrgs:
|
||||
ret = np.array([s.centroid for s in flrg.flrgs[data.name].RHS])
|
||||
return ret
|
||||
else:
|
||||
return np.array([data.centroid])
|
||||
|
||||
def forecast(self, data):
|
||||
|
||||
|
62
tests/cmsfts.py
Normal file
62
tests/cmsfts.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib as plt
|
||||
import matplotlib.pyplot as plt
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
|
||||
import datetime
|
||||
|
||||
import pandas as pd
|
||||
from pyFTS.partitioners import Grid, CMeans, FCM, Entropy
|
||||
from pyFTS.common import FLR,FuzzySet,Membership,Transformations,Util
|
||||
from pyFTS import fts,sfts
|
||||
from pyFTS.models import msfts
|
||||
from pyFTS.benchmarks import benchmarks as bchmk
|
||||
from pyFTS.benchmarks import Measures
|
||||
|
||||
os.chdir("/home/petronio/dados/Dropbox/Doutorado/Disciplinas/AdvancedFuzzyTimeSeriesModels/")
|
||||
|
||||
sonda = pd.read_csv("DataSets/SONDA_BSB_MOD.csv", sep=";")
|
||||
|
||||
sonda['data'] = pd.to_datetime(sonda['data'])
|
||||
|
||||
sonda = sonda[:][527041:]
|
||||
|
||||
sonda.index = np.arange(0,len(sonda.index))
|
||||
|
||||
|
||||
sonda_treino = sonda[:1051200]
|
||||
sonda_teste = sonda[1051201:]
|
||||
|
||||
|
||||
#res = bchmk.simpleSearch_RMSE(sonda_treino, sonda_teste,
|
||||
# sfts.SeasonalFTS,np.arange(3,30),[1],parameters=1440,
|
||||
# tam=[15,8], plotforecasts=False,elev=45, azim=40,
|
||||
# save=False,file="pictures/sonda_sfts_error_surface", intervals=False)
|
||||
|
||||
from pyFTS.common import Util
|
||||
from pyFTS.models import cmsfts
|
||||
|
||||
partitions = ['grid', 'entropy']
|
||||
|
||||
indexers = ['m15', 'Mh', 'Mhm15']
|
||||
|
||||
for max_part in [40, 50]:
|
||||
for part in partitions:
|
||||
fs = Util.load_obj("models/sonda_fs_" + part + "_" + str(max_part) + ".pkl")
|
||||
|
||||
for ind in indexers:
|
||||
ix = Util.load_obj("models/sonda_ix_" + ind + ".pkl")
|
||||
|
||||
model = cmsfts.ContextualMultiSeasonalFTS(part + " " + ind, ix)
|
||||
|
||||
model.train(sonda_treino, fs)
|
||||
|
||||
Util.persist_obj(model, "models/sonda_cmsfts_" + part + "_" + str(max_part) + "_" + ind + ".pkl")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user