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
|
2016-12-21 20:54:39 +04:00
|
|
|
|
|
|
|
|
2016-12-26 17:21:28 +04:00
|
|
|
# print(common.__dict__)
|
|
|
|
|
|
|
|
def GridPartitionerTrimf(data, npart, names=None, prefix="A"):
|
2016-12-21 20:54:39 +04:00
|
|
|
sets = []
|
2017-01-30 03:59:50 +04:00
|
|
|
if min(data) < 0:
|
|
|
|
dmin = min(data) * 1.1
|
|
|
|
else:
|
|
|
|
dmin = min(data) * 0.9
|
|
|
|
|
|
|
|
if max(data) > 0:
|
|
|
|
dmax = max(data) * 1.1
|
|
|
|
else:
|
|
|
|
dmax = max(data) * 0.9
|
|
|
|
|
2016-12-21 20:54:39 +04:00
|
|
|
dlen = dmax - dmin
|
|
|
|
partlen = math.ceil(dlen / npart)
|
2017-01-30 03:59:50 +04:00
|
|
|
|
2017-01-11 00:05:51 +04:00
|
|
|
count = 0
|
|
|
|
for c in np.arange(dmin, dmax, partlen):
|
2016-12-26 17:21:28 +04:00
|
|
|
sets.append(
|
2017-01-11 00:05:51 +04:00
|
|
|
FuzzySet.FuzzySet(prefix + str(count), Membership.trimf, [c - partlen, c, c + partlen],c))
|
|
|
|
count += 1
|
2016-12-21 20:54:39 +04:00
|
|
|
|
|
|
|
return sets
|
2016-12-26 21:47:23 +04:00
|
|
|
|
|
|
|
|
|
|
|
def GridPartitionerGaussmf(data, npart, names=None, prefix="A"):
|
|
|
|
sets = []
|
|
|
|
dmax = max(data)
|
|
|
|
dmax += dmax * 0.10
|
|
|
|
dmin = min(data)
|
|
|
|
dmin -= dmin * 0.10
|
|
|
|
dlen = dmax - dmin
|
|
|
|
partlen = math.ceil(dlen / npart)
|
|
|
|
partition = math.ceil(dmin)
|
|
|
|
for c in range(npart):
|
|
|
|
sets.append(
|
|
|
|
FuzzySet.FuzzySet(prefix + str(c), Membership.gaussmf, [partition, partlen/3],
|
|
|
|
partition))
|
|
|
|
partition += partlen
|
|
|
|
|
|
|
|
return sets
|