-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
135 lines (116 loc) · 5.11 KB
/
plots.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from scipy import io
import numpy as np
from scipy import sparse
import os
from matplotlib import pyplot as plt
# this python script creates plots (and store them as .pdfs).
# you need to give manually.
# Input parameters
########################################################################################
# name: the string
# returned in ComputeAndStore() function
# s_max: the exponent (10 base)
# of the largest singular value
# s_min: the exponent (10 base)
# of the smallest singular value
# n: The nummber of the singular values.
# prec: A string that describes
# the precision for which you want
# separate plot. Accepted values,
# "single" and "half".
########################################################################################
# Output
########################################################################################
# Two pdf files, one that shows the
# computed singular values for each case,
# and one for the separate plot.
# Those plots are being stores into the /figures folder.
########################################################################################
def print_sigmas(name,s_max,s_min,n,prec):
#os.chdir("data")
M = io.mmread("data\M_"+name+".mtx")
M = sparse.coo_matrix.toarray(M)
x = np.arange(n)+1
if not os.path.isdir('figures/'):
os.mkdir('figures/')
os.chdir("figures")
# print for all the precisions
fig2, ax = plt.subplots(1,3)
fig2.tight_layout()
s = np.arange(s_min,s_max,step=2)
plt.setp(ax, yticks = np.power(np.ones(np.size(s))*10,s))
plt.yticks(np.power(np.ones(np.size(s))*10,s))
plt.sca(ax[0])
plt.yticks(np.power(np.ones(np.size(s))*10,s))
ax[0].set_yscale('log')
ax[0].grid(True)
ax[0].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b', marker = 's',
label = 'Double')
ax[0].scatter(x,M[:,0], facecolors = 'none', s = 60, edgecolors = 'm', marker = 'v',
label = 'Exact')
ax[0].legend(loc="lower left")
ax[1].grid(True)
ax[1].set_yscale('log')
ax[1].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',marker="s",
label = 'Double')
ax[1].scatter(x,M[:,2], facecolors = 'none', s = 60, edgecolors = 'tab:orange',
marker="*",label = 'Single')
ax[1].legend(loc="lower left")
ax[2].grid(True)
ax[2].set_yscale('log')
ax[2].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',marker="s",
label = 'Double')
ax[2].scatter(x,M[:,3], facecolors = 'none', s = 60, edgecolors = 'g',marker="o",
label = 'Half')
ax[2].legend(loc="lower left")
#plt.savefig("figures\"+name+".pdf")
plt.savefig(name+'_.pdf')
if prec == "single":
fig2, ax = plt.subplots(1,2)
fig2.tight_layout()
s = np.arange(s_min,s_max,step=2)
plt.setp(ax, yticks = np.power(np.ones(np.size(s))*10,s))
plt.yticks(np.power(np.ones(np.size(s))*10,s))
plt.sca(ax[0])
plt.yticks(np.power(np.ones(np.size(s))*10,s))
ax[0].set_yscale('log')
ax[0].grid(True)
ax[0].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',
marker = 's',label = 'Double')
ax[0].scatter(x,M[:,0], facecolors = 'none', s = 60, edgecolors = 'm',
marker = 'v',label = 'Exact')
ax[0].legend(loc="lower left")
ax[1].grid(True)
ax[1].set_yscale('log')
ax[1].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',
marker="s",label = 'Double')
ax[1].scatter(x,M[:,2], facecolors = 'none', s = 60, edgecolors = 'tab:orange',
marker="*",label = 'Single')
ax[1].legend(loc="lower left")
plt.savefig(name+'_single.pdf')
if prec == "half":
fig2, ax = plt.subplots(1,2)
fig2.tight_layout()
s = np.arange(-6,2,step=2)
plt.setp(ax, yticks = np.power(np.ones(np.size(s))*10,s))
plt.yticks(np.power(np.ones(np.size(s))*10,s))
plt.sca(ax[0])
plt.yticks(np.power(np.ones(np.size(s))*10,s))
ax[0].set_yscale('log')
ax[0].grid(True)
ax[0].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',
marker = 's', label = 'Double')
ax[0].scatter(x,M[:,0], facecolors = 'none', s = 60, edgecolors = 'm',
marker = 'v', label = 'Exact')
ax[0].legend(loc="lower left")
ax[1].grid(True)
ax[1].set_yscale('log')
ax[1].scatter(x,M[:,1], facecolors = 'none', s = 60, edgecolors = 'b',
marker="s",label = 'Double')
ax[1].scatter(x,M[:,3], facecolors = 'none', s = 60, edgecolors = 'g',
marker="*",label = 'Half')
ax[1].legend(loc="lower left")
plt.savefig(name+'_half.pdf')
os.chdir("../")
# you need to manually tune this parameter
print_sigmas("2_228_28_2_2_2_2_-4",2,-4,256,"half")