2017-02-24 20:29:55 +04:00
|
|
|
from pyFTS.common import FuzzySet, Membership
|
2017-05-02 18:32:03 +04:00
|
|
|
import numpy as np
|
2017-02-24 20:29:55 +04:00
|
|
|
|
2017-04-01 03:34:12 +04:00
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
class Partitioner(object):
|
2017-05-02 18:32:03 +04:00
|
|
|
"""
|
|
|
|
Universe of Discourse partitioner. Split data on several fuzzy sets
|
|
|
|
"""
|
|
|
|
|
2017-07-02 02:42:45 +04:00
|
|
|
def __init__(self, name, data, npart, func=Membership.trimf, names=None, prefix="A", transformation=None, indexer=None):
|
2017-05-02 18:32:03 +04:00
|
|
|
"""
|
|
|
|
Universe of Discourse partitioner scheme. Split data on several fuzzy sets
|
|
|
|
:param name: partitioner name
|
|
|
|
:param data: original data to be partitioned
|
|
|
|
:param npart: number of partitions
|
|
|
|
:param func: membership function
|
|
|
|
:param names: list of partitions names. If None is given the partitions will be auto named with prefix
|
|
|
|
:param prefix: prefix of auto generated partition names
|
|
|
|
:param transformation: data transformation to be applied on data
|
|
|
|
"""
|
2017-02-24 20:29:55 +04:00
|
|
|
self.name = name
|
|
|
|
self.partitions = npart
|
|
|
|
self.sets = []
|
|
|
|
self.membership_function = func
|
|
|
|
self.setnames = names
|
|
|
|
self.prefix = prefix
|
2017-02-27 22:53:29 +04:00
|
|
|
self.transformation = transformation
|
2017-07-02 02:42:45 +04:00
|
|
|
self.indexer = indexer
|
|
|
|
|
|
|
|
if self.indexer is not None:
|
|
|
|
ndata = self.indexer.get_data(data)
|
|
|
|
else:
|
|
|
|
ndata = data
|
2017-02-27 22:53:29 +04:00
|
|
|
|
|
|
|
if transformation is not None:
|
2017-07-02 02:42:45 +04:00
|
|
|
ndata = transformation.apply(ndata)
|
2017-02-27 22:53:29 +04:00
|
|
|
else:
|
|
|
|
ndata = data
|
|
|
|
|
|
|
|
_min = min(ndata)
|
2017-02-24 20:29:55 +04:00
|
|
|
if _min < 0:
|
|
|
|
self.min = _min * 1.1
|
|
|
|
else:
|
|
|
|
self.min = _min * 0.9
|
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
_max = max(ndata)
|
2017-02-24 20:29:55 +04:00
|
|
|
if _max > 0:
|
|
|
|
self.max = _max * 1.1
|
|
|
|
else:
|
|
|
|
self.max = _max * 0.9
|
2017-07-02 02:42:45 +04:00
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
self.sets = self.build(ndata)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
2017-07-02 02:42:45 +04:00
|
|
|
del(ndata)
|
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
def build(self, data):
|
2017-05-02 18:32:03 +04:00
|
|
|
"""
|
|
|
|
Perform the partitioning of the Universe of Discourse
|
|
|
|
:param data:
|
|
|
|
:return:
|
|
|
|
"""
|
2017-02-24 20:29:55 +04:00
|
|
|
pass
|
|
|
|
|
2017-05-02 18:32:03 +04:00
|
|
|
def plot(self, ax):
|
|
|
|
"""
|
|
|
|
Plot the
|
|
|
|
:param ax:
|
|
|
|
:return:
|
|
|
|
"""
|
2017-02-24 20:29:55 +04:00
|
|
|
ax.set_title(self.name)
|
|
|
|
ax.set_ylim([0, 1])
|
|
|
|
ax.set_xlim([self.min, self.max])
|
|
|
|
for s in self.sets:
|
|
|
|
if s.mf == Membership.trimf:
|
|
|
|
ax.plot([s.parameters[0], s.parameters[1], s.parameters[2]], [0, 1, 0])
|
|
|
|
elif s.mf == Membership.gaussmf:
|
|
|
|
tmpx = [kk for kk in np.arange(s.lower, s.upper)]
|
|
|
|
tmpy = [s.membership(kk) for kk in np.arange(s.lower, s.upper)]
|
2017-04-06 06:45:11 +04:00
|
|
|
ax.plot(tmpx, tmpy)
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-02 18:32:03 +04:00
|
|
|
return self.name
|