Improvements on benchmarks.sliding_window_benchmarks for robustness; Bugfixes Hwang and CVFTS methods
This commit is contained in:
parent
a8ed5a3db7
commit
c6f9af8e00
@ -216,7 +216,6 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
|
||||
nodes = kwargs.get("nodes", ['127.0.0.1'])
|
||||
cluster, http_server = cUtil.start_dispy_cluster(experiment_method, nodes)
|
||||
|
||||
experiments = 0
|
||||
jobs = []
|
||||
|
||||
inc = __pop("inc", 0.1, kwargs)
|
||||
@ -242,8 +241,12 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
|
||||
if not distributed:
|
||||
if progress:
|
||||
progressbar.update(1)
|
||||
try:
|
||||
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:
|
||||
job = cluster.submit(deepcopy(model), None, train, test, **kwargs)
|
||||
jobs.append(job)
|
||||
@ -257,7 +260,6 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
|
||||
for partition in partitions:
|
||||
|
||||
for partitioner in partitioners_methods:
|
||||
print(transformation, partition)
|
||||
|
||||
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 progress:
|
||||
progressbar.update(1)
|
||||
try:
|
||||
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:
|
||||
job = cluster.submit(deepcopy(model), deepcopy(partitioner), train, test, **kwargs)
|
||||
job.id = id # associate an ID to identify jobs (if needed later)
|
||||
|
@ -17,18 +17,15 @@ class HighOrderFTS(fts.FTS):
|
||||
self.name = "Hwang High Order FTS"
|
||||
self.shortname = "Hwang"
|
||||
self.detail = "Hwang"
|
||||
self.configure_lags(**kwargs)
|
||||
|
||||
def forecast(self, ndata, **kwargs):
|
||||
def configure_lags(self, **kwargs):
|
||||
if "order" in kwargs:
|
||||
self.order = kwargs.get("order", 2)
|
||||
|
||||
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)
|
||||
def forecast(self, ndata, **kwargs):
|
||||
|
||||
l = len(self.sets)
|
||||
|
||||
@ -42,17 +39,17 @@ class HighOrderFTS(fts.FTS):
|
||||
for t in np.arange(self.order-1, len(ndata)):
|
||||
|
||||
for ix in range(l):
|
||||
s = ordered_sets[ix]
|
||||
cn[ix] = self.sets[s].membership( FuzzySet.grant_bounds(ndata[t], self.sets, ordered_sets))
|
||||
for w in range(self.order - 1):
|
||||
ow[w, ix] = self.sets[s].membership(FuzzySet.grant_bounds(ndata[t - w], self.sets, ordered_sets))
|
||||
s = self.partitioner.ordered_sets[ix]
|
||||
cn[ix] = self.sets[s].membership( FuzzySet.grant_bounds(ndata[t], self.sets, self.partitioner.ordered_sets))
|
||||
for w in np.arange(self.order-1):
|
||||
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]
|
||||
ft[ix] = max(ft[ix], rn[w, ix])
|
||||
mft = max(ft)
|
||||
out = 0.0
|
||||
count = 0.0
|
||||
for ix in range(l):
|
||||
s = ordered_sets[ix]
|
||||
s = self.partitioner.ordered_sets[ix]
|
||||
if ft[ix] == mft:
|
||||
out = out + self.sets[s].centroid
|
||||
count += 1.0
|
||||
@ -61,4 +58,8 @@ class HighOrderFTS(fts.FTS):
|
||||
return ret
|
||||
|
||||
def train(self, data, **kwargs):
|
||||
pass
|
||||
|
||||
if self.sets == None:
|
||||
self.sets = self.partitioner.sets
|
||||
|
||||
self.configure_lags(**kwargs)
|
||||
|
@ -46,6 +46,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS):
|
||||
self.uod_clip = False
|
||||
self.order = 1
|
||||
self.min_order = 1
|
||||
self.max_lag = 1
|
||||
self.inputs = []
|
||||
self.forecasts = []
|
||||
self.residuals = []
|
||||
|
@ -39,15 +39,44 @@ from pyFTS.partitioners import Grid, Util as pUtil
|
||||
from pyFTS.benchmarks import benchmarks as bchmk
|
||||
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]
|
||||
|
||||
bchmk.sliding_window_benchmarks(dataset, 4000, train=0.2, inc=0.2,
|
||||
methods=[chen.ConventionalFTS],
|
||||
for tf in transformations.keys():
|
||||
transformation = transformations[tf]
|
||||
|
||||
partitioning = partitions[ds][tf]
|
||||
|
||||
bchmk.sliding_window_benchmarks(dataset, 2000, train=0.2, inc=0.2,
|
||||
benchmark_models=False,
|
||||
transformations=[boxcox], #transformations[t] for t in transformations.keys()],
|
||||
partitions=np.arange(3, 40, 1),
|
||||
methods=[cvfts.ConditionalVarianceFTS],
|
||||
partitioners_methods=[nsfts_partitioner_builder],
|
||||
transformations=[transformation],
|
||||
partitions=[partitioning],
|
||||
progress=False, type='point',
|
||||
file="nsfts_benchmarks.db", dataset=ds, tag=tag)
|
Loading…
Reference in New Issue
Block a user