Bugfix on FuzzySet.__binary_search for multivariate/seasonal data; Introducing the FuzzySet.transform method
This commit is contained in:
parent
34f609d770
commit
5d90cbea82
@ -35,7 +35,10 @@ class FuzzySet(FuzzySet.FuzzySet):
|
|||||||
if self.superset:
|
if self.superset:
|
||||||
return max([s.membership(x) for s in self.sets])
|
return max([s.membership(x) for s in self.sets])
|
||||||
else:
|
else:
|
||||||
return min([self.mf[ct](x, self.parameters[ct]) for ct in np.arange(0, len(self.mf))])
|
return min([self.mf[ct](self.transform(x), self.parameters[ct]) for ct in np.arange(0, len(self.mf))])
|
||||||
|
|
||||||
|
def transform(self, x):
|
||||||
|
return self.sets[0].transform(x)
|
||||||
|
|
||||||
def append(self, mf, parameters):
|
def append(self, mf, parameters):
|
||||||
"""
|
"""
|
||||||
|
@ -35,6 +35,16 @@ class FuzzySet(object):
|
|||||||
self.upper = parameters[0] + parameters[1]*3
|
self.upper = parameters[0] + parameters[1]*3
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
|
|
||||||
|
def transform(self, x):
|
||||||
|
"""
|
||||||
|
Preprocess the data point for non native types
|
||||||
|
|
||||||
|
:param x:
|
||||||
|
:return: return a native type value for the structured type
|
||||||
|
"""
|
||||||
|
|
||||||
|
return x
|
||||||
|
|
||||||
def membership(self, x):
|
def membership(self, x):
|
||||||
"""
|
"""
|
||||||
Calculate the membership value of a given input
|
Calculate the membership value of a given input
|
||||||
@ -42,7 +52,7 @@ class FuzzySet(object):
|
|||||||
:param x: input value
|
:param x: input value
|
||||||
:return: membership value of x at this fuzzy set
|
:return: membership value of x at this fuzzy set
|
||||||
"""
|
"""
|
||||||
return self.mf(x, self.parameters) * self.alpha
|
return self.mf(self.transform(x), self.parameters) * self.alpha
|
||||||
|
|
||||||
def partition_function(self,uod=None, nbins=100):
|
def partition_function(self,uod=None, nbins=100):
|
||||||
"""
|
"""
|
||||||
@ -83,14 +93,14 @@ def __binary_search(x, fuzzy_sets, ordered_sets):
|
|||||||
fs1 = ordered_sets[midpoint - 1] if midpoint > 0 else ordered_sets[0]
|
fs1 = ordered_sets[midpoint - 1] if midpoint > 0 else ordered_sets[0]
|
||||||
fs2 = ordered_sets[midpoint + 1] if midpoint < max_len else ordered_sets[max_len]
|
fs2 = ordered_sets[midpoint + 1] if midpoint < max_len else ordered_sets[max_len]
|
||||||
|
|
||||||
if fuzzy_sets[fs1].centroid <= x <= fuzzy_sets[fs2].centroid:
|
if fuzzy_sets[fs1].centroid <= fuzzy_sets[fs].transform(x) <= fuzzy_sets[fs2].centroid:
|
||||||
return (midpoint-1, midpoint, midpoint+1)
|
return (midpoint-1, midpoint, midpoint+1)
|
||||||
elif midpoint <= 1:
|
elif midpoint <= 1:
|
||||||
return [0]
|
return [0]
|
||||||
elif midpoint >= max_len:
|
elif midpoint >= max_len:
|
||||||
return [max_len]
|
return [max_len]
|
||||||
else:
|
else:
|
||||||
if x < fuzzy_sets[fs].centroid:
|
if fuzzy_sets[fs].transform(x) < fuzzy_sets[fs].centroid:
|
||||||
last = midpoint - 1
|
last = midpoint - 1
|
||||||
else:
|
else:
|
||||||
first = midpoint + 1
|
first = midpoint + 1
|
||||||
|
@ -89,14 +89,15 @@ 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', 'datetime'),
|
type=kwargs.get('type', 'seasonal'),
|
||||||
**kwargs)
|
**kwargs)
|
||||||
self.datepart = datepart
|
self.datepart = datepart
|
||||||
self.type = 'seasonal'
|
self.type = 'seasonal'
|
||||||
|
|
||||||
def membership(self, x):
|
def transform(self, x):
|
||||||
if self.type == 'datetime':
|
if self.type == 'seasonal':
|
||||||
dp = strip_datepart(x, self.datepart)
|
dp = strip_datepart(x, self.datepart)
|
||||||
else:
|
else:
|
||||||
dp = x
|
dp = x
|
||||||
return self.mf(dp, self.parameters) * self.alpha
|
|
||||||
|
return dp
|
||||||
|
@ -8,8 +8,6 @@ from pyFTS.data import Malaysia
|
|||||||
|
|
||||||
dataset = Malaysia.get_dataframe()
|
dataset = Malaysia.get_dataframe()
|
||||||
|
|
||||||
print(dataset.head())
|
|
||||||
|
|
||||||
dataset["date"] = pd.to_datetime(dataset["time"], format='%m/%d/%y %I:%M %p')
|
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
|
||||||
@ -48,3 +46,28 @@ vload = variable.Variable("load", data_label="load", partitioner=Grid.GridPartit
|
|||||||
vtemperature = variable.Variable("temperature", data_label="temperature", partitioner=Grid.GridPartitioner, npart=10,
|
vtemperature = variable.Variable("temperature", data_label="temperature", partitioner=Grid.GridPartitioner, npart=10,
|
||||||
data=mv_train)
|
data=mv_train)
|
||||||
|
|
||||||
|
|
||||||
|
variables = {
|
||||||
|
'month': vmonth,
|
||||||
|
'day': vday,
|
||||||
|
'hour': vhour,
|
||||||
|
'temperature': vtemperature,
|
||||||
|
'load': vload
|
||||||
|
}
|
||||||
|
|
||||||
|
var_list = [k for k in variables.keys()]
|
||||||
|
|
||||||
|
models = []
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
for k in [itertools.combinations(var_list, r) for r in range(2,len(var_list))]:
|
||||||
|
for x in k:
|
||||||
|
model = mvfts.MVFTS()
|
||||||
|
print(x)
|
||||||
|
for w in x:
|
||||||
|
model.append_variable(variables[w])
|
||||||
|
model.shortname += ' ' + w
|
||||||
|
model.target_variable = vload
|
||||||
|
model.fit(mv_train)
|
||||||
|
models.append(model)
|
||||||
|
Loading…
Reference in New Issue
Block a user