pyFTS/partitioners/Util.py

63 lines
2.0 KiB
Python
Raw Normal View History

import numpy as np
import pandas as pd
import matplotlib as plt
import matplotlib.colors as pltcolors
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from pyFTS.common import Membership, Util
from pyFTS.partitioners import Grid,Huarng,FCM,Entropy
2017-05-02 03:56:47 +04:00
all_methods = [Grid.GridPartitioner, Entropy.EntropyPartitioner, FCM.FCMPartitioner, Huarng.HuarngPartitioner]
mfs = [Membership.trimf, Membership.gaussmf, Membership.trapmf]
2016-12-27 00:25:59 +04:00
def plot_sets(data, sets, titles, tam=[12, 10], save=False, file=None):
num = len(sets)
2017-01-21 06:38:32 +04:00
#fig = plt.figure(figsize=tam)
maxx = max(data)
minx = min(data)
2017-01-21 06:38:32 +04:00
#h = 1/num
#print(h)
fig, axes = plt.subplots(nrows=num, ncols=1,figsize=tam)
for k in np.arange(0,num):
#ax = fig.add_axes([0.05, 1-(k*h), 0.9, h*0.7]) # left, bottom, width, height
ax = axes[k]
ax.set_title(titles[k])
2017-05-02 03:56:47 +04:00
ax.set_ylim([0, 1.1])
2017-01-21 06:38:32 +04:00
ax.set_xlim([minx, maxx])
for s in sets[k]:
if s.mf == Membership.trimf:
ax.plot(s.parameters,[0,1,0])
2016-12-26 18:46:29 +04:00
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-01-21 06:38:32 +04:00
ax.plot(tmpx, tmpy)
2017-05-02 03:56:47 +04:00
elif s.mf == Membership.trapmf:
ax.plot(s.parameters, [0, 1, 1, 0])
2017-01-21 06:38:32 +04:00
plt.tight_layout()
Util.showAndSaveImage(fig, file, save)
def plot_partitioners(data, objs, tam=[12, 10], save=False, file=None):
sets = [k.sets for k in objs]
titles = [k.name for k in objs]
plot_sets(data,sets,titles,tam,save,file)
def explore_partitioners(data, npart, methods=None, mf=None, tam=[12, 10], save=False, file=None):
if methods is None:
methods = all_methods
if mf is None:
mf = mfs
objs = []
for p in methods:
for m in mf:
obj = p(data, npart,m)
objs.append(obj)
2017-05-02 03:56:47 +04:00
plot_partitioners(data, objs, tam, save, file)