2016-12-21 20:54:39 +04:00
|
|
|
import numpy as np
|
|
|
|
import math
|
|
|
|
import random as rnd
|
2016-12-26 17:21:28 +04:00
|
|
|
import functools, operator
|
|
|
|
from pyFTS.common import FuzzySet, Membership
|
2017-02-24 20:29:55 +04:00
|
|
|
from pyFTS.partitioners import partitioner
|
|
|
|
|
|
|
|
|
|
|
|
class GridPartitioner(partitioner.Partitioner):
|
2017-03-03 15:53:55 +04:00
|
|
|
def __init__(self, data, npart, func = Membership.trimf, transformation=None):
|
2017-02-27 22:53:29 +04:00
|
|
|
super(GridPartitioner, self).__init__("Grid", data, npart, func=func, transformation=transformation)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
|
|
|
def build(self, data):
|
|
|
|
sets = []
|
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
dlen = self.max - self.min
|
2017-02-24 20:29:55 +04:00
|
|
|
partlen = dlen / self.partitions
|
|
|
|
|
|
|
|
count = 0
|
2017-02-27 22:53:29 +04:00
|
|
|
for c in np.arange(self.min, self.max, partlen):
|
2017-02-24 20:29:55 +04:00
|
|
|
if self.membership_function == Membership.trimf:
|
|
|
|
sets.append(
|
|
|
|
FuzzySet.FuzzySet(self.prefix + str(count), Membership.trimf, [c - partlen, c, c + partlen],c))
|
|
|
|
elif self.membership_function == Membership.gaussmf:
|
|
|
|
sets.append(
|
|
|
|
FuzzySet.FuzzySet(self.prefix + str(count), Membership.gaussmf, [c, partlen / 3], c))
|
2017-04-01 03:34:12 +04:00
|
|
|
elif self.membership_function == Membership.trapmf:
|
|
|
|
q = partlen / 2
|
|
|
|
sets.append(
|
|
|
|
FuzzySet.FuzzySet(self.prefix + str(count), Membership.trapmf, [c - partlen, c - q, c + q, c + partlen], c))
|
2017-02-24 20:29:55 +04:00
|
|
|
count += 1
|
|
|
|
|
|
|
|
|
|
|
|
return sets
|