Improvements on benchmarks.sliding_window_benchmarks for robustness; Bugfixes Hwang and CVFTS methods

This commit is contained in:
Petrônio Cândido 2018-08-01 13:59:33 -03:00
parent a8ed5a3db7
commit c6f9af8e00
4 changed files with 68 additions and 31 deletions

View File

@ -216,7 +216,6 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
nodes = kwargs.get("nodes", ['127.0.0.1']) nodes = kwargs.get("nodes", ['127.0.0.1'])
cluster, http_server = cUtil.start_dispy_cluster(experiment_method, nodes) cluster, http_server = cUtil.start_dispy_cluster(experiment_method, nodes)
experiments = 0
jobs = [] jobs = []
inc = __pop("inc", 0.1, kwargs) inc = __pop("inc", 0.1, kwargs)
@ -242,8 +241,12 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
if not distributed: if not distributed:
if progress: if progress:
progressbar.update(1) progressbar.update(1)
job = experiment_method(deepcopy(model), None, train, test, **kwargs) try:
synthesis_method(dataset, tag, job, conn) job = experiment_method(deepcopy(model), None, train, test, **kwargs)
synthesis_method(dataset, tag, job, conn)
except Exception as ex:
print("Error evaluating model " + model.shortname)
print(ex)
else: else:
job = cluster.submit(deepcopy(model), None, train, test, **kwargs) job = cluster.submit(deepcopy(model), None, train, test, **kwargs)
jobs.append(job) jobs.append(job)
@ -257,7 +260,6 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
for partition in partitions: for partition in partitions:
for partitioner in partitioners_methods: for partitioner in partitioners_methods:
print(transformation, partition)
data_train_fs = partitioner(data=train, npart=partition, transformation=transformation) data_train_fs = partitioner(data=train, npart=partition, transformation=transformation)
@ -276,8 +278,12 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
if not distributed: if not distributed:
if progress: if progress:
progressbar.update(1) progressbar.update(1)
job = experiment_method(deepcopy(model), deepcopy(partitioner), train, test, **kwargs) try:
synthesis_method(dataset, tag, job, conn) job = experiment_method(deepcopy(model), deepcopy(partitioner), train, test, **kwargs)
synthesis_method(dataset, tag, job, conn)
except Exception as ex:
print("Error evaluating model " + model.shortname + " " + str(partitioner))
print(ex)
else: else:
job = cluster.submit(deepcopy(model), deepcopy(partitioner), train, test, **kwargs) job = cluster.submit(deepcopy(model), deepcopy(partitioner), train, test, **kwargs)
job.id = id # associate an ID to identify jobs (if needed later) job.id = id # associate an ID to identify jobs (if needed later)

View File

@ -17,18 +17,15 @@ class HighOrderFTS(fts.FTS):
self.name = "Hwang High Order FTS" self.name = "Hwang High Order FTS"
self.shortname = "Hwang" self.shortname = "Hwang"
self.detail = "Hwang" self.detail = "Hwang"
self.configure_lags(**kwargs)
def configure_lags(self, **kwargs):
if "order" in kwargs:
self.order = kwargs.get("order", 2)
self.max_lag = self.order
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
if 'order' in kwargs:
self.order = kwargs.get('order',self.order)
self.max_lag = self.order
if self.sets == None:
self.sets = self.partitioner.sets
ordered_sets = self.partitioner.ordered_sets
else:
ordered_sets = FuzzySet.set_ordered(self.sets)
l = len(self.sets) l = len(self.sets)
@ -42,17 +39,17 @@ class HighOrderFTS(fts.FTS):
for t in np.arange(self.order-1, len(ndata)): for t in np.arange(self.order-1, len(ndata)):
for ix in range(l): for ix in range(l):
s = ordered_sets[ix] s = self.partitioner.ordered_sets[ix]
cn[ix] = self.sets[s].membership( FuzzySet.grant_bounds(ndata[t], self.sets, ordered_sets)) cn[ix] = self.sets[s].membership( FuzzySet.grant_bounds(ndata[t], self.sets, self.partitioner.ordered_sets))
for w in range(self.order - 1): for w in np.arange(self.order-1):
ow[w, ix] = self.sets[s].membership(FuzzySet.grant_bounds(ndata[t - w], self.sets, ordered_sets)) ow[w, ix] = self.sets[s].membership(FuzzySet.grant_bounds(ndata[t - w], self.sets, self.partitioner.ordered_sets))
rn[w, ix] = ow[w, ix] * cn[ix] rn[w, ix] = ow[w, ix] * cn[ix]
ft[ix] = max(ft[ix], rn[w, ix]) ft[ix] = max(ft[ix], rn[w, ix])
mft = max(ft) mft = max(ft)
out = 0.0 out = 0.0
count = 0.0 count = 0.0
for ix in range(l): for ix in range(l):
s = ordered_sets[ix] s = self.partitioner.ordered_sets[ix]
if ft[ix] == mft: if ft[ix] == mft:
out = out + self.sets[s].centroid out = out + self.sets[s].centroid
count += 1.0 count += 1.0
@ -61,4 +58,8 @@ class HighOrderFTS(fts.FTS):
return ret return ret
def train(self, data, **kwargs): def train(self, data, **kwargs):
pass
if self.sets == None:
self.sets = self.partitioner.sets
self.configure_lags(**kwargs)

