- Non Stationary Fuzzy Sets - Refactoring
This commit is contained in:
parent
c38a3747f0
commit
80583cc202
@ -7,20 +7,21 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.
|
||||
|
||||
import numpy as np
|
||||
from pyFTS import *
|
||||
from pyFTS.common import FuzzySet, Membership
|
||||
from pyFTS.common import FuzzySet as FS, Membership
|
||||
from pyFTS.partitioners import partitioner
|
||||
from pyFTS.nonstationary import perturbation
|
||||
|
||||
|
||||
class MembershipFunction(object):
|
||||
class FuzzySet(FS.FuzzySet):
|
||||
"""
|
||||
Non Stationary Membership Function
|
||||
Non Stationary Fuzzy Sets
|
||||
"""
|
||||
|
||||
def __init__(self, name, mf, parameters, **kwargs):
|
||||
"""
|
||||
Non Stationary Membership Function
|
||||
Constructor
|
||||
:param name:
|
||||
:param mf:
|
||||
:param mf: Fuzzy Membership Function
|
||||
:param parameters:
|
||||
:param kwargs:
|
||||
- location: Pertubation function that affects the location of the membership function
|
||||
@ -30,8 +31,8 @@ class MembershipFunction(object):
|
||||
- noise: Pertubation function that adds noise on the membership function
|
||||
- noise_params: Parameters for noise pertubation function
|
||||
"""
|
||||
self.mf = mf
|
||||
self.parameters = parameters
|
||||
super(FuzzySet, self).__init__(name=name, mf=mf, parameters=parameters, centroid=None)
|
||||
|
||||
self.location = kwargs.get("location", None)
|
||||
self.location_params = kwargs.get("location_params", None)
|
||||
self.location_roots = kwargs.get("location_roots", 0)
|
||||
@ -120,18 +121,6 @@ class MembershipFunction(object):
|
||||
param = self.perform_width(t, param)
|
||||
self.perturbated_parameters[t] = param
|
||||
|
||||
def __str__(self):
|
||||
tmp = ""
|
||||
if self.location is not None:
|
||||
tmp += "Loc. Pert.: "
|
||||
for ct, f in enumerate(self.location):
|
||||
tmp += str(f.__name__) + "(" + str(self.location_params[ct]) + ") "
|
||||
if self.width is not None:
|
||||
tmp += "Wid. Pert.: "
|
||||
for ct, f in enumerate(self.width):
|
||||
tmp += str(f.__name__) + "(" + str(self.width_params[ct]) + ") "
|
||||
return str(self.mf.__name__) + "(" + str(self.parameters) + ") " + tmp
|
||||
|
||||
def get_midpoint(self, t):
|
||||
|
||||
self.perturbate_parameters(t)
|
||||
@ -180,26 +169,17 @@ class MembershipFunction(object):
|
||||
else:
|
||||
return param
|
||||
|
||||
|
||||
|
||||
class FuzzySet(FuzzySet.FuzzySet):
|
||||
"""
|
||||
Non Stationary Fuzzy Sets
|
||||
"""
|
||||
|
||||
def __init__(self, name, mf, **kwargs):
|
||||
"""
|
||||
Constructor
|
||||
:param name: Fuzzy Set name
|
||||
:param mf: NonStationary Membership Function
|
||||
"""
|
||||
super(FuzzySet, self).__init__(name=name, mf=mf, parameters=None, centroid=None)
|
||||
|
||||
def membership(self, x, t):
|
||||
return self.mf.membership(x,t)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + ": " + str(self.mf)
|
||||
tmp = ""
|
||||
if self.location is not None:
|
||||
tmp += "Loc. Pert.: "
|
||||
for ct, f in enumerate(self.location):
|
||||
tmp += str(f.__name__) + "(" + str(self.location_params[ct]) + ") "
|
||||
if self.width is not None:
|
||||
tmp += "Wid. Pert.: "
|
||||
for ct, f in enumerate(self.width):
|
||||
tmp += str(f.__name__) + "(" + str(self.width_params[ct]) + ") "
|
||||
return self.name + ": " + str(self.mf.__name__) + "(" + str(self.parameters) + ") " + tmp
|
||||
|
||||
|
||||
class PolynomialNonStationaryPartitioner(partitioner.Partitioner):
|
||||
@ -221,14 +201,13 @@ class PolynomialNonStationaryPartitioner(partitioner.Partitioner):
|
||||
for ct, set in enumerate(part.sets):
|
||||
loc_roots = np.roots(loc_params[ct])[0]
|
||||
wid_roots = np.roots(wid_params[ct])[0]
|
||||
mf = MembershipFunction(name=set.name, mf=set.mf, parameters=set.parameters,
|
||||
tmp = FuzzySet(set.name, set.mf, set.parameters,
|
||||
location=perturbation.polynomial,
|
||||
location_params=loc_params[ct],
|
||||
location_roots=loc_roots, #**kwargs)
|
||||
width=perturbation.polynomial,
|
||||
width_params=wid_params[ct],
|
||||
width_roots=wid_roots, **kwargs)
|
||||
tmp = FuzzySet(set.name, mf, **kwargs)
|
||||
|
||||
self.sets.append(tmp)
|
||||
|
||||
|
@ -12,9 +12,9 @@ def plot_sets(uod, sets, start=0, end=10, tam=[5, 5], colors=None, save=False, f
|
||||
for t in np.arange(start,end,1):
|
||||
for ct, set in enumerate(sets):
|
||||
set.membership(0, t)
|
||||
param = set.mf.perturbated_parameters[t]
|
||||
param = set.perturbated_parameters[t]
|
||||
|
||||
if set.mf.mf == Membership.trimf:
|
||||
if set.mf == Membership.trimf:
|
||||
axes.plot([t, t+1, t], param)
|
||||
|
||||
ticks.extend(["t+"+str(t),""])
|
||||
|
Loading…
Reference in New Issue
Block a user