Exemplo n.º 1
0
def plotBar(Ncandidats,Nelecteurs, test, Nmentions, root="data"):
    import matplotlib.pyplot as plt
    fname = mj.getFolderName(Ncandidats, Nelecteurs, test, root)
    raw_post   = np.genfromtxt(fname + "raw.results.%i.%i.txt" % (Ncandidats, Nelecteurs), dtype=float, delimiter=",").astype(float)
    n_priori = np.genfromtxt(fname + "terranova.%i.txt" % Ncandidats, dtype=float, delimiter=",").astype(float)
    n_post     = mj.normalize(raw_post)
    nameMentions = ["Excellent", "Tres bien", "Bien", "Assez bien", "Passable", "Insuffisant", "A rejeter"]
    couleurs = ["DarkRed", "Crimson","Tomato","DarkOrange","Yellow","Khaki","DarkKhaki"]
    abs_res = range(0,Ncandidats)
    abs_prob = np.arange(0,Ncandidats) + 0.46
    width = 0.45
    #plt.bar(abs_res, results[:,0], width, color=couleurs[0], label=nameMentions[0])
    for i in range(Nmentions):
	plt.bar(abs_res, n_post[:,i], width,color=couleurs[i],  label=nameMentions[i], bottom=np.sum(n_post[:,:i],axis=1), edgecolor='white')
	plt.bar(abs_prob, n_priori[:,i], width,color=couleurs[i], bottom=np.sum(n_priori[:,:i],axis=1), edgecolor='white')

    plt.ylabel('Mentions')
    plt.xlabel('Candidats')
    plt.title('Jugement majoritaire avec %i candidats et %i electeurs' % (Ncandidats, Nelecteurs))
    #plt.xticks(ind + width/2., ('C1', 'G2', 'G3', 'G4', 'G5'))
    plt.yticks(np.arange(0, 1, 0.1))
    plt.xticks(np.arange(0, Ncandidats))
    plt.legend()

    plt.show()
Exemplo n.º 2
0
def plotBar(Ncandidats, Nelecteurs, test, Nmentions, root="data"):
    import matplotlib.pyplot as plt
    fname = mj.getFolderName(Ncandidats, Nelecteurs, test, root)
    raw_post = np.genfromtxt(fname + "raw.results.%i.%i.txt" %
                             (Ncandidats, Nelecteurs),
                             dtype=float,
                             delimiter=",").astype(float)
    n_priori = np.genfromtxt(fname + "terranova.%i.txt" % Ncandidats,
                             dtype=float,
                             delimiter=",").astype(float)
    n_post = mj.normalize(raw_post)
    nameMentions = [
        "Excellent", "Tres bien", "Bien", "Assez bien", "Passable",
        "Insuffisant", "A rejeter"
    ]
    couleurs = [
        "DarkRed", "Crimson", "Tomato", "DarkOrange", "Yellow", "Khaki",
        "DarkKhaki"
    ]
    abs_res = range(0, Ncandidats)
    abs_prob = np.arange(0, Ncandidats) + 0.46
    width = 0.45
    #plt.bar(abs_res, results[:,0], width, color=couleurs[0], label=nameMentions[0])
    for i in range(Nmentions):
        plt.bar(abs_res,
                n_post[:, i],
                width,
                color=couleurs[i],
                label=nameMentions[i],
                bottom=np.sum(n_post[:, :i], axis=1),
                edgecolor='white')
        plt.bar(abs_prob,
                n_priori[:, i],
                width,
                color=couleurs[i],
                bottom=np.sum(n_priori[:, :i], axis=1),
                edgecolor='white')

    plt.ylabel('Mentions')
    plt.xlabel('Candidats')
    plt.title('Jugement majoritaire avec %i candidats et %i electeurs' %
              (Ncandidats, Nelecteurs))
    #plt.xticks(ind + width/2., ('C1', 'G2', 'G3', 'G4', 'G5'))
    plt.yticks(np.arange(0, 1, 0.1))
    plt.xticks(np.arange(0, Ncandidats))
    plt.legend()

    plt.show()
Exemplo n.º 3
0
def readData(Ncandidats, Nelecteurs, test, root = "data", relog = False):
    folder = mj.getFolderName(Ncandidats, Nelecteurs, test)
    fname = folder + "log.txt"
    if not os.path.isfile(fname + "log.txt") or relog:
        mj.computeLog(Ncandidats, Nelecteurs, test, root)

    f = open(fname, "r")
    p = re.compile(ur'5 premiers: ([0-9]+),')
    a = []
    for l in f.readlines():
        a = re.findall(p, l)
        if a != []:
            break
    if a == []:
        print "Unreadable data for C_%i.E_%i_%i" % (Ncandidats, Nelecteurs, test)
    return a[0]
Exemplo n.º 4
0
def readData(Ncandidats, Nelecteurs, test, root="data", relog=False):
    folder = mj.getFolderName(Ncandidats, Nelecteurs, test)
    fname = folder + "log.txt"
    if not os.path.isfile(fname + "log.txt") or relog:
        mj.computeLog(Ncandidats, Nelecteurs, test, root)

    f = open(fname, "r")
    p = re.compile(ur'5 premiers: ([0-9]+),')
    a = []
    for l in f.readlines():
        a = re.findall(p, l)
        if a != []:
            break
    if a == []:
        print "Unreadable data for C_%i.E_%i_%i" % (Ncandidats, Nelecteurs,
                                                    test)
    return a[0]