Bugfix in mvfts and seasonal.common.FuzzySet
This commit is contained in:
parent
72b34217f8
commit
b0a0fa5fe0
@ -200,10 +200,13 @@ def get_fuzzysets(inst, fuzzy_sets, ordered_sets=None, alpha_cut=0.0):
|
|||||||
if ordered_sets is None:
|
if ordered_sets is None:
|
||||||
ordered_sets = set_ordered(fuzzy_sets)
|
ordered_sets = set_ordered(fuzzy_sets)
|
||||||
|
|
||||||
|
try:
|
||||||
fs = [ordered_sets[ix]
|
fs = [ordered_sets[ix]
|
||||||
for ix in __binary_search(inst, fuzzy_sets, ordered_sets)
|
for ix in __binary_search(inst, fuzzy_sets, ordered_sets)
|
||||||
if fuzzy_sets[ordered_sets[ix]].membership(inst) > alpha_cut]
|
if fuzzy_sets[ordered_sets[ix]].membership(inst) > alpha_cut]
|
||||||
return fs
|
return fs
|
||||||
|
except Exception as ex:
|
||||||
|
raise ex
|
||||||
|
|
||||||
|
|
||||||
def get_maximum_membership_fuzzyset(inst, fuzzy_sets, ordered_sets=None):
|
def get_maximum_membership_fuzzyset(inst, fuzzy_sets, ordered_sets=None):
|
||||||
|
@ -89,10 +89,9 @@ class FuzzySet(FuzzySet.FuzzySet):
|
|||||||
|
|
||||||
def __init__(self, datepart, name, mf, parameters, centroid, alpha=1.0, **kwargs):
|
def __init__(self, datepart, name, mf, parameters, centroid, alpha=1.0, **kwargs):
|
||||||
super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha,
|
super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha,
|
||||||
type=kwargs.get('type', 'seasonal'),
|
|
||||||
**kwargs)
|
**kwargs)
|
||||||
self.datepart = datepart
|
self.datepart = datepart
|
||||||
self.type = 'seasonal'
|
self.type = kwargs.get('type', 'seasonal')
|
||||||
|
|
||||||
def transform(self, x):
|
def transform(self, x):
|
||||||
if self.type == 'seasonal':
|
if self.type == 'seasonal':
|
||||||
|
@ -30,6 +30,8 @@ class TimeGridPartitioner(partitioner.Partitioner):
|
|||||||
self.min = tmp
|
self.min = tmp
|
||||||
self.max = self.season.value + tmp
|
self.max = self.season.value + tmp
|
||||||
|
|
||||||
|
self.type = kwargs.get('type','seasonal')
|
||||||
|
|
||||||
self.sets = self.build(None)
|
self.sets = self.build(None)
|
||||||
|
|
||||||
if self.ordered_sets is None and self.setnames is not None:
|
if self.ordered_sets is None and self.setnames is not None:
|
||||||
@ -40,7 +42,7 @@ class TimeGridPartitioner(partitioner.Partitioner):
|
|||||||
def build(self, data):
|
def build(self, data):
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
kwargs = {'variable': self.variable}
|
kwargs = {'variable': self.variable, 'type': self.type }
|
||||||
|
|
||||||
if self.season == DateTime.year:
|
if self.season == DateTime.year:
|
||||||
dlen = (self.max - self.min)
|
dlen = (self.max - self.min)
|
||||||
|
@ -21,10 +21,14 @@ from pyFTS.data import TAIEX, SP500, NASDAQ, Malaysia
|
|||||||
|
|
||||||
dataset = Malaysia.get_data('temperature')[:1000]
|
dataset = Malaysia.get_data('temperature')[:1000]
|
||||||
|
|
||||||
p = Entropy.EntropyPartitioner(data=dataset, npart=19)
|
p = Entropy.EntropyPartitioner(data=dataset, npart=3)
|
||||||
|
|
||||||
print(p)
|
print(p)
|
||||||
|
|
||||||
|
model = hofts.HighOrderFTS(partitioner=p, order=2, lags=[34, 47], alpha_cut=0.31390672707694006)
|
||||||
|
|
||||||
|
model.fit(dataset)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
#dataset = SP500.get_data()[11500:16000]
|
#dataset = SP500.get_data()[11500:16000]
|
||||||
#dataset = NASDAQ.get_data()
|
#dataset = NASDAQ.get_data()
|
||||||
|
@ -3,13 +3,6 @@ import matplotlib.pylab as plt
|
|||||||
from pyFTS.data import TAIEX as tx
|
from pyFTS.data import TAIEX as tx
|
||||||
from pyFTS.common import Transformations
|
from pyFTS.common import Transformations
|
||||||
|
|
||||||
|
|
||||||
from pyFTS.data import Malaysia
|
|
||||||
|
|
||||||
dataset = Malaysia.get_dataframe()
|
|
||||||
|
|
||||||
dataset["date"] = pd.to_datetime(dataset["time"], format='%m/%d/%y %I:%M %p')
|
|
||||||
|
|
||||||
from pyFTS.partitioners import Grid, Util as pUtil
|
from pyFTS.partitioners import Grid, Util as pUtil
|
||||||
from pyFTS.common import Transformations, Util
|
from pyFTS.common import Transformations, Util
|
||||||
from pyFTS.models.multivariate import common, variable, mvfts
|
from pyFTS.models.multivariate import common, variable, mvfts
|
||||||
@ -23,6 +16,13 @@ from pyFTS.models.multivariate import common, variable, mvfts
|
|||||||
from pyFTS.models.seasonal import partitioner as seasonal
|
from pyFTS.models.seasonal import partitioner as seasonal
|
||||||
from pyFTS.models.seasonal.common import DateTime
|
from pyFTS.models.seasonal.common import DateTime
|
||||||
|
|
||||||
|
#"""
|
||||||
|
from pyFTS.data import Malaysia
|
||||||
|
|
||||||
|
dataset = Malaysia.get_dataframe()
|
||||||
|
|
||||||
|
dataset["date"] = pd.to_datetime(dataset["time"], format='%m/%d/%y %I:%M %p')
|
||||||
|
|
||||||
mv_train = dataset.iloc[:100000]
|
mv_train = dataset.iloc[:100000]
|
||||||
|
|
||||||
sp = {'seasonality': DateTime.month , 'names': ['Jan','Feb','Mar','Apr','May','Jun','Jul', 'Aug','Sep','Oct','Nov','Dec']}
|
sp = {'seasonality': DateTime.month , 'names': ['Jan','Feb','Mar','Apr','May','Jun','Jul', 'Aug','Sep','Oct','Nov','Dec']}
|
||||||
@ -71,3 +71,37 @@ for k in [itertools.combinations(var_list, r) for r in range(2,len(var_list))]:
|
|||||||
model.target_variable = vload
|
model.target_variable = vload
|
||||||
model.fit(mv_train)
|
model.fit(mv_train)
|
||||||
models.append(model)
|
models.append(model)
|
||||||
|
#"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
dataset = pd.read_csv('/home/petronio/Downloads/priceHong')
|
||||||
|
dataset['hour'] = dataset.index.values % 24
|
||||||
|
|
||||||
|
data = dataset['price'].values.flatten()
|
||||||
|
|
||||||
|
train_split = 24 * 800
|
||||||
|
|
||||||
|
# Multivariate time series
|
||||||
|
|
||||||
|
train_mv = dataset.iloc[:train_split]
|
||||||
|
test_mv = dataset.iloc[train_split:]
|
||||||
|
|
||||||
|
vhour = variable.Variable("Hour", data_label="hour", partitioner=seasonal.TimeGridPartitioner, npart=24,
|
||||||
|
data=dataset,
|
||||||
|
partitioner_specific={'seasonality': DateTime.hour_of_day, 'type': 'common'})
|
||||||
|
vprice = variable.Variable("Price", data_label="price", partitioner=Grid.GridPartitioner, npart=25,
|
||||||
|
data=train_mv)
|
||||||
|
|
||||||
|
model1 = mvfts.MVFTS()
|
||||||
|
model1.shortname += "1"
|
||||||
|
model1.append_variable(vhour)
|
||||||
|
model1.append_variable(vprice)
|
||||||
|
model1.target_variable = vprice
|
||||||
|
model1.fit(train_mv)
|
||||||
|
|
||||||
|
model2 = mvfts.MVFTS()
|
||||||
|
model2.shortname += "2"
|
||||||
|
model2.append_variable(vhour)
|
||||||
|
model2.target_variable = vprice
|
||||||
|
model2.fit(train_mv)
|
||||||
|
"""
|
Loading…
Reference in New Issue
Block a user