View File

@ -46,6 +46,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS):
self.uod_clip = False self.uod_clip = False
self.order = 1 self.order = 1
self.min_order = 1 self.min_order = 1
self.max_lag = 1
self.inputs = [] self.inputs = []
self.forecasts = [] self.forecasts = []
self.residuals = [] self.residuals = []

View File

@ -39,15 +39,44 @@ from pyFTS.partitioners import Grid, Util as pUtil
from pyFTS.benchmarks import benchmarks as bchmk from pyFTS.benchmarks import benchmarks as bchmk
from pyFTS.models import chen from pyFTS.models import chen
tag = 'chen_partitioning' partitions = {'CMIV': {'BoxCox(0)': 17, 'Differential(1)': 7, 'None': 13},
'IMCV': {'BoxCox(0)': 22, 'Differential(1)': 9, 'None': 25},
'IMIV': {'BoxCox(0)': 27, 'Differential(1)': 11, 'None': 6},
'NASDAQ': {'BoxCox(0)': 39, 'Differential(1)': 10, 'None': 34},
'SP500': {'BoxCox(0)': 38, 'Differential(1)': 15, 'None': 39},
'TAIEX': {'BoxCox(0)': 36, 'Differential(1)': 18, 'None': 38}}
for ds in ['IMIV0']: #datasets.keys():
tag = 'benchmarks'
def nsfts_partitioner_builder(data, npart, transformation):
from pyFTS.partitioners import Grid
from pyFTS.models.nonstationary import perturbation, partitioners
tmp_fs = Grid.GridPartitioner(data=data, npart=npart, transformation=transformation)
fs = partitioners.SimpleNonStationaryPartitioner(data, tmp_fs,
location=perturbation.polynomial,
location_params=[1, 0],
location_roots=0,
width=perturbation.polynomial,
width_params=[1, 0],
width_roots=0)
return fs
for ds in datasets.keys():
dataset = datasets[ds] dataset = datasets[ds]
bchmk.sliding_window_benchmarks(dataset, 4000, train=0.2, inc=0.2, for tf in transformations.keys():
methods=[chen.ConventionalFTS], transformation = transformations[tf]
benchmark_models=False,
transformations=[boxcox], #transformations[t] for t in transformations.keys()], partitioning = partitions[ds][tf]
partitions=np.arange(3, 40, 1),
progress=False, type='point', bchmk.sliding_window_benchmarks(dataset, 2000, train=0.2, inc=0.2,
file="nsfts_benchmarks.db", dataset=ds, tag=tag) benchmark_models=False,
methods=[cvfts.ConditionalVarianceFTS],
partitioners_methods=[nsfts_partitioner_builder],
transformations=[transformation],
partitions=[partitioning],
progress=False, type='point',
file="nsfts_benchmarks.db", dataset=ds, tag=tag)