Esempio n. 1
0
def test_perplexity(res_file, playlist_test_file, tag_test_file):
    res = analyze.loadresult(res_file, [-1])[0]
    playlists, tags = train_hte.loaddata(playlist_test_file, tag_test_file)

    Pi = res[0]
    Gt = res[1]
    Tt = res[2]
    A = res[3]

    predictor = predict.NeitherPredictor(Pi, A, Gt, Tt)
    print predictor.calc_perplexity(playlists, tags)
Esempio n. 2
0
def test_tag_accuracy(res_file, tag_test_file, n):
    res = analyze.loadresult(res_file, [-1])[0]
    tag_true = train_hte.loaddata(None, tag_test_file)[1]

    Pi = res[0]
    Gt = res[1]
    Tt = res[2]
    A = res[3]

    predictor = predict.Predictor(Pi, A, Gt, Tt)
    tag_est = predictor.predict_tag(n)
   
    return test_tag_acc(tag_est, tag_true)
Esempio n. 3
0
def report_all(res_dir, playlist_test_file, tag_test_file):
    files = os.listdir(res_dir)
    files = [path.join(res_dir,f) for f in files if f.startswith('res')
             and path.isfile(path.join(res_dir,f))]
    playlists, tags = train_hte.loaddata(playlist_test_file, tag_test_file)
    b = np.zeros((tags.shape[0], 250))
    b[:,:tags.shape[1]] = tags
    tags = b

    stat = {}
    for f in files:
        print f
        ss = f.split('-')
        lam = float([k[1:] for k in ss if k.startswith('L')][0])
        sc = float([k[2:] for k in ss if k.startswith('sc')][0])
        ss = int([k[2:] for k in ss if k.startswith('ss')][0])

        res = analyze.loadresult(f, [-1])[0]
        Pi = res[0]
        Gt = res[1]
        Tt = res[2]
        A = res[3]

        predictor = predict.NeitherPredictor(Pi, A, Gt, Tt)
        r = predictor.calc_perplexity(playlists, tags)
        #r = (predictor.calc_hmm_perplexity(playlists),
        #        predictor.calc_lda_perplexity(tags))
        print r, r[0]+lam*r[1]

        if (lam,sc,ss) in stat:
            stat[(lam,sc,ss)].append(r)
        else:
            stat[(lam,sc,ss)] = [r]
    report = [] 
    for k in stat:
        ph = [x[0] for x in stat[k]]
        pl = [x[1] for x in stat[k]]
        report.append([k[0],k[1],k[2],np.mean(ph),np.std(ph),np.mean(pl),np.std(pl)])
    report = np.array(report)
    from scipy import io as sio
    sio.savemat('report.mat', {'report':report})
    return report