diff options
Diffstat (limited to 'hw4/plot.py')
| -rw-r--r-- | hw4/plot.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/hw4/plot.py b/hw4/plot.py new file mode 100644 index 0000000..0ed704a --- /dev/null +++ b/hw4/plot.py @@ -0,0 +1,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() |
