- Non Stationary Fuzzy Sets

This commit is contained in:
Petrônio Cândido 2017-09-27 22:26:03 -03:00
parent b783f7bb15
commit 921dd5d146
2 changed files with 86 additions and 21 deletions

View File

@ -52,12 +52,23 @@ def gaussmf(x, parameters):
:return: the membership value of x given the parameters :return: the membership value of x given the parameters
""" """
return math.exp((-(x - parameters[0])**2)/(2 * parameters[1]**2)) return math.exp((-(x - parameters[0])**2)/(2 * parameters[1]**2))
#return math.exp(-0.5 * ((x - parameters[0]) / parameters[1]) ** 2)
def bellmf(x, parameters): def bellmf(x, parameters):
"""
Bell shaped membership function
:param x:
:param parameters:
:return:
"""
return 1 / (1 + abs((x - parameters[2]) / parameters[0]) ** (2 * parameters[1])) return 1 / (1 + abs((x - parameters[2]) / parameters[0]) ** (2 * parameters[1]))
def sigmf(x, parameters): def sigmf(x, parameters):
"""
Sigmoid / Logistic membership function
:param x:
:param parameters: an list with 2 real values (smoothness and midpoint)
:return:
"""
return 1 / (1 + math.exp(-parameters[0] * (x - parameters[1]))) return 1 / (1 + math.exp(-parameters[0] * (x - parameters[1])))

View File

@ -3,6 +3,76 @@ from pyFTS import *
from pyFTS.common import FuzzySet, Membership from pyFTS.common import FuzzySet, Membership
class NonStationaryMembershipFunction(object):
def __init__(self, name, mf, parameters, **kwargs):
self.mf = mf
self.parameters = parameters
self.location = kwargs.get("location", None)
self.location_params = kwargs.get("location_params", None)
self.width = kwargs.get("width", None)
self.width_params = kwargs.get("width_params", None)
self.noise = kwargs.get("noise", None)
self.noise_params = kwargs.get("noise_params", None)
def perform_location(self, t, param):
if self.location is None:
return param
inc = self.location(t, self.location_params)
if self.mf == Membership.gaussmf:
#changes only the mean parameter
return [param[0] + inc, param[1]]
elif self.mf == Membership.sigmf:
#changes only the midpoint parameter
return [param[0], param[1] + inc]
elif self.mf == Membership.bellmf:
return [param[0], param[1], param[2] + inc]
else:
#translate all parameters
return [k + inc for k in param]
def perform_width(self, t, param):
if self.width is None:
return param
inc = self.width(t, self.width_params)
if self.mf == Membership.gaussmf:
#changes only the variance parameter
return [param[0], param[1] + inc]
elif self.mf == Membership.sigmf:
#changes only the smooth parameter
return [param[0] + inc, param[1]]
elif self.mf == Membership.trimf:
return [param[0] + inc, param[1], param[2] - inc]
elif self.mf == Membership.trapmf:
l = (param[3]-param[0])
rab = (param[1] - param[0]) / l
rcd = (param[3] - param[2]) / l
return [param[0] + inc, param[1] + inc*rab, param[2] - inc*rcd, param[3] - inc]
else:
return param
def membership(self, x, t):
"""
Calculate the membership value of a given input
:param x: input value
:return: membership value of x at this fuzzy set
"""
param = self.parameters
param = self.perform_location(t, param)
param = self.perform_width(t, param)
tmp = self.mf(x, param)
if self.noise is not None:
tmp += self.noise(t, self.noise_params)
return tmp
class NonStationaryFuzzySet(FuzzySet.FuzzySet): class NonStationaryFuzzySet(FuzzySet.FuzzySet):
""" """
Non Stationary Fuzzy Sets Non Stationary Fuzzy Sets
@ -11,28 +81,12 @@ class NonStationaryFuzzySet(FuzzySet.FuzzySet):
IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008. IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.
""" """
def __init__(self, name, mf, parameters): def __init__(self, name, mf, **kwargs):
""" """
Constructor Constructor
:param name: Fuzzy Set name :param name: Fuzzy Set name
:param mf: Membership Function :param mf: NonStationary Membership Function
:param pf: Pertubation Function
:param parameters: initial parameters of the membership function
:param pf_parameters: parameters of the membership pertubation function
""" """
super(FuzzySet, self).__init__(order=1, name=name, **kwargs) super(FuzzySet, self).__init__(name=name, mf=mf, parameters=None, centroid=None)
self.name = name
self.mf = mf
self.parameters = parameters
self.pf = []
self.pf_parameters = []
def appendPertubation(self, pf, pf_parameters):
"""
Append a pertubation function to the non-stationary fuzzy set
:param pf:
:param pf_parameters:
:return:
"""
self.pf.append(pf)
self.pf_parameters.append(pf_parameters)