Esempio n. 1
0
    print model2.veto_weights
    # Display learned model parameters
    print('Learned model')
    print('=============')
    model2.bpt.display(criterion_ids=cids)
    model2.cv.display(criterion_ids=cids)
    print("lambda: %.7s" % model2.lbda)

    # Compute assignment with the learned model
    aa2 = model2.pessimist(pt)

    # Compute CA
    total = len(a)
    nok = 0
    anok = []
    for alt in a:
        if aa(alt.id) != aa2(alt.id):
            anok.append(alt)
            nok += 1

    print("Good assignments: %3g %%" % (float(total - nok) / total * 100))
    print("Bad assignments : %3g %%" % (float(nok) / total * 100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok.keys(), model.criteria.keys(), [aa, aa2],
                                 pt)

    # Display models
    display_electre_tri_models([model, model2], [worst, worst], [best, best])
Esempio n. 2
0
    cvs.display()
    print('Criteria functions:')
    cfs.display()
    print('Categories values:')
    catv.display()

    u2 = AVFSort(c, cvs, cfs, catv)
    aa2 = u2.get_assignments(pt)

    total = len(a)
    nok = nok_erroned = 0
    anok = []
    for alt in a:
        if aa(alt.id) != aa2(alt.id):
            anok.append(alt)
            nok += 1
            if alt.id in aa_erroned:
                nok_erroned += 1

    print("Good assignments          : %3g %%" \
          % ((total - nok) / total *100))
    print("Bad assignments           : %3g %%" \
          % ((nok) / total *100))
    if aa_erroned:
        print("Bad in erroned assignments: %3g %%" \
              % (nok_erroned / total * 100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok.keys(), c.keys(), [aa, aa2], pt)
Esempio n. 3
0
            anok.append(alt.id)
            nok += 1
            if alt.id in aa_erroned:
                nok_erroned += 1

    print("Good assignments          : %3g %%" \
          % (float(total-nok)/total*100))
    print("Bad assignments           : %3g %%" \
          % (float(nok)/total*100))
    if aa_erroned:
        print("Bad in erroned assignments: %3g %%" \
              % (float(nok_erroned)/total*100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok, model.criteria.keys(),
                                 [aa, aa_learned], pt)

    win1, loose1 = compute_winning_and_loosing_coalitions(model.cv,
                                                          model.lbda)
    win2, loose2 = compute_winning_and_loosing_coalitions(model2.cv,
                                                          model2.lbda)
    coali = list(set(win1) & set(win2))
    coal1e = list(set(win1) ^ set(coali))
    coal2e = list(set(win2) ^ set(coali))

    print("Number of coalitions original: %d"
          % len(win1))
    print("Number of coalitions learned: %d"
          % len(win2))
    print("Number of common coalitions: %d"
          % len(coali))
    print("lambda: %s" % model.lbda)
    result['obj_weights'] = obj

    mip = MipMRSortMobius(model, pt, aa)
    obj = mip.solve()
    aa3 = model.pessimist(pt)
    aa3.id = 'aa_capa'
    print("MipMRSortMobius:  Objective: %d (/%d)" % (obj, len(aa)))
    anok = [a.id for a in aa if a.category_id != aa3[a.id].category_id]
    print("Alternative not restored: %s" % ','.join("%s" % a for a in anok))
    print(model.cv)
    print("lambda: %s" % model.lbda)
    result['obj_capa'] = obj

    a = Alternatives([Alternative(a.id) for a in aa])
    print_pt_and_assignments(a.keys(), criteria.keys(), [aa, aa2, aa3], pt)

    results.append(result)

results.sort(key = lambda x: x['vector'])
results.sort(key = lambda x: len(x['vector']))

maxlen = max([len(', '.join("%s" % f for f in result['fmins']))
                                     for result in results])
print("\n%*s obj_weights obj_capa" % (maxlen, "Fmin"))
for result in results:
    print("%*s %*s %*s" % (maxlen, ', '.join("%s" % f
                                   for f in sorted(result['fmins'], key = len)),
                           len('obj_weights'), result['obj_weights'],
                           len('obj_capa'), result['obj_capa']))
Esempio n. 5
0
            anok.append(alt.id)
            nok += 1
            if alt.id in aa_erroned:
                nok_erroned += 1

    print("Good assignments          : %3g %%" \
          % (float(total-nok)/total*100))
    print("Bad assignments           : %3g %%" \
          % (float(nok)/total*100))
    if aa_erroned:
        print("Bad in erroned assignments: %3g %%" \
              % (float(nok_erroned)/total*100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok, model.criteria.keys(), [aa, aa_learned],
                                 pt)

    win1, loose1 = compute_winning_and_loosing_coalitions(model.cv, model.lbda)
    win2, loose2 = compute_winning_and_loosing_coalitions(
        model2.cv, model2.lbda)
    coali = list(set(win1) & set(win2))
    coal1e = list(set(win1) ^ set(coali))
    coal2e = list(set(win2) ^ set(coali))

    print("Number of coalitions original: %d" % len(win1))
    print("Number of coalitions learned: %d" % len(win2))
    print("Number of common coalitions: %d" % len(coali))
    print("Coalitions in original and not in learned: %s" %
          '; '.join(map(str, coal1e)))
    print("Coalitions in learned and not in original: %s" %
          '; '.join(map(str, coal2e)))
Esempio n. 6
0
    cvs.display()
    print('Criteria functions:')
    cfs.display()
    print('Categories values:')
    catv.display()

    u2 = AVFSort(c, cvs, cfs, catv)
    aa2 = u2.get_assignments(pt)

    total = len(a)
    nok = nok_erroned = 0
    anok = []
    for alt in a:
        if aa(alt.id) != aa2(alt.id):
            anok.append(alt)
            nok += 1
            if alt.id in aa_erroned:
                nok_erroned += 1

    print("Good assignments          : %3g %%" \
          % ((total - nok) / total *100))
    print("Bad assignments           : %3g %%" \
          % ((nok) / total *100))
    if aa_erroned:
        print("Bad in erroned assignments: %3g %%" \
              % (nok_erroned / total * 100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok.keys(), c.keys(), [aa, aa2], pt)
Esempio n. 7
0
                       alternative_ids = model2.profiles)
    model2.cv.display(criterion_ids=cids)
    print("lambda: %.7s" % model2.lbda)

    aa2 = model2.pessimist(pt)
    total = len(a)
    nok = nok_erroned = 0
    anok = []
    for alt in a:
        if aa(alt.id) != aa2(alt.id):
            anok.append(alt)
            nok += 1
            if alt.id in aa_erroned:
                nok_erroned += 1

    print("Good assignments          : %3g %%" \
          % (float(total-nok)/total*100))
    print("Bad assignments           : %3g %%" \
          % (float(nok)/total*100))
    if aa_erroned:
        print("Bad in erroned assignments: %3g %%" \
              % (float(nok_erroned)/total*100))

    if len(anok) > 0:
        print("Alternatives wrongly assigned:")
        print_pt_and_assignments(anok.keys(), model.criteria.keys(),
                                 [aa, aa2], pt)

    display_electre_tri_models([model, model2],
                               [worst, worst], [best, best])
    if pt_test is not None:
        aa_test_m2 = m2.pessimist(pt_test)
elif root.find("AVFSort[@id='learned']") is not None:
    m2 = AVFSort().from_xmcda(root, 'learned')
    if pt_learning is not None:
        aa_learning_m2 = m2.get_assignments(pt_learning)
        aids = []
        from pymcda.utils import print_pt_and_assignments
        for aid in aa_learning_m2.keys():
            if aa_learning_m2[aid].category_id != aa_learning_m1[aid].category_id:
                aids.append(aid)
            else:
                aids.append(aid)

        au = m2.global_utilities(pt_learning)
        print_pt_and_assignments(aids, None, [aa_learning_m1, aa_learning_m2], pt_learning, au)
#        for i in range(1, len(pt_learning) + 1):
#            aid = "a%d" % i
#            uti = m2.global_utility(pt_learning["a%d" % i])
#            if aa_learning_m2[aid].category_id != aa_learning_m1[aid].category_id:
#                print("%s %g %s %s" % (aid, uti.value, aa_learning_m2[aid].category_id, aa_learning_m1[aid].category_id))
#        print_pt_and_assignments(anok, c, [aa_learning_m1, aa_learning_m2], pt_learning)
    if pt_test is not None:
        aa_test_m2 = m2.get_assignments(pt_test)

def compute_auc_histo(aa):
    pass

if aa_learning_m1 is not None:
    ca_learning = compute_ca(aa_learning_m1, aa_learning_m2)
    auc_learning = m2.auc(aa_learning_m1, pt_learning)
Esempio n. 9
0
save_to_xmcda("%s/%s-all-%s-%s.bz2" % (DATADIR, algo, data.name, dt), data.aa,
              data.pt, model)

aa2 = model.get_assignments(data.pt)

ca = compute_ca(data.aa, aa2)
auc = model.auc(data.aa, data.pt)

anok = []
for a in data.a:
    if data.aa[a.id].category_id != aa2[a.id].category_id:
        anok.append(a)

if len(anok) > 0:
    print("Alternatives wrongly assigned:")
    print_pt_and_assignments(anok.keys(), data.c.keys(), [data.aa, aa2],
                             data.pt)

print("Model parameters:")
cids = model.criteria.keys()
if model_type == 'mrsort':
    print(model.bpt)
    print(model.cv)
    print("lambda: %.7s" % model.lbda)

    print("Weights and lambda optimization:")
    if algo == 'meta_mrsort':
        lp = LpMRSortPostWeights(model.cv, model.lbda)
        obj, model.cv, model.lbda = lp.solve()
    print(model.cv)
    print(model.lbda)
Esempio n. 10
0
save_to_xmcda("%s/%s-all-%s-%s.bz2" % (DATADIR, algo, data.name, dt),
              data.aa, data.pt, model)

aa2 = model.get_assignments(data.pt)

ca = compute_ca(data.aa, aa2)
auc = model.auc(data.aa, data.pt)

anok = []
for a in data.a:
    if data.aa[a.id].category_id != aa2[a.id].category_id:
        anok.append(a)

if len(anok) > 0:
    print("Alternatives wrongly assigned:")
    print_pt_and_assignments(anok.keys(), data.c.keys(), [data.aa, aa2], data.pt)

print("Model parameters:")
cids = model.criteria.keys()
if model_type == 'mrsort':
    print(model.bpt)
    print(model.cv)
    print("lambda: %.7s" % model.lbda)

    print("Weights and lambda optimization:")
    if algo == 'meta_mrsort':
        lp = LpMRSortPostWeights(model.cv, model.lbda)
        obj, model.cv, model.lbda = lp.solve()
    print(model.cv)
    print(model.lbda)