Appending margin, upper_margin and lower_margin parameters to Partitioner class.
This commit is contained in:
parent
a094ba04d4
commit
cbaa3942eb
@ -35,6 +35,12 @@ class Partitioner(object):
|
|||||||
"""A ordered list of the fuzzy sets names, sorted by their middle point"""
|
"""A ordered list of the fuzzy sets names, sorted by their middle point"""
|
||||||
self.kdtree = None
|
self.kdtree = None
|
||||||
"""A spatial index to help in fuzzyfication"""
|
"""A spatial index to help in fuzzyfication"""
|
||||||
|
self.margin = kwargs.get("margin", 0.1)
|
||||||
|
"""The upper and lower exceeding margins for the known UoD. The default value is .1"""
|
||||||
|
self.lower_margin = kwargs.get("lower_margin", self.margin)
|
||||||
|
"""Specific lower exceeding margins for the known UoD. The default value is the self.margin parameter"""
|
||||||
|
self.upper_margin = kwargs.get("lower_margin", self.margin)
|
||||||
|
"""Specific upper exceeding margins for the known UoD. The default value is the self.margin parameter"""
|
||||||
|
|
||||||
if kwargs.get('preprocess',True):
|
if kwargs.get('preprocess',True):
|
||||||
|
|
||||||
@ -58,10 +64,10 @@ class Partitioner(object):
|
|||||||
ndata[ndata == -np.inf] = 0
|
ndata[ndata == -np.inf] = 0
|
||||||
_min = np.nanmin(ndata)
|
_min = np.nanmin(ndata)
|
||||||
|
|
||||||
self.min = float(_min * 1.1 if _min < 0 else _min * 0.9)
|
self.min = float(_min * (1 + self.lower_margin) if _min < 0 else _min * (1 - self.lower_margin))
|
||||||
|
|
||||||
_max = np.nanmax(ndata)
|
_max = np.nanmax(ndata)
|
||||||
self.max = float(_max * 1.1 if _max > 0 else _max * 0.9)
|
self.max = float(_max * (1 + self.upper_margin) if _max > 0 else _max * (1 - self.upper_margin))
|
||||||
|
|
||||||
self.sets = self.build(ndata)
|
self.sets = self.build(ndata)
|
||||||
|
|
||||||
|
@ -19,46 +19,37 @@ test_length = 200
|
|||||||
|
|
||||||
from pyFTS.common import Transformations
|
from pyFTS.common import Transformations
|
||||||
|
|
||||||
|
from pyFTS.benchmarks import naive
|
||||||
from pyFTS.partitioners import Grid, Util as pUtil
|
|
||||||
from pyFTS.benchmarks import benchmarks as bchmk
|
|
||||||
from pyFTS.models import chen, hofts, pwfts, hwang
|
|
||||||
from pyFTS.models.incremental import TimeVariant, IncrementalEnsemble
|
from pyFTS.models.incremental import TimeVariant, IncrementalEnsemble
|
||||||
|
from pyFTS.models.nonstationary import common, perturbation, partitioners as nspart
|
||||||
|
from pyFTS.models.nonstationary import nsfts, util as nsUtil
|
||||||
|
from pyFTS.partitioners import Grid
|
||||||
|
from pyFTS.models import hofts, pwfts
|
||||||
|
from pyFTS.benchmarks import Measures
|
||||||
|
from pyFTS.common import Transformations, Util as cUtil
|
||||||
|
|
||||||
|
diff = Transformations.Differential(lag=1)
|
||||||
|
|
||||||
train = dataset[:1000]
|
train = dataset[:1000]
|
||||||
test = dataset[1000:]
|
test = dataset[1000:]
|
||||||
|
|
||||||
window = 100
|
#grid = Grid.GridPartitioner(data=train, transformation=diff)
|
||||||
|
#model = pwfts.ProbabilisticWeightedFTS(partitioner=grid)
|
||||||
|
#model.append_transformation(diff)
|
||||||
|
|
||||||
batch = 10
|
model = naive.Naive()
|
||||||
|
|
||||||
num_models = 3
|
model.fit(train)
|
||||||
|
|
||||||
model1 = TimeVariant.Retrainer(partitioner_method=Grid.GridPartitioner, partitioner_params={'npart': 35},
|
for ct, ttrain, ttest in cUtil.sliding_window(test, 1000, .95, inc=.5):
|
||||||
fts_method=pwfts.ProbabilisticWeightedFTS, fts_params={}, order=1,
|
if model.shortname not in ('PWFTS','Naive'):
|
||||||
batch_size=batch, window_length=window * num_models)
|
model.predict(ttrain)
|
||||||
|
print(ttest)
|
||||||
model2 = IncrementalEnsemble.IncrementalEnsembleFTS(partitioner_method=Grid.GridPartitioner,
|
if len(ttest) > 0:
|
||||||
partitioner_params={'npart': 35},
|
forecasts = model.predict(ttest, steps_ahead=10)
|
||||||
fts_method=pwfts.ProbabilisticWeightedFTS, fts_params={}, order=1,
|
measures = Measures.get_point_ahead_statistics(ttest[1:11], forecasts)
|
||||||
batch_size=int(batch / 3), window_length=window,
|
|
||||||
num_models=num_models)
|
|
||||||
|
|
||||||
model1.fit(train)
|
|
||||||
model2.fit(train)
|
|
||||||
|
|
||||||
print(len(test))
|
|
||||||
'''
|
|
||||||
forecasts1 = model1.predict(test[:-10])
|
|
||||||
print(len(forecasts1))
|
|
||||||
forecasts1 = model1.predict(test[-10:], steps_ahead=10)
|
|
||||||
print(len(forecasts1))
|
|
||||||
'''
|
|
||||||
forecasts2 = model2.predict(test[:-10])
|
|
||||||
print(len(forecasts2))
|
|
||||||
forecasts2 = model2.predict(test[-10:], steps_ahead=10)
|
|
||||||
print(len(forecasts2))
|
|
||||||
|
|
||||||
|
print(measures)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
from pyFTS.models.nonstationary import partitioners as nspart, nsfts, honsfts
|
from pyFTS.models.nonstationary import partitioners as nspart, nsfts, honsfts
|
||||||
|
Loading…
Reference in New Issue
Block a user