X_phone = np.array([[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0], [0, 0, 0, 1],
                    [0, 1, 0, 0]])
X1, Y1 = getPhonesLabels(X, X_phone, phones=[1, 1, 1, 0])
if (X1 == np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [13, 14, 15]
                    ])).all() and (Y1 == np.array([1, 2, 0, 1])).all():
    print 'getPhonesLabels Test 2 OK'
else:
    print 'getPhonesLabels Test 2 pas OK'

####### test getData_goodmaps #######
mapconv1J_file = '../../maps/PHONIM_l_conv1_35maps_th0.001000.pkl'
mapconv1F_file = '../../maps/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv2J_file = "../../maps/PHONIM_l_conv2_35maps_th0.001000.pkl"
mapconv2F_file = '../../maps/BREF80_l_conv2_35maps_th0.500000.pkl'
#Load data
conv1J = load_maps(mapconv1J_file)
conv1F = load_maps(mapconv1F_file)
conv2J = load_maps(mapconv2J_file)
conv2F = load_maps(mapconv2F_file)

#test case 1
ph = ['R']
dics = [conv1J, conv1F]
ind_goodmaps = []
X, Y_c_inc, Y_r_v, Y_fr_jap = getData_goodmaps(dics, conv2J.keys(), ph,
                                               ind_goodmaps)
if not X:
    print("Test Successes")
else:
    print("Test Fails")
