summaryrefslogtreecommitdiffstats
path: root/hw4/plot.py
blob: 0ed704a7cbe100219cee70f2cfaa54a45fb34929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sbn

sbn.set_style("white")


def three():
    with open("gibbs_2.txt") as fh:
        values = [map(float, line.strip().split()) for line in fh]
        a, b, c = zip(*values)
        plt.figure(figsize=(8, 6))
        plt.plot(a, -np.array(b), label="train")
        plt.plot(a, -np.array(c), label="test")
        plt.legend(loc="lower right")
        plt.xlabel("Epoch")
        plt.ylabel("Likelihood")
        plt.savefig("2.pdf")


def four():
    plt.figure(figsize=(8, 6))
    for i in xrange(1, 11):
        with open("gibbs_" + str(i) + ".txt") as fh:
            values = [map(float, line.strip().split()) for line in fh]
            a, b, c = zip(*values)
            plt.plot(a, np.array(b), label="K=" + str(i))
    plt.legend(loc="upper right")
    plt.xlabel("Epoch")
    plt.ylabel("MSE")
    plt.axes().set_yscale("log")
    plt.savefig("train.pdf")

    plt.figure(figsize=(8, 6))
    for i in xrange(1, 11):
        with open("gibbs_" + str(i) + ".txt") as fh:
            values = [map(float, line.strip().split()) for line in fh]
            a, b, c = zip(*values)
            plt.plot(a, np.array(c), label="K=" + str(i))
    plt.legend(loc="upper right")
    plt.xlabel("Epoch")
    plt.ylabel("MSE")
    plt.axes().set_yscale("log")
    plt.savefig("test.pdf")
four()