diff --git a/pyFTS/partitioners/CMeans.py b/pyFTS/partitioners/CMeans.py index 7651e3d..df67219 100644 --- a/pyFTS/partitioners/CMeans.py +++ b/pyFTS/partitioners/CMeans.py @@ -83,6 +83,9 @@ class CMeansPartitioner(partitioner.Partitioner): def build(self, data): sets = {} + + kwargs = {'type': self.type, 'variable': self.variable} + centroides = c_means(self.partitions, data, 1) centroides.append(self.max) centroides.append(self.min) @@ -92,6 +95,6 @@ class CMeansPartitioner(partitioner.Partitioner): _name = self.get_name(c) sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf, [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 diff --git a/pyFTS/partitioners/Entropy.py b/pyFTS/partitioners/Entropy.py index 0bf8e1e..969463c 100644 --- a/pyFTS/partitioners/Entropy.py +++ b/pyFTS/partitioners/Entropy.py @@ -87,6 +87,8 @@ class EntropyPartitioner(partitioner.Partitioner): def build(self, data): sets = {} + kwargs = {'type': self.type, 'variable': self.variable} + partitions = bestSplit(data, self.partitions) partitions.append(self.min) partitions.append(self.max) @@ -96,13 +98,13 @@ class EntropyPartitioner(partitioner.Partitioner): _name = self.get_name(c) if self.membership_function == 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: b1 = (partitions[c] - partitions[c - 1])/2 b2 = (partitions[c + 1] - partitions[c]) / 2 sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf, [partitions[c - 1], partitions[c] - b1, partitions[c] + b2, partitions[c + 1]], - partitions[c]) + partitions[c], **kwargs) return sets diff --git a/pyFTS/partitioners/FCM.py b/pyFTS/partitioners/FCM.py index 2125952..8e91b0d 100644 --- a/pyFTS/partitioners/FCM.py +++ b/pyFTS/partitioners/FCM.py @@ -113,6 +113,8 @@ class FCMPartitioner(partitioner.Partitioner): def build(self, data): sets = {} + kwargs = {'type': self.type, 'variable': self.variable} + centroids = fuzzy_cmeans(self.partitions, data, 1, 2) centroids.append(self.max) centroids.append(self.min) @@ -124,13 +126,13 @@ class FCMPartitioner(partitioner.Partitioner): 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], 3), **kwargs) elif self.membership_function == Membership.trapmf: q1 = (round(centroids[c], 3) - round(centroids[c - 1], 3)) / 2 q2 = (round(centroids[c + 1], 3) - round(centroids[c], 3)) / 2 sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf, [round(centroids[c - 1], 3), round(centroids[c], 3) - q1, round(centroids[c], 3) + q2, round(centroids[c + 1], 3)], - round(centroids[c], 3)) + round(centroids[c], 3), **kwargs) return sets diff --git a/pyFTS/partitioners/Huarng.py b/pyFTS/partitioners/Huarng.py index ff83a28..d322a7e 100644 --- a/pyFTS/partitioners/Huarng.py +++ b/pyFTS/partitioners/Huarng.py @@ -32,6 +32,8 @@ class HuarngPartitioner(partitioner.Partitioner): sets = {} + kwargs = {'type': self.type, 'variable': self.variable} + dlen = self.max - self.min npart = math.ceil(dlen / base) partition = math.ceil(self.min) @@ -39,14 +41,14 @@ class HuarngPartitioner(partitioner.Partitioner): _name = self.get_name(c) if self.membership_function == 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: sets[_name] = FuzzySet.FuzzySet(_name, Membership.gaussmf, [partition, base/2], partition) elif self.membership_function == Membership.trapmf: sets[_name] = FuzzySet.FuzzySet(_name, Membership.trapmf, [partition - base, partition - (base/2), - partition + (base / 2), partition + base], partition) + partition + (base / 2), partition + base], partition, **kwargs) partition += base diff --git a/pyFTS/partitioners/Singleton.py b/pyFTS/partitioners/Singleton.py index 92d64e5..65cb981 100644 --- a/pyFTS/partitioners/Singleton.py +++ b/pyFTS/partitioners/Singleton.py @@ -20,10 +20,10 @@ class SingletonPartitioner(partitioner.Partitioner): def build(self, data): 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} + for count, instance in enumerate(data): + _name = self.get_name(count) + sets[_name] = FuzzySet.FuzzySet(_name, Membership.singleton, [instance], instance, **kwargs) + return sets diff --git a/pyFTS/tests/multivariate.py b/pyFTS/tests/multivariate.py index 58dbe54..c2ddc0b 100644 --- a/pyFTS/tests/multivariate.py +++ b/pyFTS/tests/multivariate.py @@ -72,7 +72,7 @@ print(_s2-_s1) Util.persist_obj(model, 'sonda_wmvfts') ''' -model = Util.load_obj('sonda_wmvfts') +#model = Util.load_obj('sonda_wmvfts') ''' from pyFTS.benchmarks import Measures @@ -84,13 +84,13 @@ _s2 = time.time() print(_s2-_s1) ''' -print(len(model)) +#print(len(model)) # #model.fit(data, distributed='dispy', nodes=['192.168.0.110']) -''' +#''' from pyFTS.models.multivariate import common, variable, mvfts, wmvfts, cmvfts, grid 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.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, data=train_mv, partitioner_specific=sp, data_type=pd.datetime, mask='%Y-%m-%d %H:%M:%S')