예제 #2
0
def Maps5Clustering(couche = 'conv1', seuilCartesVides = 559, fichier = True):
    """
    tous les clusterings pour la couche demandee
    :param couche: la couche de convolution ou de reseau de neurones sur laquelle on effectue les cluterings
    :param seuilCartesVides: seuil a partir duquel on considere que la carte est vide pour suffisamment d'exemples et ne doit pas etre prise en compte
    :param algorithme: algorithme de clustering qu'on souhaite utiliser : kmeansNonInit kmeansInit AgglomerativeClustering MeanShift DBSCAN hierarchique
    :param fichier: si on souhaite enregistrer les resultats sous des fichiers
    :return: les fichiers des differents pourcentages, ainsi que la matrice des indices de cartes qui nous donnent deux classes
    """


    ################################################################################
    #Chargement des cartes d'activation et definintion des fichiers d'enregistrement
    ################################################################################

    #chargement des dictionnaires
    map_file_FR = "../maps2/BREF80_l_conv1_35maps_th0.500000.pkl"
    map_file_JA = "../maps2/PHONIM_l_conv1_35maps_th0.001000.pkl"
    FR= load_maps(map_file_FR)
    JA = load_maps(map_file_JA)

    #recuperation des dimensions pour un dictionnaire
    tableau = np.array(FR['correct_OK']['R'])
    taille=tableau.shape
    listeVide = []


    #creation des fichiers d'enregistrement
    if fichier == True:
        fichier1 = "../resultats/resultats5phonemes/pourcentagesFRJA_R.csv"
        fichier1bis = "../resultats/resultats5phonemes/pourcentagesFRJA_V.csv"
        fichier2 = "../resultats/resultats5phonemes/pourcentagesRV.csv"
        fichier3 = "../resultats/resultats5phonemes/pourcentagesCIC_R.csv"
        fichier3bis = "../resultats/resultats5phonemes/pourcentagesCIC_V.csv"
        fichier6 = "../resultats/resultats5phonemes/pourcentagesFR_Rlvb_cl0.csv"
        fichier7 = "../resultats/resultats5phonemes/pourcentagesFR_Rlvb_cl1.csv"
        fichier8 = "../resultats/resultats5phonemes/pourcentagesFR_Rlvb_cl2.csv"
        fichier9 = "../resultats/resultats5phonemes/pourcentagesFR_Rlvb_cl3.csv"


    else:
        fichier1 = None
        fichier1bis = None
        fichier2 = None
        fichier3 = None
        fichier3bis = None
        fichier6 = None
        fichier7 =None
        fichier8=None
        fichier9=None

    #creation des matrices ratio
    pourcentagesFRJA_R = []
    pourcentagesFRJA_V = []
    pourcentagesRV = []
    pourcentagesCIC_R = []
    pourcentagesCIC_V = []
    pourcentagesFR_Rlvb0 = []
    pourcentagesFR_Rlvb1 = []
    pourcentagesFR_Rlvb2 = []
    pourcentagesFR_Rlvb3 = []

    #Colonne indices que l'on va inserer a chaque fois dans matIndicesCartes
    indices=[]
    #Matrice indices de cartes qui donnent 2 classes, 5 colonnes pour chaque clustering
    matIndicesCartes = []


    ################################################################################
    #Clustering 1
    ################################################################################
    clus = KMeans(n_clusters=2, init='k-means++')
    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR, JA],FR.keys(),['R'])
    #calcul des ratios de classement
    for i in range (taille[1]):
            if not(i in listeVide):
                resCluster = clus.fit(Mat[i])
                Y_Cluster = resCluster.labels_
                if (max(Y_Cluster) +1) ==2:
                    indices.append(i)
                    FRJA = ratios(Y_Cluster, Reference[:,0])
                    pourcentagesFRJA_R.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier1, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "JA-R"])
        np.savetxt(f,np.atleast_2d(pourcentagesFRJA_R), delimiter =',')


    ################################################################################
    #Clustering 1bis
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering
    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR, JA],FR.keys(),['v'])
    indices=[]
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,0])
                pourcentagesFRJA_V.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier1bis, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-V", "JA-V"])
        np.savetxt(f,np.atleast_2d(pourcentagesFRJA_V), delimiter =',')



    ################################################################################
    #Clustering 2
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR],FR.keys(),['R', 'v'])
    indices=[]
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,2])
                pourcentagesRV.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier2, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-V"])
        np.savetxt(f, np.atleast_2d(pourcentagesRV), delimiter =',')


    ################################################################################
    #Clustering 3
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([JA],JA.keys(),['R'])
    indices=[]
    #rassemblement des correct_OK et correct_PasOK et des incorrect_OK et incorrect_PasOK en correct et incorrect
    for i in range(len(Reference[:,1])):
        if Reference[i,1] == 1:
            Reference[i,1] = 0
        if Reference[i,1] == 2:
            Reference[i,1] = 1
        if Reference[i,1] == 3:
            Reference[i,1] = 1
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,1])
                pourcentagesCIC_R.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier3, "wb")
        writer = csv.writer(f)
        writer.writerow(["JA-CORR-R", "JA-INC-R"])
        np.savetxt(f, np.atleast_2d(pourcentagesCIC_R), delimiter =',')


    ################################################################################
    #Clustering 3bis
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([JA],JA.keys(),['v'])
    indices=[]
    for i in range(len(Reference[:,1])):
        if Reference[i,1] == 1:
            Reference[i,1] = 0
        if Reference[i,1] == 2:
            Reference[i,1] = 1
        if Reference[i,1] == 3:
            Reference[i,1] = 1
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,1])
                pourcentagesCIC_V.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier3bis, "wb")
        writer = csv.writer(f)
        writer.writerow(["JA-CORR-V", "JA-INC-V"])
        np.savetxt(f, np.atleast_2d(pourcentagesCIC_V), delimiter =',')

    # ################################################################################
    # #Clustering 6
    # ################################################################################
    clus = KMeans(n_clusters=4, init='k-means++')
    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR],FR.keys(),['R','l','v','b'])
    indices = []
    #calcul des ratios de classement
    for i in range (taille[1]):
            if not(i in listeVide):
                resCluster = clus.fit(Mat[i])
                Y_Cluster = resCluster.labels_
                if (max(Y_Cluster) +1) ==4:
                    indices.append(i)
                    FRJA = ratios(Y_Cluster, Reference[:,2],nb_classes=4)
                    pourcentagesFR_Rlvb0.append(FRJA[0])
                    pourcentagesFR_Rlvb1.append(FRJA[1])
                    pourcentagesFR_Rlvb2.append(FRJA[2])
                    pourcentagesFR_Rlvb3.append(FRJA[3])

    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier6, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-l", "FR-v", "FR-b"])
        np.savetxt(f,np.atleast_2d(pourcentagesFR_Rlvb0), delimiter =',')

        f = open(fichier7, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-l", "FR-v", "FR-b"])
        np.savetxt(f,np.atleast_2d(pourcentagesFR_Rlvb1), delimiter =',')

        f = open(fichier8, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-l", "FR-v", "FR-b"])
        np.savetxt(f,np.atleast_2d(pourcentagesFR_Rlvb2), delimiter =',')

        f = open(fichier9, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-l", "FR-v", "FR-b"])
        np.savetxt(f,np.atleast_2d(pourcentagesFR_Rlvb3), delimiter =',')

    matIndicesCartes=np.array(matIndicesCartes)
    return pourcentagesFRJA_R, pourcentagesFRJA_V, pourcentagesRV, pourcentagesCIC_R, pourcentagesCIC_V, pourcentagesFR_Rlvb0,pourcentagesFR_Rlvb1,pourcentagesFR_Rlvb2, pourcentagesFR_Rlvb3, matIndicesCartes
예제 #3
0
if (bon == [10, 30]):
    print "test 6 : test de la matrice indice : OK"
else:
    print "test 6 : test de la matrice indice : KO"


########################################################################################################################
######################################## TEST INITIALISATION CENTRES ###################################################
########################################################################################################################

#test 1 : test du format de sortie
print "\n###################################\n"
print "tests initialisation_centres\n"
print "###################################\n"
map_file_FR = '../../maps/BREF80_l_conv1_35maps_th0.500000.pkl'
FR= load_maps(map_file_FR)

type_clustering = 'R_v'
Mat, Reference = pretraitementMatrice([FR],FR.keys(),['R','v'])

centres = initialisation_centres (type_clustering, Mat, Reference)

if (centres.shape==(2,Mat.shape[2])):
    print ('Test 1 initialisation_centres ok : La matrice de sortie a la bonne forme')
else:
    print ('Test 1 initialisation_centres pas ok !! La matrice de sortie n a pas la bonne forme')

#test 2 et 3: existence du centre dans la matrice de depart
ind_centre0 = [index for index,row in enumerate(Mat[0,:,:]) if (row==centres[0,:]).all() ]
if(ind_centre0!=[] and (Mat[0,ind_centre0[0],:]==centres[0,:]).all()):
    print('Test 2 initialisation_centres ok : Le centre 0 appartient bien a la matrice de depart')
예제 #4
0
# Fait pour toutes les combinaisons de dictionnaires, toutes les combinaisons de phonemes, pour tous les types de classifications,

#Files
mapconv1J_file='../maps/PHONIM_l_conv1_35maps_th0.001000.pkl'
mapconv2J_file='../maps/PHONIM_l_conv2_35maps_th0.001000.pkl'
mapmp2J_file='../maps/PHONIM_l_mp2_35maps_th0.001000.pkl'
denseJ_file = '../maps/PHONIM_l_dense1_35maps_th0.001000.pkl'
mapconv1F_file='../maps/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv2F_file='../maps/BREF80_l_conv2_35maps_th0.500000.pkl'
mapmp2F_file='../maps/BREF80_l_mp2_35maps_th0.500000.pkl'
denseF_file = '../maps/BREF80_l_dense1_35maps_th0.500000.pkl'
mapconv1F_file_newFbank = '../maps2/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv1J_file_newFbank = '../maps2/PHONIM_l_conv1_35maps_th0.001000.pkl'

#Load data
conv1J = load_maps(mapconv1J_file)
conv2J = load_maps(mapconv2J_file)
mpJ = load_maps(mapmp2J_file)
#denseJ = load_maps(denseJ_file)
conv1F = load_maps(mapconv1F_file)
conv2F = load_maps(mapconv2F_file)
mpF = load_maps(mapmp2F_file)
# denseF = load_maps(denseF_file)
#conv1F_newFbank = load_maps(mapconv1F_file_newFbank)
#conv1J_newFbank = load_maps(mapconv1J_file_newFbank)

# liste des ensembles de dictionnaires que l'on veut prendre en donnees d'entree
#liste_dics = [[mpF],[mpJ],[mpF,mpJ]]
#dics_labels = ['mp2F','mp2J','mp2F_mp2J']
#liste_dics = [[conv1F],[conv1J],[conv1F,conv1J]]
#dics_labels = ['conv1F','conv1J','conv1F_conv1J']
예제 #5
0
def MapsClustering(couche = 'conv1', seuilCartesVides = 559, algorithme = 'kmeansNonInit', fichier = True):
    """
    tous les clusterings pour la couche demandee
    :param couche: la couche de convolution ou de reseau de neurones sur laquelle on effectue les cluterings
    :param seuilCartesVides: seuil a partir duquel on considere que la carte est vide pour suffisamment d'exemples et ne doit pas etre prise en compte
    :param algorithme: algorithme de clustering qu'on souhaite utiliser : kmeansNonInit kmeansInit AgglomerativeClustering MeanShift DBSCAN hierarchique
    :param fichier: si on souhaite enregistrer les resultats sous des fichiers
    :return: les fichiers des differents pourcentages, ainsi que la matrice des indices de cartes qui nous donnent deux classes
    """


    ################################################################################
    #Chargement des cartes d'activation et definintion des fichiers d'enregistrement
    ################################################################################

    #chargement des dictionnaires
    map_file_FR = "../maps/BREF80_l_" + couche + "_35maps_th0.500000.pkl"
    map_file_JA = "../maps/PHONIM_l_" + couche + "_35maps_th0.001000.pkl"
    FR= load_maps(map_file_FR)
    JA = load_maps(map_file_JA)

    #recuperation des dimensions pour un dictionnaire
    tableau = np.array(FR['correct_OK']['R'])
    taille=tableau.shape
    listeVide = []
    if couche != "dense1":
        listeVide = strategie_trois_l1([FR, JA], seuilCartesVides)


    #creation des fichiers d'enregistrement
    if fichier == True:
        fichier1 = "../resultats/" + couche + "/" + algorithme +"/pourcentagesFRJA_R.csv"
        fichier1bis = "../resultats/" + couche + "/" + algorithme +"/pourcentagesFRJA_V.csv"
        fichier2 = "../resultats/" + couche + "/" + algorithme +"/pourcentagesRV.csv"
        fichier3 = "../resultats/" + couche + "/" + algorithme +"/pourcentagesCIC_R.csv"
        fichier3bis = "../resultats/" + couche + "/" + algorithme +"/pourcentagesCIC_V.csv"
    else:
        fichier1 = None
        fichier1bis = None
        fichier2 = None
        fichier3 = None
        fichier3bis = None

    #creation des matrices ratio
    pourcentagesFRJA_R = []
    pourcentagesFRJA_V = []
    pourcentagesRV = []
    pourcentagesCIC_R = []
    pourcentagesCIC_V = []

    #Colonne indices que l'on va inserer a chaque fois dans matIndicesCartes
    indices=[]
    #Matrice indices de cartes qui donnent 2 classes, 5 colonnes pour chaque clustering
    matIndicesCartes = []

    ################################################################################
    #Appel du clustering
    ################################################################################

    if algorithme == "kmeansNonInit":
        clus = KMeans(n_clusters=2, init='k-means++')
    elif algorithme == "kmeansInit":
        None
    elif algorithme == "MeanShift":
        clus = MeanShift(bandwidth=None, seeds=None, bin_seeding=False, min_bin_freq=1, cluster_all=True, n_jobs=1)
    elif algorithme == "DBSCAN":
        clus = DBSCAN(eps=0.5, min_samples=5, metric='euclidean', algorithm='auto', leaf_size=30, p=None, random_state=None)
    else:
        print "l'algorithme demande n'existe pas essayez : kmeansNonInit, kmeansInit, MeanShift, DBSCAN"


    ################################################################################
    #Clustering 1
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering
    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR, JA],FR.keys(),['R'])
    #decommenter ces lignes pour ne prendre en compte que les element qui ont ete bien classes (correctOK et incorrectOK)
    #indicesOK = [index for index,row in enumerate(Reference) if ((row[1]==1) or (row[1]==2))]
    #Mat = Mat[:,indicesOK,:]
    #Reference = Reference[indicesOK,:]
    #calcul des ratios de classement
    for i in range (taille[1]):
            if not(i in listeVide):
                if algorithme=="kmeansInit":
                    type_clustering = 'FRJAP_R'
                    centres = initialisation_centres (type_clustering, Mat, Reference)
                    clus = KMeans(n_clusters=2, init=centres)
                resCluster = clus.fit(Mat[i])
                Y_Cluster = resCluster.labels_
                if (max(Y_Cluster) +1) ==2:
                    indices.append(i)
                    FRJA = ratios(Y_Cluster, Reference[:,0])
                    pourcentagesFRJA_R.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier1, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "JA-R"])
        np.savetxt(f,np.atleast_2d(pourcentagesFRJA_R), delimiter =',')


    ################################################################################
    #Clustering 1bis
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering
    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR, JA],FR.keys(),['v'])
    indices=[]
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            if algorithme=="kmeansInit":
                type_clustering = 'FRJAP_v'
                centres = initialisation_centres (type_clustering, Mat, Reference)
                clus = KMeans(n_clusters=2, init=centres)
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,0])
                pourcentagesFRJA_V.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier1bis, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-V", "JA-V"])
        np.savetxt(f,np.atleast_2d(pourcentagesFRJA_V), delimiter =',')


    ################################################################################
    #Clustering 2
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([FR],FR.keys(),['R', 'v'])
    indices=[]
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            if algorithme=="kmeansInit":
                type_clustering = 'R_v'
                centres = initialisation_centres (type_clustering, Mat, Reference)
                clus = KMeans(n_clusters=2, init=centres)
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,2])
                pourcentagesRV.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier2, "wb")
        writer = csv.writer(f)
        writer.writerow(["FR-R", "FR-V"])
        np.savetxt(f, np.atleast_2d(pourcentagesRV), delimiter =',')


    ################################################################################
    #Clustering 3
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([JA],JA.keys(),['R'])
    indices=[]
    #rassemblement des correct_OK et correct_PasOK et des incorrect_OK et incorrect_PasOK en correct et incorrect
    for i in range(len(Reference[:,1])):
        if Reference[i,1] == 1:
            Reference[i,1] = 0
        if Reference[i,1] == 2:
            Reference[i,1] = 1
        if Reference[i,1] == 3:
            Reference[i,1] = 1
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            if algorithme=="kmeansInit":
                type_clustering = 'CIC_R'
                centres = initialisation_centres (type_clustering, Mat, Reference)
                clus = KMeans(n_clusters=2, init=centres)
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,1])
                pourcentagesCIC_R.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier3, "wb")
        writer = csv.writer(f)
        writer.writerow(["JA-CORR-R", "JA-INC-R"])
        np.savetxt(f, np.atleast_2d(pourcentagesCIC_R), delimiter =',')


    ################################################################################
    #Clustering 3bis
    ################################################################################

    # ouverture du fichier d'ecriture et precision sur la nature du clustering

    #creation du tenser
    Mat, Reference = pretraitementMatrice([JA],JA.keys(),['v'])
    indices=[]
    for i in range(len(Reference[:,1])):
        if Reference[i,1] == 1:
            Reference[i,1] = 0
        if Reference[i,1] == 2:
            Reference[i,1] = 1
        if Reference[i,1] == 3:
            Reference[i,1] = 1
    #calcul des ratios de classement
    for i in range (taille[1]):
        if not(i in listeVide):
            if algorithme=="kmeansInit":
                type_clustering = 'CIC_v'
                centres = initialisation_centres (type_clustering, Mat, Reference)
                clus = KMeans(n_clusters=2, init=centres)
            resCluster = clus.fit(Mat[i])
            Y_Cluster = resCluster.labels_
            if (max(Y_Cluster) +1) ==2:
                indices.append(i)
                FRJA = ratios(Y_Cluster, Reference[:,1])
                pourcentagesCIC_V.append(FRJA[0])
    matIndicesCartes.append(indices)
    if fichier == True:
        f = open(fichier3bis, "wb")
        writer = csv.writer(f)
        writer.writerow(["JA-CORR-V", "JA-INC-V"])
        np.savetxt(f, np.atleast_2d(pourcentagesCIC_V), delimiter =',')

    matIndicesCartes=np.array(matIndicesCartes)
    return pourcentagesFRJA_R, pourcentagesFRJA_V, pourcentagesRV, pourcentagesCIC_R, pourcentagesCIC_V, matIndicesCartes
