From 756d0d2c1c68be7abc11fa48a0642e61dfcfcc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Mon, 26 Dec 2016 12:06:54 -0200 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20de=20bugs;=20Fun=C3=A7?= =?UTF-8?q?=C3=A3o=20para=20visualiza=C3=A7=C3=A3o=20do=20particionamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- partitioners/CMeans.py | 2 +- partitioners/FCM.py | 2 +- partitioners/Util.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 partitioners/Util.py diff --git a/partitioners/CMeans.py b/partitioners/CMeans.py index b451bd1..baf15fa 100644 --- a/partitioners/CMeans.py +++ b/partitioners/CMeans.py @@ -15,7 +15,7 @@ def distancia(x, y): def c_means(k, dados, tam): # Inicializa as centróides escolhendo elementos aleatórios dos conjuntos - centroides = [dados[rnd.randint(0, len(dados))] for kk in range(0, k)] + centroides = [dados[rnd.randint(0, len(dados)-1)] for kk in range(0, k)] grupos = [-1 for x in range(0, len(dados))] diff --git a/partitioners/FCM.py b/partitioners/FCM.py index fa6aede..153150d 100644 --- a/partitioners/FCM.py +++ b/partitioners/FCM.py @@ -29,7 +29,7 @@ def fuzzy_cmeans(k, dados, tam, m, deltadist=0.001): tam_dados = len(dados) # Inicializa as centróides escolhendo elementos aleatórios dos conjuntos - centroides = [dados[rnd.randint(0, tam_dados)] for kk in range(0, k)] + centroides = [dados[rnd.randint(0, tam_dados-1)] for kk in range(0, k)] # Tabela de pertinência das instâncias aos grupos grupos = [[0 for kk in range(0, k)] for xx in range(0, tam_dados)] diff --git a/partitioners/Util.py b/partitioners/Util.py new file mode 100644 index 0000000..a9d5a45 --- /dev/null +++ b/partitioners/Util.py @@ -0,0 +1,21 @@ +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 + +def plotSets(data, sets,num): + fig = plt.figure(figsize=[20, 10]) + maxx = max(data) + minx = min(data) + h = 1/num + for k in range(num): + ax0 = fig.add_axes([0, (k+1)*h, 0.65, h]) # left, bottom, width, height + ax0.set_ylim([0, 1]) + ax0.set_xlim([minx, maxx]) + for s in sets[k]: + if s.mf == Membership.trimf: + ax0.plot([s.parameters[0],s.parameters[1],s.parameters[2]],[0,1,0])