00001
00002 print "Algorithme de k-means"
00003 print "\t@version: 1.2 date: 26/06/2007 modified by Thomas Leaute"
00004 print "\t@version: 1.1 date: 25/05/2007 modified by Thomas Leaute"
00005 print "\t@version: 1.0 date: 05/03/2007 created by Thomas Leaute"
00006 print "\t@author: thomas.leaute _AT_ epfl.ch date: 09/05/2007"
00007 print "\t@copyright: EPFL-IC-IIF-LIA 2007"
00008
00009
00010
00011
00012
00013 import copy
00014 execfile("distance.py")
00015
00016
00017 VIEUXNOYAUX = []
00018
00019
00020 CLUSTERS = []
00021
00022
00023
00024 def afficheClusters (clusters):
00025 print "*********************"
00026 print "Clusters :"
00027 for cluster in clusters:
00028 if len(cluster) > 0:
00029 print "Donnees :", cluster[0]
00030 for donnee in cluster[1:]:
00031 print " ", donnee
00032 print "*********************"
00033
00034
00035
00036
00037 def formeClusters (noyaux):
00038 print "a completer"
00039
00040
00041
00042
00043
00044
00045
00046 def recentreNoyau (cluster):
00047 print "a completer"
00048
00049
00050
00051
00052 def afficheNoyaux (noyaux):
00053 if len(noyaux) > 0:
00054 print "Noyaux :", noyaux[0]
00055 for noyau in noyaux[1:]:
00056 print " ", noyau
00057
00058
00059
00060 def afficheResultat ():
00061 afficheClusters(CLUSTERS)
00062
00063
00064
00065
00066
00067
00068
00069 def chargeDonnees (k, listeNoyaux = None):
00070 global CLUSTERS
00071
00072 noyaux = listeNoyaux
00073 if noyaux == None:
00074
00075 noyaux = DONNEES[0:k]
00076 afficheNoyaux(noyaux)
00077
00078
00079 print "a completer"
00080
00081
00082
00083
00084 def retourneNoyaux ():
00085 print "a completer"
00086
00087
00088
00089
00090 def fini ():
00091 print "a completer"
00092
00093
00094
00095 def reviseClusters ():
00096 global VIEUXNOYAUX, CLUSTERS
00097
00098 noyaux = retourneNoyaux()
00099 VIEUXNOYAUX = copy.deepcopy(noyaux)
00100
00101
00102 CLUSTERS = formeClusters(noyaux)
00103
00104
00105 CLUSTERS = [recentreNoyau(cluster) for cluster in CLUSTERS]
00106
00107
00108
00109
00110
00111
00112 execfile("maladies.py")
00113
00114
00115
00116 chargeDonnees(4)
00117
00118
00119 execfile("clustering.py")