Adding multivariate support on all partitioners
This commit is contained in:
parent
e91d44afd1
commit
d7d4efad60
@ -83,6 +83,9 @@ class CMeansPartitioner(partitioner.Partitioner):
|
|||||||
|
|
||||||
def build(self, data):
|
def build(self, data):
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
|
kwargs = {'type': self.type, 'variable': self.variable}
|
||||||
|
|
||||||
centroides = c_means(self.partitions, data, 1)
|
centroides = c_means(self.partitions, data, 1)
|
||||||
centroides.append(self.max)
|
centroides.append(self.max)
|
||||||
centroides.append(self.min)
|
centroides.append(self.min)
|
||||||
@ -92,6 +95,6 @@ class CMeansPartitioner(partitioner.Partitioner):
|
|||||||
_name = self.get_name(c)
|
_name = self.get_name(c)
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
||||||
[round(centroides[c - 1], 3), round(centroides[c], 3), round(centroides[c + 1], 3)],
|
[round(centroides[c - 1], 3), round(centroides[c], 3), round(centroides[c + 1], 3)],
|
||||||
round(centroides[c], 3))
|
round(centroides[c], 3), **kwargs)
|
||||||
|
|
||||||
return sets
|
return sets
|
||||||
|
@ -87,6 +87,8 @@ class EntropyPartitioner(partitioner.Partitioner):
|
|||||||
def build(self, data):
|
def build(self, data):
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
|
kwargs = {'type': self.type, 'variable': self.variable}
|
||||||
|
|
||||||
partitions = bestSplit(data, self.partitions)
|
partitions = bestSplit(data, self.partitions)
|
||||||
partitions.append(self.min)
|
partitions.append(self.min)
|
||||||
partitions.append(self.max)
|
partitions.append(self.max)
|
||||||
@ -96,13 +98,13 @@ class EntropyPartitioner(partitioner.Partitioner):
|
|||||||
_name = self.get_name(c)
|
_name = self.get_name(c)
|
||||||
if self.membership_function == Membership.trimf:
|
if self.membership_function == Membership.trimf:
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
||||||
[partitions[c - 1], partitions[c], partitions[c + 1]],partitions[c])
|
[partitions[c - 1], partitions[c], partitions[c + 1]],partitions[c], **kwargs)
|
||||||
elif self.membership_function == Membership.trapmf:
|
elif self.membership_function == Membership.trapmf:
|
||||||
b1 = (partitions[c] - partitions[c - 1])/2
|
b1 = (partitions[c] - partitions[c - 1])/2
|
||||||
b2 = (partitions[c + 1] - partitions[c]) / 2
|
b2 = (partitions[c + 1] - partitions[c]) / 2
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf,
|
||||||
[partitions[c - 1], partitions[c] - b1,
|
[partitions[c - 1], partitions[c] - b1,
|
||||||
partitions[c] + b2, partitions[c + 1]],
|
partitions[c] + b2, partitions[c + 1]],
|
||||||
partitions[c])
|
partitions[c], **kwargs)
|
||||||
|
|
||||||
return sets
|
return sets
|
||||||
|
@ -113,6 +113,8 @@ class FCMPartitioner(partitioner.Partitioner):
|
|||||||
def build(self, data):
|
def build(self, data):
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
|
kwargs = {'type': self.type, 'variable': self.variable}
|
||||||
|
|
||||||
centroids = fuzzy_cmeans(self.partitions, data, 1, 2)
|
centroids = fuzzy_cmeans(self.partitions, data, 1, 2)
|
||||||
centroids.append(self.max)
|
centroids.append(self.max)
|
||||||
centroids.append(self.min)
|
centroids.append(self.min)
|
||||||
@ -124,13 +126,13 @@ class FCMPartitioner(partitioner.Partitioner):
|
|||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
||||||
[round(centroids[c - 1], 3), round(centroids[c], 3),
|
[round(centroids[c - 1], 3), round(centroids[c], 3),
|
||||||
round(centroids[c + 1], 3)],
|
round(centroids[c + 1], 3)],
|
||||||
round(centroids[c], 3))
|
round(centroids[c], 3), **kwargs)
|
||||||
elif self.membership_function == Membership.trapmf:
|
elif self.membership_function == Membership.trapmf:
|
||||||
q1 = (round(centroids[c], 3) - round(centroids[c - 1], 3)) / 2
|
q1 = (round(centroids[c], 3) - round(centroids[c - 1], 3)) / 2
|
||||||
q2 = (round(centroids[c + 1], 3) - round(centroids[c], 3)) / 2
|
q2 = (round(centroids[c + 1], 3) - round(centroids[c], 3)) / 2
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
||||||
[round(centroids[c - 1], 3), round(centroids[c], 3) - q1,
|
[round(centroids[c - 1], 3), round(centroids[c], 3) - q1,
|
||||||
round(centroids[c], 3) + q2, round(centroids[c + 1], 3)],
|
round(centroids[c], 3) + q2, round(centroids[c + 1], 3)],
|
||||||
round(centroids[c], 3))
|
round(centroids[c], 3), **kwargs)
|
||||||
|
|
||||||
return sets
|
return sets
|
||||||
|
@ -32,6 +32,8 @@ class HuarngPartitioner(partitioner.Partitioner):
|
|||||||
|
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
|
kwargs = {'type': self.type, 'variable': self.variable}
|
||||||
|
|
||||||
dlen = self.max - self.min
|
dlen = self.max - self.min
|
||||||
npart = math.ceil(dlen / base)
|
npart = math.ceil(dlen / base)
|
||||||
partition = math.ceil(self.min)
|
partition = math.ceil(self.min)
|
||||||
@ -39,14 +41,14 @@ class HuarngPartitioner(partitioner.Partitioner):
|
|||||||
_name = self.get_name(c)
|
_name = self.get_name(c)
|
||||||
if self.membership_function == Membership.trimf:
|
if self.membership_function == Membership.trimf:
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
|
||||||
[partition - base, partition, partition + base], partition)
|
[partition - base, partition, partition + base], partition, **kwargs)
|
||||||
elif self.membership_function == Membership.gaussmf:
|
elif self.membership_function == Membership.gaussmf:
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.gaussmf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.gaussmf,
|
||||||
[partition, base/2], partition)
|
[partition, base/2], partition)
|
||||||
elif self.membership_function == Membership.trapmf:
|
elif self.membership_function == Membership.trapmf:
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf,
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf,
|
||||||
[partition - base, partition - (base/2),
|
[partition - base, partition - (base/2),
|
||||||
partition + (base / 2), partition + base], partition)
|
partition + (base / 2), partition + base], partition, **kwargs)
|
||||||
|
|
||||||
partition += base
|
partition += base
|
||||||
|
|
||||||
|
@ -20,10 +20,10 @@ class SingletonPartitioner(partitioner.Partitioner):
|
|||||||
def build(self, data):
|
def build(self, data):
|
||||||
sets = {}
|
sets = {}
|
||||||
|
|
||||||
for count, instance in enumerate(data):
|
|
||||||
_name = self.get_name(count)
|
|
||||||
sets[_name] = FuzzySet.FuzzySet(_name, Membership.singleton, [instance], instance)
|
|
||||||
|
|
||||||
kwargs = {'type': self.type, 'variable': self.variable}
|
kwargs = {'type': self.type, 'variable': self.variable}
|
||||||
|
|
||||||
|
for count, instance in enumerate(data):
|
||||||
|
_name = self.get_name(count)
|
||||||
|
sets[_name] = FuzzySet.FuzzySet(_name, Membership.singleton, [instance], instance, **kwargs)
|
||||||
|
|
||||||
return sets
|
return sets
|
||||||
|
@ -72,7 +72,7 @@ print(_s2-_s1)
|
|||||||
Util.persist_obj(model, 'sonda_wmvfts')
|
Util.persist_obj(model, 'sonda_wmvfts')
|
||||||
'''
|
'''
|
||||||
|
|
||||||
model = Util.load_obj('sonda_wmvfts')
|
#model = Util.load_obj('sonda_wmvfts')
|
||||||
|
|
||||||
'''
|
'''
|
||||||
from pyFTS.benchmarks import Measures
|
from pyFTS.benchmarks import Measures
|
||||||
@ -84,13 +84,13 @@ _s2 = time.time()
|
|||||||
print(_s2-_s1)
|
print(_s2-_s1)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
print(len(model))
|
#print(len(model))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
#model.fit(data, distributed='dispy', nodes=['192.168.0.110'])
|
#model.fit(data, distributed='dispy', nodes=['192.168.0.110'])
|
||||||
'''
|
#'''
|
||||||
|
|
||||||
from pyFTS.models.multivariate import common, variable, mvfts, wmvfts, cmvfts, grid
|
from pyFTS.models.multivariate import common, variable, mvfts, wmvfts, cmvfts, grid
|
||||||
from pyFTS.models.seasonal import partitioner as seasonal
|
from pyFTS.models.seasonal import partitioner as seasonal
|
||||||
@ -105,6 +105,11 @@ test_mv = dataset.iloc[24505:]
|
|||||||
|
|
||||||
sp = {'seasonality': DateTime.minute_of_day, 'names': [str(k)+'hs' for k in range(0,24)]}
|
sp = {'seasonality': DateTime.minute_of_day, 'names': [str(k)+'hs' for k in range(0,24)]}
|
||||||
|
|
||||||
|
sp = {'seasonality': DateTime.day_of_week, 'names': ['mon','tue','wed','tur','fri','sat','sun']}
|
||||||
|
|
||||||
|
vday = variable.Variable("DayOfWeek", data_label="date", partitioner=seasonal.TimeGridPartitioner, npart=7,
|
||||||
|
data=train_mv, partitioner_specific=sp)
|
||||||
|
|
||||||
vhour = variable.Variable("Hour", data_label="date", partitioner=seasonal.TimeGridPartitioner, npart=24,
|
vhour = variable.Variable("Hour", data_label="date", partitioner=seasonal.TimeGridPartitioner, npart=24,
|
||||||
data=train_mv, partitioner_specific=sp, data_type=pd.datetime, mask='%Y-%m-%d %H:%M:%S')
|
data=train_mv, partitioner_specific=sp, data_type=pd.datetime, mask='%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user