source: branches/collapse/SEMILOG_PLOTS.py @ 855

Revision 855, 5.3 KB checked in by mmckerns, 5 months ago (diff)

updated copyright to 2016

Line 
1#!/usr/bin/env python
2#
3# Author: Lan Huong Nguyen (lanhuong @stanford)
4# Copyright (c) 2012-2016 California Institute of Technology.
5# License: 3-clause BSD.  The full license text is available at:
6#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE
7
8def my_read_paramlog_file(file):
9    from mystic.munge import read_support_file
10    steps, cost_hist  = read_support_file(file)
11   
12    params_hist = []
13   
14    generations =  len(steps[0][0])
15    nDim = len(steps[0])
16   
17    for n in range(generations):
18        c = []
19        for i in range(nDim):
20            c.append(steps[0][i][n])
21        params_hist.append(c)
22   
23    return params_hist, cost_hist
24
25p_col_222,c_col_222 = my_read_paramlog_file("paramlog_collapse_222_ngen200_ngcol100_3.py")
26p_col_333,c_col_333 = my_read_paramlog_file("paramlog_collapse_333_ngen200_ngcol100_4.py")
27p_col_555,c_col_555 = my_read_paramlog_file("paramlog_collapse_555_ngen200_ngcol100_2.py")
28
29p_222,c_222 = my_read_paramlog_file("paramlog_COG_222_ngen200_5.py")
30p_333,c_333 = my_read_paramlog_file("paramlog_COG_333_ngen200_3.py")
31p_555,c_555 = my_read_paramlog_file("paramlog_COG_555_ngen200_2.py")
32
33
34'''print len(cost_hist)
35print len(cost_hist2)'''
36
37import numpy as np
38import matplotlib.pyplot as plt
39from math import log10
40
41x_col_222 = np.arange(0, len(c_col_222), 1)
42y_col_222 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_222]
43
44x_col_333 = np.arange(0, len(c_col_333), 1)
45y_col_333 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_333]
46
47x_col_555 = np.arange(0, len(c_col_555), 1)
48y_col_555 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_555]
49
50x_222 = np.arange(0, len(c_222), 1)
51y_222= [log10(abs(-1*ele-0.378970568266)) for ele in c_222]
52
53x_333 = np.arange(0, len(c_333), 1)
54y_333= [log10(abs(-1*ele-0.378970568266)) for ele in c_333]
55
56x_555 = np.arange(0, len(c_555), 1)
57y_555 = [log10(abs(-1*ele-0.378970568266)) for ele in c_555]
58
59
60plt.plot(x_col_222, y_col_222, 'b:', x_col_333, y_col_333, 'b--', x_col_555, \
61         y_col_555, 'b-', x_222, y_222, 'g:', x_333, y_333, 'g--', x_555, \
62         y_555, 'g-', linewidth = 2)
63
64'''
65#npts 555, 2
66plt.axvline(x=101, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
67plt.axvline(x=147, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
68plt.axvline(x=370, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
69plt.axvline(x=488, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
70plt.axvline(x=674, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
71plt.axvline(x=1132, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
72plt.axvline(x=1311, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
73plt.axvline(x=2488, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
74
75#npts 333, 2
76plt.axvline(x=145, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
77plt.axvline(x=530, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
78plt.axvline(x=785, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
79
80
81#npts 222, 3
82plt.axvline(x=260, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
83plt.axvline(x=510, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
84
85#npts 222, 1
86plt.axvline(x=255, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
87plt.axvline(x=600, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
88
89#npts 222, 2
90plt.axvline(x=220, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
91
92#npts 333, 4
93plt.axvline(x=120, ymin=-10, ymax=1, hold = None, linestyle = '--', linewidth=1, color='r')
94plt.axvline(x=125, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
95plt.axvline(x=270, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
96plt.axvline(x=490, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
97plt.axvline(x=740, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
98
99# npts 333, 5
100plt.axvline(x=139, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
101#plt.axvline(x=249, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
102plt.axvline(x=388, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
103plt.axvline(x=556, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
104#plt.axvline(x=629, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
105plt.axvline(x=717, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
106plt.axvline(x=824, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
107#plt.axvline(x=930, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
108plt.axvline(x=1238, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')'''
109
110plt.legend(('COG & CLPS, 222', 'COG & CLPS, 333', 'COG & CLPS, 555', 'COG, 222', \
111            'COG, 333', 'COG, 555'), 'lower right', shadow=True, fancybox=True)
112
113plt.title('Semilog Plot for Convergence Rate')
114plt.xlabel('iteration number, n')
115plt.ylabel('$log-error,\; log_{10}(\hat{P} - \hat{P}_{max})$')
116plt.grid(True)
117plt.show()
Note: See TracBrowser for help on using the repository browser.