pyFTS/partitioners/Grid.py
Petrônio Cândido de Lima e Silva 7f13a24402 Refactorings
2017-02-27 15:53:29 -03:00

31 lines
1.0 KiB
Python

import numpy as np
import math
import random as rnd
import functools, operator
from pyFTS.common import FuzzySet, Membership
from pyFTS.partitioners import partitioner
class GridPartitioner(partitioner.Partitioner):
def __init__(self, data,npart,func = Membership.trimf, transformation=None):
super(GridPartitioner, self).__init__("Grid", data, npart, func=func, transformation=transformation)
def build(self, data):
sets = []
dlen = self.max - self.min
partlen = dlen / self.partitions
count = 0
for c in np.arange(self.min, self.max, partlen):
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))
count += 1
return sets