-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind_function.py
More file actions
205 lines (180 loc) · 5.68 KB
/
Find_function.py
File metadata and controls
205 lines (180 loc) · 5.68 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import numpy
import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.colors as mc
import matplotlib.mlab as mlab
from matplotlib.ticker import NullFormatter
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
import matplotlib.path as mpath
import matplotlib.lines as mlines
from pylab import *
from numpy import array
from configobj import ConfigObj
from subprocess import call
import os
# As first thing, I have to manually set the interval for the p, pmax , wich model I am using and how many lines I have in each file
MODELUSED = "Random Splitting"
MODELUSED1= "random_splitting"
NUMLINES=151 # The script will run way faster in this way. An alternative would be to create a matrix by adding line by line using the append method
# Now let's compute how many files I have and create the matrix
#dummy = PMAX/PInterval
#NUMFILES = int (math.floor(dummy)+1)
NUMFILES = 29
NUMROWS = NUMFILES*NUMLINES
A = numpy.zeros(shape=(NUMROWS,5)) # This is creating a matrix with NUMROWS rows and 5 columns. The columns will be s,p,<x>, <T> and the checkvalue
Dx= numpy.zeros(shape=(4,NUMFILES)) #This creates a matrix with p as first row and s as second row, and x as third row,the 4th row is the value of s such that x=0.5 (is the one computed with the linear interpolation). This is the matrix with the first value of s such that x<=0.5
xtoprint=range(NUMFILES-1)
ytoprint=range(NUMFILES-1)
#********************************Let's define the function I am going to use to to check for which value of s I have exactly 0.5
def computeexactx(matrix):
#print " "
dum1=numpy.where(matrix[1]<=0.5)
dum2=numpy.where(matrix[1]>=0.5)
DUM1=numpy.amin(dum1)
DUM2=numpy.amax(dum2)
s1=matrix[0][DUM1]
s2=matrix[0][DUM2]
x1=matrix[1][DUM1]
x2=matrix[1][DUM2]
mdummy=(s2-s1)/(x2-x1)
s0dummy=(s1*x2-s2*x1)/(x2-x1)
s0five=mdummy*0.5+s0dummy
#print s0five, s1, s2, x1, x2, DUM1, dum1[0][0]
return s0five
#**************** NOW LET'S FILL THE MATRIX ***************************
# Here I will basically just attach the files one after the other adding as second column the value of p!
l=0
for i in range(NUMFILES):
if i==0:
p=0
if (i>0 and i<=10):
p=i*0.01
if (i>10 and i<19):
p=(i-9)*0.1
if i>=19:
p=i-18
nameoffile= "p+%s" % p
b=numpy.loadtxt(nameoffile)
dummy1=b.transpose() # In this line and in the next for I look for the first value of s such that x is smaller equal than 0.52 (I chose 0.52 because in this way I'm getting values for x that are closer to 0.5)
dummy2=numpy.where(dummy1[1]<=0.52)
dummy3=computeexactx(dummy1)
Dx[0][i]=p
Dx[1][i]=dummy1[0][dummy2[0][0]]
Dx[2][i]=dummy1[1][dummy2[0][0]]
Dx[3][i]=dummy3
#Dx[3][0]=0.5 #Here I manually correct for p=0,s=0
#**************************************************************Let's plot it ************************************
scatter(Dx[1],Dx[0],c=Dx[2],cmap=cm.jet)
plt.colorbar()
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_normal"+".png",dpi=200)
exponent1=0.9305
a1=exp(-1.4026)
exponent2=4.3559
a2=exp(4.8443)
x1=arange(0,0.15,0.01)
x2=arange(0.15,0.56,0.01)
y1=a1*(x1**exponent1)
y2=a2*(x2**exponent2)
plot(x1,y1)
plot(x2,y2)
#plt.show()
close()
#Let's make a log plot instead:
yscale('log')
scatter(Dx[1],Dx[0],c=Dx[2],cmap=cm.jet)
plt.colorbar()
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_log"+".png",dpi=200)
#plt.show()
close()
#Let's make a log log plot
yscale('log')
xscale('log')
scatter(Dx[1],Dx[0],c=Dx[2],cmap=cm.jet)
plt.colorbar()
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_log_log"+".png",dpi=200)
#plt.show()
close()
#*******************************************************************************************
#**********************NOW LET'S PLOT THE ONE WITH THE INTERPOLATED DATA************************
scatter(Dx[3],Dx[0])
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_normal_interpolated"+".png",dpi=200)
exponent1=0.9305
a1=exp(-1.4026)
exponent2=4.3559
a2=exp(4.8443)
x1=arange(0,0.15,0.01)
x2=arange(0.15,0.56,0.01)
y1=a1*(x1**exponent1)
y2=a2*(x2**exponent2)
plot(x1,y1)
plot(x2,y2)
#plt.show()
close()
#Let's make a log plot instead:
yscale('log')
scatter(Dx[3],Dx[0])
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_log_interpolated"+".png",dpi=200)
close()
#Let's make a log log plot
yscale('log')
xscale('log')
scatter(Dx[3],Dx[0])
title("Transition line for the random splitting model")
xlabel("s",fontsize=12)
ylabel("p",fontsize=12)
plt.savefig("transition_line_log_log_interpolated"+".png",dpi=200)
exponent1=0.9305
a1=exp(-1.4026)
exponent2=4.3559
a2=exp(4.8443)
x1=arange(0,0.15,0.01)
x2=arange(0.15,0.56,0.01)
y1=a1*(x1**exponent1)
y2=a2*(x2**exponent2)
plot(x1,y1)
plot(x2,y2)
#plt.show()
close()
#***************Now let's save the one for the thesis!*****************************
axes([0,0,1,1])
figure(num=None, figsize=(12, 9), dpi=160, facecolor='w', edgecolor='k')
title("Transition line for the random splitting model",fontsize=20)
scatter(Dx[3],Dx[0])
xlabel("s",fontsize=20)
ylabel("p",fontsize=20)
exponent1=0.9305
a1=exp(-1.4026)
exponent2=4.3559
a2=exp(4.8443)
x1=arange(0,0.15,0.01)
x2=arange(0.15,0.56,0.01)
y1=a1*(x1**exponent1)
y2=a2*(x2**exponent2)
plot(x1,y1)
plot(x2,y2)
axes([0.2,0.43,0.42,0.42])
yscale('log')
xscale('log')
scatter(Dx[3],Dx[0])
plt.tight_layout()
plt.savefig("Double_pic"+".png",dpi=200)
close()
#*************Now let's prepare the data for printing**********************
# I want to print them in log-log scale
for i in range(1,NUMFILES): #I don't print the 0,0 value because in log log scale is going to be -infinity
xtoprint[i-1]=log(Dx[3][i])
ytoprint[i-1]=log(Dx[0][i])
print xtoprint
print ytoprint