예제 #6
0
                     indices=[10, 20, 30, 40, 50, 60, 70])
if (bon == [10, 30]):
    print "test 6 : test de la matrice indice : OK"
else:
    print "test 6 : test de la matrice indice : KO"

########################################################################################################################
######################################## TEST INITIALISATION CENTRES ###################################################
########################################################################################################################

#test 1 : test du format de sortie
print "\n###################################\n"
print "tests initialisation_centres\n"
print "###################################\n"
map_file_FR = '../../maps/BREF80_l_conv1_35maps_th0.500000.pkl'
FR = load_maps(map_file_FR)

type_clustering = 'R_v'
Mat, Reference = pretraitementMatrice([FR], FR.keys(), ['R', 'v'])

centres = initialisation_centres(type_clustering, Mat, Reference)

if (centres.shape == (2, Mat.shape[2])):
    print(
        'Test 1 initialisation_centres ok : La matrice de sortie a la bonne forme'
    )
else:
    print(
        'Test 1 initialisation_centres pas ok !! La matrice de sortie n a pas la bonne forme'
    )
예제 #7
0
def imagesCartesInteressantes(indice_carte_interessante,
                              indice_carte_non_int,
                              couche='conv1',
                              clustering='1'):
    '''
    :param indice_carte_interessante: Indice de la carte interessante (cf fichier bonClustering)
    :param indice_carte_non_int: Indice de la deuxieme carte a laquelle on veut la comparer
    :param couche: ='conv1','conv2','dense1','mp2'
    :param clustering: 1, 1bis, 2, 3, 3bis suivant le type de clustering effectue
    :return: Image de la carte (interessante et non interessante) stockee dans resultats/couche
    '''

    #Load the maps corresponding to the selected layer
    map_file_FR = '../maps/BREF80_l_' + couche + '_35maps_th0.500000.pkl'
    map_file_JA = '../maps/PHONIM_l_' + couche + '_35maps_th0.001000.pkl'
    FR = load_maps(map_file_FR)
    JA = load_maps(map_file_JA)

    #Load and plot giving the chosen clustering
    if clustering == '1':
        phone = 'R'
        cat = 'correct_pasOK'
        ex = 8

        map1 = FR[cat][phone][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone][ex][indice_carte_non_int]

        map2 = JA[cat][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-R")
        ax[0, 0].imshow(map1, aspect='auto')
        ax[0, 0].set_title("FR-int")
        ax[0, 1].imshow(othermap1, aspect='auto')
        ax[0, 1].set_title("FR-nonInt")
        ax[1, 0].imshow(map2, aspect='auto')
        ax[1, 0].set_title("JA-int")
        ax[1, 1].imshow(othermap2, aspect='auto')
        ax[1, 1].set_title("JA-nonInt")

    elif clustering == '1bis':
        phone = 'v'
        cat = 'correct_pasOK'
        ex = 8
        map1 = FR[cat][phone][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone][ex][indice_carte_non_int]

        map2 = JA[cat][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 2 : FRJA-V")
        ax[0, 0].imshow(map1, aspect='auto')
        ax[0, 0].set_title("FR-int")
        ax[0, 1].imshow(othermap1, aspect='auto')
        ax[0, 1].set_title("FR-nonInt")
        ax[1, 0].imshow(map2, aspect='auto')
        ax[1, 0].set_title("JA-int")
        ax[1, 1].imshow(othermap2, aspect='auto')
        ax[1, 1].set_title("JA-nonInt")

    elif clustering == 2:
        phone1 = 'R'
        phone2 = 'v'
        cat = 'correct_pasOK'
        ex = 8

        map1 = FR[cat][phone1][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone1][ex][indice_carte_non_int]

        map2 = FR[cat][phone2][ex][indice_carte_interessante]
        othermap2 = FR[cat][phone2][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 3 : FR-RV")
        ax[0, 0].imshow(map1, aspect='auto')
        ax[0, 0].set_title("R-int")
        ax[0, 1].imshow(othermap1, aspect='auto')
        ax[0, 1].set_title("R-nonInt")
        ax[1, 0].imshow(map2, aspect='auto')
        ax[1, 0].set_title("V-int")
        ax[1, 1].imshow(othermap2, aspect='auto')
        ax[1, 1].set_title("V-nonInt")

    elif clustering == '3':
        phone = 'R'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'
        ex = 8

        map1 = JA[cat1][phone][ex][indice_carte_interessante]
        othermap1 = JA[cat1][phone][ex][indice_carte_non_int]

        map2 = JA[cat2][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat2][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 4 : CIC-R (JA)")
        ax[0, 0].imshow(map1, aspect='auto')
        ax[0, 0].set_title("Correct-int")
        ax[0, 1].imshow(othermap1, aspect='auto')
        ax[0, 1].set_title("Correct-nonInt")
        ax[1, 0].imshow(map2, aspect='auto')
        ax[1, 0].set_title("Incorrect-int")
        ax[1, 1].imshow(othermap2, aspect='auto')
        ax[1, 1].set_title("Incorrect-nonInt")

    elif clustering == '3bis':
        phone = 'v'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'
        ex = 8

        map1 = JA[cat1][phone][ex][indice_carte_interessante]
        othermap1 = JA[cat1][phone][ex][indice_carte_non_int]

        map2 = JA[cat2][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat2][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 5 : CIC-V (JA)")
        ax[0, 0].imshow(map1, aspect='auto')
        ax[0, 0].set_title("Correct-int")
        ax[0, 1].imshow(othermap1, aspect='auto')
        ax[0, 1].set_title("Correct-nonInt")
        ax[1, 0].imshow(map2, aspect='auto')
        ax[1, 0].set_title("Incorrect-int")
        ax[1, 1].imshow(othermap2, aspect='auto')
        ax[1, 1].set_title("Incorrect-nonInt")

    for i in range(2):
        for j in range(2):
            ax[i, j].xaxis.set_visible(False)
            ax[i, j].yaxis.set_visible(False)
    plt.axis('off')
    plt.show()
    plt.savefig('../resultats/' + str(couche) + '/carte' +
                str(indice_carte_interessante) + str(couche) + 'clus' +
                clustering + '.png')
예제 #8
0
# Fait pour toutes les combinaisons de dictionnaires, toutes les combinaisons de phonemes, pour tous les types de classifications,

#Files
mapconv1J_file = 'maps/PHONIM_l_conv1_35maps_th0.001000.pkl'
mapconv2J_file = 'maps/PHONIM_l_conv2_35maps_th0.001000.pkl'
mapmp2J_file = 'maps/PHONIM_l_mp2_35maps_th0.001000.pkl'
denseJ_file = 'maps/PHONIM_l_dense1_35maps_th0.001000.pkl'
mapconv1F_file = 'maps/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv2F_file = 'maps/BREF80_l_conv2_35maps_th0.500000.pkl'
mapmp2F_file = 'maps/BREF80_l_mp2_35maps_th0.500000.pkl'
denseF_file = 'maps/BREF80_l_dense1_35maps_th0.500000.pkl'
mapconv1F_file_newFbank = '../maps2/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv1J_file_newFbank = '../maps2/PHONIM_l_conv1_35maps_th0.001000.pkl'

#Load data
conv1J = load_maps(mapconv1J_file)
conv2J = load_maps(mapconv2J_file)
mpJ = load_maps(mapmp2J_file)
#denseJ = load_maps(denseJ_file)
conv1F = load_maps(mapconv1F_file)
conv2F = load_maps(mapconv2F_file)
mpF = load_maps(mapmp2F_file)
# denseF = load_maps(denseF_file)
#conv1F_newFbank = load_maps(mapconv1F_file_newFbank)
#conv1J_newFbank = load_maps(mapconv1J_file_newFbank)

# liste des ensembles de dictionnaires que l'on veut prendre en donnees d'entree
#liste_dics = [[mpF],[mpJ],[mpF,mpJ]]
#dics_labels = ['mp2F','mp2J','mp2F_mp2J']
#liste_dics = [[conv1F],[conv1J],[conv1F,conv1J]]
#dics_labels = ['conv1F','conv1J','conv1F_conv1J']
예제 #9
0
# Results (Kfold mean scores) are printed into a text file

#Files
mapconv1J_file='../maps/PHONIM_l_conv1_35maps_th0.001000.pkl'
mapconv2J_file='../maps/PHONIM_l_conv2_35maps_th0.001000.pkl'
mapmp2J_file='../maps/PHONIM_l_mp2_35maps_th0.001000.pkl'
denseJ_file = '../maps/PHONIM_l_dense1_35maps_th0.001000.pkl'
mapconv1F_file='../maps/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv2F_file='../maps/BREF80_l_conv2_35maps_th0.500000.pkl'
mapmp2F_file='../maps/BREF80_l_mp2_35maps_th0.500000.pkl'
denseF_file = '../maps/BREF80_l_dense1_35maps_th0.500000.pkl'
mapconv1F_file_newFbank = '../maps2/BREF80_l_conv1_35maps_th0.500000.pkl'
mapconv1J_file_newFbank = '../maps2/PHONIM_l_conv1_35maps_th0.001000.pkl'

#Load data
conv1J = load_maps(mapconv1J_file)
#conv2J = load_maps(mapconv2J_file)
#mpJ = load_maps(mapmp2J_file)
# denseJ = load_maps(denseJ_file)
conv1F = load_maps(mapconv1F_file)
#conv2F = load_maps(mapconv2F_file)
#mpF = load_maps(mapmp2F_file)
# denseF = load_maps(denseF_file)
#conv1F_newFbank = load_maps(mapconv1F_file_newFbank)
#conv1J_newFbank = load_maps(mapconv1J_file_newFbank)

# liste des ensembles de dictionnaires que l'on veut prendre en donnees d'entree
all_liste_dics = [[conv1F],[conv1J],[conv1J,conv1F]]
labels_dictionnaire = ['FR','JAP','FR JAP'] #Pour ecrire dans le fichier

# Listes des phonemes que l'on veut traiter
예제 #10
0
def imagesCartesInteressantes(indice_carte_interessante, indice_carte_non_int, couche="conv1", clustering="1"):
    """
    :param indice_carte_interessante: Indice de la carte interessante (cf fichier bonClustering)
    :param indice_carte_non_int: Indice de la deuxieme carte a laquelle on veut la comparer
    :param couche: ='conv1','conv2','dense1','mp2'
    :param clustering: 1, 1bis, 2, 3, 3bis suivant le type de clustering effectue
    :return: Image de la carte (interessante et non interessante) stockee dans resultats/couche
    """

    # Load the maps corresponding to the selected layer
    map_file_FR = "../maps/BREF80_l_" + couche + "_35maps_th0.500000.pkl"
    map_file_JA = "../maps/PHONIM_l_" + couche + "_35maps_th0.001000.pkl"
    FR = load_maps(map_file_FR)
    JA = load_maps(map_file_JA)

    # Load and plot giving the chosen clustering
    if clustering == "1":
        phone = "R"
        cat = "correct_pasOK"
        ex = 8

        map1 = FR[cat][phone][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone][ex][indice_carte_non_int]

        map2 = JA[cat][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-R")
        ax[0, 0].imshow(map1, aspect="auto")
        ax[0, 0].set_title("FR-int")
        ax[0, 1].imshow(othermap1, aspect="auto")
        ax[0, 1].set_title("FR-nonInt")
        ax[1, 0].imshow(map2, aspect="auto")
        ax[1, 0].set_title("JA-int")
        ax[1, 1].imshow(othermap2, aspect="auto")
        ax[1, 1].set_title("JA-nonInt")

    elif clustering == "1bis":
        phone = "v"
        cat = "correct_pasOK"
        ex = 8
        map1 = FR[cat][phone][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone][ex][indice_carte_non_int]

        map2 = JA[cat][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 2 : FRJA-V")
        ax[0, 0].imshow(map1, aspect="auto")
        ax[0, 0].set_title("FR-int")
        ax[0, 1].imshow(othermap1, aspect="auto")
        ax[0, 1].set_title("FR-nonInt")
        ax[1, 0].imshow(map2, aspect="auto")
        ax[1, 0].set_title("JA-int")
        ax[1, 1].imshow(othermap2, aspect="auto")
        ax[1, 1].set_title("JA-nonInt")

    elif clustering == 2:
        phone1 = "R"
        phone2 = "v"
        cat = "correct_pasOK"
        ex = 8

        map1 = FR[cat][phone1][ex][indice_carte_interessante]
        othermap1 = FR[cat][phone1][ex][indice_carte_non_int]

        map2 = FR[cat][phone2][ex][indice_carte_interessante]
        othermap2 = FR[cat][phone2][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 3 : FR-RV")
        ax[0, 0].imshow(map1, aspect="auto")
        ax[0, 0].set_title("R-int")
        ax[0, 1].imshow(othermap1, aspect="auto")
        ax[0, 1].set_title("R-nonInt")
        ax[1, 0].imshow(map2, aspect="auto")
        ax[1, 0].set_title("V-int")
        ax[1, 1].imshow(othermap2, aspect="auto")
        ax[1, 1].set_title("V-nonInt")

    elif clustering == "3":
        phone = "R"
        cat1 = "correct_OK"
        cat2 = "incorrect_OK"
        ex = 8

        map1 = JA[cat1][phone][ex][indice_carte_interessante]
        othermap1 = JA[cat1][phone][ex][indice_carte_non_int]

        map2 = JA[cat2][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat2][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 4 : CIC-R (JA)")
        ax[0, 0].imshow(map1, aspect="auto")
        ax[0, 0].set_title("Correct-int")
        ax[0, 1].imshow(othermap1, aspect="auto")
        ax[0, 1].set_title("Correct-nonInt")
        ax[1, 0].imshow(map2, aspect="auto")
        ax[1, 0].set_title("Incorrect-int")
        ax[1, 1].imshow(othermap2, aspect="auto")
        ax[1, 1].set_title("Incorrect-nonInt")

    elif clustering == "3bis":
        phone = "v"
        cat1 = "correct_OK"
        cat2 = "incorrect_OK"
        ex = 8

        map1 = JA[cat1][phone][ex][indice_carte_interessante]
        othermap1 = JA[cat1][phone][ex][indice_carte_non_int]

        map2 = JA[cat2][phone][ex][indice_carte_interessante]
        othermap2 = JA[cat2][phone][ex][indice_carte_non_int]

        plt.figure()
        f, ax = plt.subplots(2, 2, sharex=True, sharey=True)
        f.suptitle("Clustering 5 : CIC-V (JA)")
        ax[0, 0].imshow(map1, aspect="auto")
        ax[0, 0].set_title("Correct-int")
        ax[0, 1].imshow(othermap1, aspect="auto")
        ax[0, 1].set_title("Correct-nonInt")
        ax[1, 0].imshow(map2, aspect="auto")
        ax[1, 0].set_title("Incorrect-int")
        ax[1, 1].imshow(othermap2, aspect="auto")
        ax[1, 1].set_title("Incorrect-nonInt")

    for i in range(2):
        for j in range(2):
            ax[i, j].xaxis.set_visible(False)
            ax[i, j].yaxis.set_visible(False)
    plt.axis("off")
    plt.show()
    plt.savefig(
        "../resultats/"
        + str(couche)
        + "/carte"
        + str(indice_carte_interessante)
        + str(couche)
        + "clus"
        + clustering
        + ".png"
    )
예제 #11
0
import pickle
import numpy as np
from utiles_classification import *
from mapsAnalysis.utiles import *
from process_activation_maps import load_maps

# LDA classification using mfcc raw data

mfcc_phone = '../maps/Train_mfcc_phone_array_NORMED.pkl'
mfcc = load_maps(mfcc_phone)

Y_c_inc = np.array(mfcc['y'])
X = np.array(mfcc['X'])
X_phones = np.array(mfcc['X_phone'])
X = X.reshape((X.shape[0],X.shape[2]*X.shape[3])) #To put in lda

# All sets of data by phone
phone_sets = [[1,1,1,1],[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,1,0,0],[0,1,1,0],[0,0,1,1],[1,0,0,1],[1,0,1,0],[0,1,0,1],[1,1,1,0],[0,1,1,1],[1,0,1,1],[1,1,0,1]]
n_folds = 5
dim = -1 #call to best dimension
f_res = open('./resultats_temp/LDA_resultats_mfcc_phones.txt','w')

# Correct/incorrect classification
f_res.write('MFCC LDA classification \n2 classes : correct/incorrect \n')
for phones in phone_sets:
    X_t,Y_c_inc_t = selectPhones(X,X_phones,Y_c_inc,phones)
    score = LDAmeanScore(X_t,Y_c_inc_t,n_folds,dim_reduction=dim)
    f_res.write('Selected phones :'+str(phones)+' Score : '+str(score)+'\n')

# Phone category classification
f_res.write('MFCC LDA classification \nnb_phonemes classes (one class per phone) \n')
예제 #12
0
import pickle
import numpy as np
from utiles_classification import *
from process_activation_maps import load_maps


# LDA on dense parameters

denseJ_file = '../maps/PHONIM_l_dense1_35maps_th0.001000.pkl'
denseF_file = '../maps/BREF80_l_dense1_35maps_th0.500000.pkl'
denseJ = load_maps(denseJ_file)
denseF = load_maps(denseF_file)

# liste des ensembles de dictionnaires que l'on veut prendre en donnees d'entree
all_liste_dics = [[denseF],[denseJ],[denseF,denseJ]]
labels_dictionnaire = ['FR','JAP','FR JAP'] #Pour ecrire dans le fichier

# Listes des phonemes que l'on veut traiter
all_listes_phonemes = [['R'],['v'],['R','v']]
labels_phonemes = [' R ',' v ',' R v '] #Pour ecrire dans le fichier

#Categories que l'on veut traiter, on prend tout en general
all_categories = denseF.keys()

#Type de classification que l'on veut faire
types = ['c_inc','r_v','fr_jap']

a_ignorer = []
l_cartes = []
n_folds = 5
f_res = open('LDA_resultats_dense.txt', 'w')
예제 #13
0
def imagesCartesInteressantes(indice_carte_interessante, couche='conv1', clustering='1'):
    '''
    Permet de visualiser la carte jugee interessante pour 3 exemples
    :param indice_carte_interessante: Indice de la carte interessante (cf fichier bonClustering)
    :param couche: ='conv1','conv2','dense1','mp2'
    :param clustering: 1, 1bis, 2, 3, 3bis suivant le type de clustering effectue
    :return: Image de la carte (interessante) stockee dans resultats/couche
    '''

    #Load the maps corresponding to the selected layer
    map_file_FR = '../maps/BREF80_l_' + couche + '_35maps_th0.500000.pkl'
    map_file_JA = '../maps/PHONIM_l_' + couche + '_35maps_th0.001000.pkl'
    FR= load_maps(map_file_FR)
    JA = load_maps(map_file_JA)


    #Load and plot giving the chosen clustering
    if clustering == '1':
        phone = 'R'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone][ex][indice_carte_interessante]
        map21= JA[cat][phone][ex][indice_carte_interessante]

        map12 = FR[cat][phone][ex+10][indice_carte_interessante]
        map22 = JA[cat][phone][ex+10][indice_carte_interessante]

        map13 = FR[cat][phone][ex+20][indice_carte_interessante]
        map23 = JA[cat][phone][ex+20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-R (carte interessante " + str(indice_carte_interessante) + ")")
        ax[0,0].imshow(map11, aspect='auto')
        ax[0,0].set_title("FR - exemple " + str(ex))
        ax[1,0].imshow(map21, aspect='auto')
        ax[1,0].set_title("JA - exemple " + str(ex))

        ax[0,1].imshow(map12, aspect='auto')
        ax[0,1].set_title("FR - exemple " + str(ex+10))
        ax[1,1].imshow(map22, aspect='auto')
        ax[1,1].set_title("JA - exemple " + str(ex+10))

        ax[0,2].imshow(map13, aspect='auto')
        ax[0,2].set_title("FR - exemple " + str(ex+20))
        ax[1,2].imshow(map23, aspect='auto')
        ax[1,2].set_title("JA - exemple " + str(ex+20))

    elif clustering == '1bis':
        phone = 'v'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone][ex][indice_carte_interessante]
        map21= JA[cat][phone][ex][indice_carte_interessante]

        map12 = FR[cat][phone][ex+10][indice_carte_interessante]
        map22 = JA[cat][phone][ex+10][indice_carte_interessante]

        map13 = FR[cat][phone][ex+20][indice_carte_interessante]
        map23 = JA[cat][phone][ex+20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-V (carte interessante " + str(indice_carte_interessante) + ")")
        ax[0,0].imshow(map11, aspect='auto')
        ax[0,0].set_title("FR - exemple " + str(ex))
        ax[1,0].imshow(map21, aspect='auto')
        ax[1,0].set_title("JA - exemple " + str(ex))

        ax[0,1].imshow(map12, aspect='auto')
        ax[0,1].set_title("FR - exemple " + str(ex+10))
        ax[1,1].imshow(map22, aspect='auto')
        ax[1,1].set_title("JA - exemple " + str(ex+10))

        ax[0,2].imshow(map13, aspect='auto')
        ax[0,2].set_title("FR - exemple " + str(ex+20))
        ax[1,2].imshow(map23, aspect='auto')
        ax[1,2].set_title("JA - exemple " + str(ex+20))

    elif clustering == 2:
        phone1 = 'R'
        phone2 = 'v'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone1][ex][indice_carte_interessante]
        map21= FR[cat][phone2][ex][indice_carte_interessante]

        map12 = FR[cat][phone1][ex+10][indice_carte_interessante]
        map22 = FR[cat][phone2][ex+10][indice_carte_interessante]

        map13 = FR[cat][phone1][ex+20][indice_carte_interessante]
        map23 = FR[cat][phone2][ex+20][indice_carte_interessante]


        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FR-RV (carte interessante " + str(indice_carte_interessante) + ")")
        ax[0,0].imshow(map11, aspect='auto')
        ax[0,0].set_title("FR-R - exemple " + str(ex))
        ax[1,0].imshow(map21, aspect='auto')
        ax[1,0].set_title("FR-V - exemple " + str(ex))

        ax[0,1].imshow(map12, aspect='auto')
        ax[0,1].set_title("FR-R - exemple " + str(ex+10))
        ax[1,1].imshow(map22, aspect='auto')
        ax[1,1].set_title("FR-V - exemple " + str(ex+10))

        ax[0,2].imshow(map13, aspect='auto')
        ax[0,2].set_title("FR-R - exemple " + str(ex+20))
        ax[1,2].imshow(map23, aspect='auto')
        ax[1,2].set_title("FR-V - exemple " + str(ex+20))

    elif clustering == '3':
        phone = 'R'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'

        ex = 0

        map11 = JA[cat1][phone][ex][indice_carte_interessante]
        map21= JA[cat2][phone][ex][indice_carte_interessante]

        map12 = JA[cat1][phone][ex+10][indice_carte_interessante]
        map22 = JA[cat2][phone][ex+10][indice_carte_interessante]

        map13 = JA[cat1][phone][ex+20][indice_carte_interessante]
        map23 = JA[cat2][phone][ex+20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : JA-CIC-R (carte interessante " + str(indice_carte_interessante) + ")")
        ax[0,0].imshow(map11, aspect='auto')
        ax[0,0].set_title("JA-R-Correct - exemple " + str(ex))
        ax[1,0].imshow(map21, aspect='auto')
        ax[1,0].set_title("JA-R-Incorrect - exemple " + str(ex))

        ax[0,1].imshow(map12, aspect='auto')
        ax[0,1].set_title("JA-R-Correct - exemple " + str(ex+10))
        ax[1,1].imshow(map22, aspect='auto')
        ax[1,1].set_title("JA-R-Incorrect - exemple " + str(ex+10))

        ax[0,2].imshow(map13, aspect='auto')
        ax[0,2].set_title("JA-R-Correct - exemple " + str(ex+20))
        ax[1,2].imshow(map23, aspect='auto')
        ax[1,2].set_title("JA-R-Incorrect - exemple " + str(ex+20))



    elif clustering == '3bis':
        phone = 'v'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'
        ex = 0

        map11 = JA[cat1][phone][ex][indice_carte_interessante]
        map21= JA[cat2][phone][ex][indice_carte_interessante]

        map12 = JA[cat1][phone][ex+10][indice_carte_interessante]
        map22 = JA[cat2][phone][ex+10][indice_carte_interessante]

        map13 = JA[cat1][phone][ex+20][indice_carte_interessante]
        map23 = JA[cat2][phone][ex+20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : JA-CIC-V (carte interessante " + str(indice_carte_interessante) + ")")
        ax[0,0].imshow(map11, aspect='auto')
        ax[0,0].set_title("JA-V-Correct - exemple " + str(ex))
        ax[1,0].imshow(map21, aspect='auto')
        ax[1,0].set_title("JA-V-Incorrect - exemple " + str(ex))

        ax[0,1].imshow(map12, aspect='auto')
        ax[0,1].set_title("JA-V-Correct - exemple " + str(ex+10))
        ax[1,1].imshow(map22, aspect='auto')
        ax[1,1].set_title("JA-V-Incorrect - exemple " + str(ex+10))

        ax[0,2].imshow(map13, aspect='auto')
        ax[0,2].set_title("JA-V-Correct - exemple " + str(ex+20))
        ax[1,2].imshow(map23, aspect='auto')
        ax[1,2].set_title("JA-V-Incorrect - exemple " + str(ex+20))


    for i in range(2):
        for j in range(2):
            ax[i,j].xaxis.set_visible(False)
            ax[i,j].yaxis.set_visible(False)
    plt.axis('off')
    plt.show()
    plt.savefig('../resultats/'+str(couche)+'/carte'+str(indice_carte_interessante)+str(couche)+'clus'+clustering+'.png')
예제 #14
0
def imagesCartesInteressantes(indice_carte_interessante,
                              couche='conv1',
                              clustering='1'):
    '''
    Permet de visualiser la carte jugee interessante pour 3 exemples
    :param indice_carte_interessante: Indice de la carte interessante (cf fichier bonClustering)
    :param couche: ='conv1','conv2','dense1','mp2'
    :param clustering: 1, 1bis, 2, 3, 3bis suivant le type de clustering effectue
    :return: Image de la carte (interessante) stockee dans resultats/couche
    '''

    #Load the maps corresponding to the selected layer
    map_file_FR = '../maps/BREF80_l_' + couche + '_35maps_th0.500000.pkl'
    map_file_JA = '../maps/PHONIM_l_' + couche + '_35maps_th0.001000.pkl'
    FR = load_maps(map_file_FR)
    JA = load_maps(map_file_JA)

    #Load and plot giving the chosen clustering
    if clustering == '1':
        phone = 'R'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone][ex][indice_carte_interessante]
        map21 = JA[cat][phone][ex][indice_carte_interessante]

        map12 = FR[cat][phone][ex + 10][indice_carte_interessante]
        map22 = JA[cat][phone][ex + 10][indice_carte_interessante]

        map13 = FR[cat][phone][ex + 20][indice_carte_interessante]
        map23 = JA[cat][phone][ex + 20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-R (carte interessante " +
                   str(indice_carte_interessante) + ")")
        ax[0, 0].imshow(map11, aspect='auto')
        ax[0, 0].set_title("FR - exemple " + str(ex))
        ax[1, 0].imshow(map21, aspect='auto')
        ax[1, 0].set_title("JA - exemple " + str(ex))

        ax[0, 1].imshow(map12, aspect='auto')
        ax[0, 1].set_title("FR - exemple " + str(ex + 10))
        ax[1, 1].imshow(map22, aspect='auto')
        ax[1, 1].set_title("JA - exemple " + str(ex + 10))

        ax[0, 2].imshow(map13, aspect='auto')
        ax[0, 2].set_title("FR - exemple " + str(ex + 20))
        ax[1, 2].imshow(map23, aspect='auto')
        ax[1, 2].set_title("JA - exemple " + str(ex + 20))

    elif clustering == '1bis':
        phone = 'v'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone][ex][indice_carte_interessante]
        map21 = JA[cat][phone][ex][indice_carte_interessante]

        map12 = FR[cat][phone][ex + 10][indice_carte_interessante]
        map22 = JA[cat][phone][ex + 10][indice_carte_interessante]

        map13 = FR[cat][phone][ex + 20][indice_carte_interessante]
        map23 = JA[cat][phone][ex + 20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FRJA-V (carte interessante " +
                   str(indice_carte_interessante) + ")")
        ax[0, 0].imshow(map11, aspect='auto')
        ax[0, 0].set_title("FR - exemple " + str(ex))
        ax[1, 0].imshow(map21, aspect='auto')
        ax[1, 0].set_title("JA - exemple " + str(ex))

        ax[0, 1].imshow(map12, aspect='auto')
        ax[0, 1].set_title("FR - exemple " + str(ex + 10))
        ax[1, 1].imshow(map22, aspect='auto')
        ax[1, 1].set_title("JA - exemple " + str(ex + 10))

        ax[0, 2].imshow(map13, aspect='auto')
        ax[0, 2].set_title("FR - exemple " + str(ex + 20))
        ax[1, 2].imshow(map23, aspect='auto')
        ax[1, 2].set_title("JA - exemple " + str(ex + 20))

    elif clustering == 2:
        phone1 = 'R'
        phone2 = 'v'
        cat = 'correct_OK'
        ex = 0

        map11 = FR[cat][phone1][ex][indice_carte_interessante]
        map21 = FR[cat][phone2][ex][indice_carte_interessante]

        map12 = FR[cat][phone1][ex + 10][indice_carte_interessante]
        map22 = FR[cat][phone2][ex + 10][indice_carte_interessante]

        map13 = FR[cat][phone1][ex + 20][indice_carte_interessante]
        map23 = FR[cat][phone2][ex + 20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : FR-RV (carte interessante " +
                   str(indice_carte_interessante) + ")")
        ax[0, 0].imshow(map11, aspect='auto')
        ax[0, 0].set_title("FR-R - exemple " + str(ex))
        ax[1, 0].imshow(map21, aspect='auto')
        ax[1, 0].set_title("FR-V - exemple " + str(ex))

        ax[0, 1].imshow(map12, aspect='auto')
        ax[0, 1].set_title("FR-R - exemple " + str(ex + 10))
        ax[1, 1].imshow(map22, aspect='auto')
        ax[1, 1].set_title("FR-V - exemple " + str(ex + 10))

        ax[0, 2].imshow(map13, aspect='auto')
        ax[0, 2].set_title("FR-R - exemple " + str(ex + 20))
        ax[1, 2].imshow(map23, aspect='auto')
        ax[1, 2].set_title("FR-V - exemple " + str(ex + 20))

    elif clustering == '3':
        phone = 'R'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'

        ex = 0

        map11 = JA[cat1][phone][ex][indice_carte_interessante]
        map21 = JA[cat2][phone][ex][indice_carte_interessante]

        map12 = JA[cat1][phone][ex + 10][indice_carte_interessante]
        map22 = JA[cat2][phone][ex + 10][indice_carte_interessante]

        map13 = JA[cat1][phone][ex + 20][indice_carte_interessante]
        map23 = JA[cat2][phone][ex + 20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : JA-CIC-R (carte interessante " +
                   str(indice_carte_interessante) + ")")
        ax[0, 0].imshow(map11, aspect='auto')
        ax[0, 0].set_title("JA-R-Correct - exemple " + str(ex))
        ax[1, 0].imshow(map21, aspect='auto')
        ax[1, 0].set_title("JA-R-Incorrect - exemple " + str(ex))

        ax[0, 1].imshow(map12, aspect='auto')
        ax[0, 1].set_title("JA-R-Correct - exemple " + str(ex + 10))
        ax[1, 1].imshow(map22, aspect='auto')
        ax[1, 1].set_title("JA-R-Incorrect - exemple " + str(ex + 10))

        ax[0, 2].imshow(map13, aspect='auto')
        ax[0, 2].set_title("JA-R-Correct - exemple " + str(ex + 20))
        ax[1, 2].imshow(map23, aspect='auto')
        ax[1, 2].set_title("JA-R-Incorrect - exemple " + str(ex + 20))

    elif clustering == '3bis':
        phone = 'v'
        cat1 = 'correct_OK'
        cat2 = 'incorrect_OK'
        ex = 0

        map11 = JA[cat1][phone][ex][indice_carte_interessante]
        map21 = JA[cat2][phone][ex][indice_carte_interessante]

        map12 = JA[cat1][phone][ex + 10][indice_carte_interessante]
        map22 = JA[cat2][phone][ex + 10][indice_carte_interessante]

        map13 = JA[cat1][phone][ex + 20][indice_carte_interessante]
        map23 = JA[cat2][phone][ex + 20][indice_carte_interessante]

        plt.figure()
        f, ax = plt.subplots(2, 3, sharex=True, sharey=True)
        f.suptitle("Clustering 1 : JA-CIC-V (carte interessante " +
                   str(indice_carte_interessante) + ")")
        ax[0, 0].imshow(map11, aspect='auto')
        ax[0, 0].set_title("JA-V-Correct - exemple " + str(ex))
        ax[1, 0].imshow(map21, aspect='auto')
        ax[1, 0].set_title("JA-V-Incorrect - exemple " + str(ex))

        ax[0, 1].imshow(map12, aspect='auto')
        ax[0, 1].set_title("JA-V-Correct - exemple " + str(ex + 10))
        ax[1, 1].imshow(map22, aspect='auto')
        ax[1, 1].set_title("JA-V-Incorrect - exemple " + str(ex + 10))

        ax[0, 2].imshow(map13, aspect='auto')
        ax[0, 2].set_title("JA-V-Correct - exemple " + str(ex + 20))
        ax[1, 2].imshow(map23, aspect='auto')
        ax[1, 2].set_title("JA-V-Incorrect - exemple " + str(ex + 20))

    for i in range(2):
        for j in range(2):
            ax[i, j].xaxis.set_visible(False)
            ax[i, j].yaxis.set_visible(False)
    plt.axis('off')
    plt.show()
    plt.savefig('../resultats/' + str(couche) + '/carte' +
                str(indice_carte_interessante) + str(couche) + 'clus' +
                clustering + '.png')