| 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 |
|
|---|
| 8 | def 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 |
|
|---|
| 25 | p_col_222,c_col_222 = my_read_paramlog_file("paramlog_collapse_222_ngen200_ngcol100_3.py")
|
|---|
| 26 | p_col_333,c_col_333 = my_read_paramlog_file("paramlog_collapse_333_ngen200_ngcol100_4.py")
|
|---|
| 27 | p_col_555,c_col_555 = my_read_paramlog_file("paramlog_collapse_555_ngen200_ngcol100_2.py")
|
|---|
| 28 |
|
|---|
| 29 | p_222,c_222 = my_read_paramlog_file("paramlog_COG_222_ngen200_5.py")
|
|---|
| 30 | p_333,c_333 = my_read_paramlog_file("paramlog_COG_333_ngen200_3.py")
|
|---|
| 31 | p_555,c_555 = my_read_paramlog_file("paramlog_COG_555_ngen200_2.py")
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | '''print len(cost_hist)
|
|---|
| 35 | print len(cost_hist2)'''
|
|---|
| 36 |
|
|---|
| 37 | import numpy as np
|
|---|
| 38 | import matplotlib.pyplot as plt
|
|---|
| 39 | from math import log10
|
|---|
| 40 |
|
|---|
| 41 | x_col_222 = np.arange(0, len(c_col_222), 1)
|
|---|
| 42 | y_col_222 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_222]
|
|---|
| 43 |
|
|---|
| 44 | x_col_333 = np.arange(0, len(c_col_333), 1)
|
|---|
| 45 | y_col_333 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_333]
|
|---|
| 46 |
|
|---|
| 47 | x_col_555 = np.arange(0, len(c_col_555), 1)
|
|---|
| 48 | y_col_555 = [log10(abs(-1*ele-0.378970568266)) for ele in c_col_555]
|
|---|
| 49 |
|
|---|
| 50 | x_222 = np.arange(0, len(c_222), 1)
|
|---|
| 51 | y_222= [log10(abs(-1*ele-0.378970568266)) for ele in c_222]
|
|---|
| 52 |
|
|---|
| 53 | x_333 = np.arange(0, len(c_333), 1)
|
|---|
| 54 | y_333= [log10(abs(-1*ele-0.378970568266)) for ele in c_333]
|
|---|
| 55 |
|
|---|
| 56 | x_555 = np.arange(0, len(c_555), 1)
|
|---|
| 57 | y_555 = [log10(abs(-1*ele-0.378970568266)) for ele in c_555]
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | plt.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
|
|---|
| 66 | plt.axvline(x=101, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 67 | plt.axvline(x=147, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 68 | plt.axvline(x=370, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 69 | plt.axvline(x=488, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 70 | plt.axvline(x=674, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 71 | plt.axvline(x=1132, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 72 | plt.axvline(x=1311, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 73 | plt.axvline(x=2488, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 74 |
|
|---|
| 75 | #npts 333, 2
|
|---|
| 76 | plt.axvline(x=145, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 77 | plt.axvline(x=530, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 78 | plt.axvline(x=785, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | #npts 222, 3
|
|---|
| 82 | plt.axvline(x=260, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 83 | plt.axvline(x=510, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 84 |
|
|---|
| 85 | #npts 222, 1
|
|---|
| 86 | plt.axvline(x=255, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 87 | plt.axvline(x=600, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 88 |
|
|---|
| 89 | #npts 222, 2
|
|---|
| 90 | plt.axvline(x=220, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 91 |
|
|---|
| 92 | #npts 333, 4
|
|---|
| 93 | plt.axvline(x=120, ymin=-10, ymax=1, hold = None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 94 | plt.axvline(x=125, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 95 | plt.axvline(x=270, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 96 | plt.axvline(x=490, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 97 | plt.axvline(x=740, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 98 |
|
|---|
| 99 | # npts 333, 5
|
|---|
| 100 | plt.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')
|
|---|
| 102 | plt.axvline(x=388, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 103 | plt.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')
|
|---|
| 105 | plt.axvline(x=717, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')
|
|---|
| 106 | plt.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')
|
|---|
| 108 | plt.axvline(x=1238, ymin=-10, ymax=1, hold=None, linestyle = '--', linewidth=1, color='r')'''
|
|---|
| 109 |
|
|---|
| 110 | plt.legend(('COG & CLPS, 222', 'COG & CLPS, 333', 'COG & CLPS, 555', 'COG, 222', \
|
|---|
| 111 | 'COG, 333', 'COG, 555'), 'lower right', shadow=True, fancybox=True)
|
|---|
| 112 |
|
|---|
| 113 | plt.title('Semilog Plot for Convergence Rate')
|
|---|
| 114 | plt.xlabel('iteration number, n')
|
|---|
| 115 | plt.ylabel('$log-error,\; log_{10}(\hat{P} - \hat{P}_{max})$')
|
|---|
| 116 | plt.grid(True)
|
|---|
| 117 | plt.show()
|
|---|