2016-12-22 20:15:07 +04:00
|
|
|
import numpy as np
|
|
|
|
from pyFTS import *
|
2016-12-26 21:47:23 +04:00
|
|
|
from pyFTS.common import Membership
|
2016-12-22 20:15:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
class FuzzySet:
|
|
|
|
def __init__(self, name, mf, parameters, centroid):
|
|
|
|
self.name = name
|
|
|
|
self.mf = mf
|
|
|
|
self.parameters = parameters
|
|
|
|
self.centroid = centroid
|
2016-12-26 21:47:23 +04:00
|
|
|
if self.mf == Membership.trimf:
|
|
|
|
self.lower = min(parameters)
|
|
|
|
self.upper = max(parameters)
|
|
|
|
elif self.mf == Membership.gaussmf:
|
|
|
|
self.lower = parameters[0] - parameters[1]*3
|
|
|
|
self.upper = parameters[0] + parameters[1]*3
|
2016-12-22 20:15:07 +04:00
|
|
|
|
|
|
|
def membership(self, x):
|
|
|
|
return self.mf(x, self.parameters)
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-01-11 00:05:51 +04:00
|
|
|
return self.name + ": " + str(self.mf.__name__) + "(" + str(self.parameters) + ")"
|
2016-12-22 20:15:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
def fuzzyInstance(inst, fuzzySets):
|
|
|
|
mv = np.array([fs.membership(inst) for fs in fuzzySets])
|
|
|
|
return mv
|
|
|
|
|
|
|
|
|
2017-02-16 17:54:37 +04:00
|
|
|
def fuzzyInstances(data, fuzzySets):
|
|
|
|
ret = []
|
|
|
|
for inst in data:
|
|
|
|
mv = np.array([fs.membership(inst) for fs in fuzzySets])
|
|
|
|
ret.append(mv)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2016-12-22 20:15:07 +04:00
|
|
|
def getMaxMembershipFuzzySet(inst, fuzzySets):
|
|
|
|
mv = fuzzyInstance(inst, fuzzySets)
|
|
|
|
return fuzzySets[np.argwhere(mv == max(mv))[0, 0]]
|
|
|
|
|
2017-02-15 05:01:44 +04:00
|
|
|
def getMaxMembershipFuzzySetIndex(inst, fuzzySets):
|
|
|
|
mv = fuzzyInstance(inst, fuzzySets)
|
|
|
|
return np.argwhere(mv == max(mv))[0, 0]
|
|
|
|
|
2016-12-22 20:15:07 +04:00
|
|
|
|
|
|
|
def fuzzySeries(data, fuzzySets):
|
|
|
|
fts = []
|
|
|
|
for item in data:
|
|
|
|
fts.append(getMaxMembershipFuzzySet(item, fuzzySets))
|
2016-12-26 17:21:28 +04:00
|
|
|
return fts
|