Bugfixes in FTS, HOFTS and CVFTS
This commit is contained in:
parent
c6f9af8e00
commit
f5652f7029
@ -332,11 +332,11 @@ def get_point_statistics(data, model, **kwargs):
|
||||
if not isinstance(forecasts, (list, np.ndarray)):
|
||||
forecasts = [forecasts]
|
||||
|
||||
nforecasts = np.array(forecasts[:-1])
|
||||
forecasts = np.array(forecasts[:-1])
|
||||
|
||||
ret.append(np.round(rmse(ndata[model.max_lag:], nforecasts), 2))
|
||||
ret.append(np.round(mape(ndata[model.max_lag:], nforecasts), 2))
|
||||
ret.append(np.round(UStatistic(ndata[model.max_lag:], nforecasts), 2))
|
||||
ret.append(np.round(rmse(ndata[model.max_lag:], forecasts), 2))
|
||||
ret.append(np.round(mape(ndata[model.max_lag:], forecasts), 2))
|
||||
ret.append(np.round(UStatistic(ndata[model.max_lag:], forecasts), 2))
|
||||
else:
|
||||
steps_ahead_sampler = kwargs.get('steps_ahead_sampler', 1)
|
||||
nforecasts = []
|
||||
|
@ -7,6 +7,7 @@
|
||||
import datetime
|
||||
import time
|
||||
from copy import deepcopy
|
||||
import traceback
|
||||
|
||||
import matplotlib as plt
|
||||
import matplotlib.cm as cmx
|
||||
@ -245,8 +246,8 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
|
||||
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)
|
||||
print('EXCEPTION! ', model.shortname, model.order)
|
||||
traceback.print_exc()
|
||||
else:
|
||||
job = cluster.submit(deepcopy(model), None, train, test, **kwargs)
|
||||
jobs.append(job)
|
||||
@ -279,11 +280,14 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs):
|
||||
if progress:
|
||||
progressbar.update(1)
|
||||
try:
|
||||
print(model.shortname, model.order, partitioner.name,
|
||||
partitioner.partitions, str(partitioner.transformation))
|
||||
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)
|
||||
print('EXCEPTION! ',model.shortname, model.order, partitioner.name,
|
||||
partitioner.partitions, str(partitioner.transformation))
|
||||
traceback.print_exc()
|
||||
else:
|
||||
job = cluster.submit(deepcopy(model), deepcopy(partitioner), train, test, **kwargs)
|
||||
job.id = id # associate an ID to identify jobs (if needed later)
|
||||
|
@ -144,7 +144,7 @@ class FTS(object):
|
||||
|
||||
if not self.is_multivariate:
|
||||
kwargs['type'] = type
|
||||
ret = self.apply_inverse_transformations(ret, params=[data[self.order - 1:]], **kwargs)
|
||||
ret = self.apply_inverse_transformations(ret, params=[data[self.max_lag - 1:]], **kwargs)
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -38,6 +38,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS):
|
||||
self.shortname = "CVFTS "
|
||||
self.detail = ""
|
||||
self.flrgs = {}
|
||||
self.is_high_order = False
|
||||
if self.partitioner is not None:
|
||||
self.append_transformation(self.partitioner.transformation)
|
||||
|
||||
@ -256,4 +257,4 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS):
|
||||
|
||||
ret.append(itvl)
|
||||
|
||||
return ret
|
||||
return ret
|
@ -132,3 +132,19 @@ class SimpleNonStationaryPartitioner(partitioner.Partitioner):
|
||||
|
||||
def build(self, data):
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
def simplenonstationary_gridpartitioner_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
|
||||
|
@ -1,7 +1,7 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from pyFTS.common import Membership, Transformations
|
||||
from pyFTS.models.nonstationary import common, perturbation, partitioners, util
|
||||
from pyFTS.models.nonstationary import common, perturbation, partitioners as nspart, util
|
||||
from pyFTS.models.nonstationary import nsfts, cvfts
|
||||
from pyFTS.partitioners import Grid, Entropy
|
||||
import matplotlib.pyplot as plt
|
||||
@ -33,36 +33,47 @@ tdiff = Transformations.Differential(1)
|
||||
|
||||
boxcox = Transformations.BoxCox(0)
|
||||
|
||||
transformations = {'None': None, 'Differential(1)': tdiff, 'BoxCox(0)': boxcox }
|
||||
transformations = {
|
||||
'None': None,
|
||||
'Differential(1)': tdiff,
|
||||
'BoxCox(0)': boxcox
|
||||
}
|
||||
|
||||
from pyFTS.partitioners import Grid, Util as pUtil
|
||||
from pyFTS.benchmarks import benchmarks as bchmk
|
||||
from pyFTS.models import chen
|
||||
from pyFTS.models import chen, hofts, pwfts, hwang
|
||||
|
||||
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}}
|
||||
partitions = {'CMIV': {'BoxCox(0)': 36, 'Differential(1)': 11, 'None': 8},
|
||||
'IMCV': {'BoxCox(0)': 36, 'Differential(1)': 20, 'None': 16},
|
||||
'IMIV': {'BoxCox(0)': 39, 'Differential(1)': 12, 'None': 6},
|
||||
'IMIV0': {'BoxCox(0)': 39, 'Differential(1)': 12, 'None': 3},
|
||||
'NASDAQ': {'BoxCox(0)': 39, 'Differential(1)': 13, 'None': 36},
|
||||
'SP500': {'BoxCox(0)': 33, 'Differential(1)': 7, 'None': 33},
|
||||
'TAIEX': {'BoxCox(0)': 39, 'Differential(1)': 31, 'None': 33}}
|
||||
|
||||
|
||||
tag = 'benchmarks'
|
||||
'''
|
||||
for ds in datasets.keys():
|
||||
dataset = datasets[ds]
|
||||
|
||||
def nsfts_partitioner_builder(data, npart, transformation):
|
||||
from pyFTS.partitioners import Grid
|
||||
from pyFTS.models.nonstationary import perturbation, partitioners
|
||||
for tf in transformations.keys():
|
||||
transformation = transformations[tf]
|
||||
|
||||
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
|
||||
partitioning = partitions[ds][tf]
|
||||
|
||||
bchmk.sliding_window_benchmarks(dataset, 2000, train=0.2, inc=0.2,
|
||||
methods=[
|
||||
hwang.HighOrderFTS,
|
||||
hofts.HighOrderFTS,
|
||||
pwfts.ProbabilisticWeightedFTS],
|
||||
#orders = [3],
|
||||
benchmark_models=False,
|
||||
transformations=[transformation],
|
||||
partitions=[partitioning],
|
||||
progress=False, type='point',
|
||||
file="nsfts_benchmarks.db", dataset=ds, tag=tag)
|
||||
'''
|
||||
|
||||
for ds in datasets.keys():
|
||||
dataset = datasets[ds]
|
||||
@ -75,7 +86,7 @@ for ds in datasets.keys():
|
||||
bchmk.sliding_window_benchmarks(dataset, 2000, train=0.2, inc=0.2,
|
||||
benchmark_models=False,
|
||||
methods=[cvfts.ConditionalVarianceFTS],
|
||||
partitioners_methods=[nsfts_partitioner_builder],
|
||||
partitioners_methods=[nspart.simplenonstationary_gridpartitioner_builder],
|
||||
transformations=[transformation],
|
||||
partitions=[partitioning],
|
||||
progress=False, type='point',
|
||||
|
Loading…
Reference in New Issue
Block a user