Rectify swp2 plot
parent
bbc06411e9
commit
f79d48bf5b
26
swp2.py
26
swp2.py
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
|
||||
|
|
@ -29,17 +28,17 @@ def return_x_y_from_stwp_theta_file(stwp_theta_file, breaks, mu, tgen):
|
|||
if dim < breaks+1:
|
||||
return 0,0,0
|
||||
# get n, the last bin of the last group
|
||||
#n = int(groups[-1].split(",")[-1])
|
||||
# revert the list of groups as the most recent times correspond
|
||||
# to the closest and last leafs of the coal. tree.
|
||||
groups = groups[::-1]
|
||||
theta_site = theta_site[::-1]
|
||||
# initiate the dict of times
|
||||
t = {}
|
||||
# list of thetas
|
||||
theta_L = []
|
||||
sum_t = 0
|
||||
for group_nb, group in enumerate(groups):
|
||||
print(group_nb, group, theta_site[group_nb], len(theta_site))
|
||||
###print(group_nb, group, theta_site[group_nb], len(theta_site))
|
||||
# store all the thetas one by one, with one theta per group
|
||||
theta_L.append(float(theta_site[group_nb]))
|
||||
# if the group is of size 1
|
||||
|
|
@ -51,37 +50,29 @@ def return_x_y_from_stwp_theta_file(stwp_theta_file, breaks, mu, tgen):
|
|||
i = int(group.split(",")[0])
|
||||
j = int(group.split(",")[-1])
|
||||
t[i] = 0
|
||||
#t =
|
||||
if len(group.split(',')) == 1:
|
||||
k = i
|
||||
t[i] += ((theta_L[group_nb] ) / (k*(k-1)) * tgen) / mu
|
||||
else:
|
||||
for k in range(i, j+1):
|
||||
for k in range(j, i-1, -1 ):
|
||||
t[i] += ((theta_L[group_nb] ) / (k*(k-1)) * tgen) / mu
|
||||
# we add the cumulative times at the end
|
||||
t[i] += sum_t
|
||||
sum_t = t[i]
|
||||
# build the y axis (sizes)
|
||||
y = []
|
||||
#theta_L.sort(reverse=True)
|
||||
for theta in theta_L:
|
||||
# with size N = theta/4mu
|
||||
size = theta / (4*mu)
|
||||
y.append(size)
|
||||
y.append(size)
|
||||
|
||||
# build the time x axis
|
||||
x = [0]
|
||||
# need to fix: t.values are sorted? and in reverse order because the groups and the times are sorted in opposite order
|
||||
for time in range(0, len(t.values())-1):
|
||||
x.append(list(t.values())[time])
|
||||
x.append(list(t.values())[time])
|
||||
x.append(list(t.values())[len(t.values())-1])
|
||||
|
||||
#x = x[::-1]
|
||||
#y = y[::-1]
|
||||
#x.sort(reverse=True)
|
||||
#y.sort(reverse=True)
|
||||
|
||||
return x,y,likelihood
|
||||
|
||||
def plot_3epochs_thetafolder(folder_path, mu, tgen, breaks = 2, title = "Title"):
|
||||
|
|
@ -100,7 +91,7 @@ def plot_3epochs_thetafolder(folder_path, mu, tgen, breaks = 2, title = "Title")
|
|||
cpt +=1
|
||||
scenari[likelihood] = x,y
|
||||
print("\n*******\n"+title+"\n--------\n"+"mu="+str(mu)+"\ntgen="+str(tgen)+"\nbreaks="+str(breaks)+"\n*******\n")
|
||||
print(cpt, "theta files have been scanned.")
|
||||
print(cpt, "theta file(s) have been scanned.")
|
||||
# sort starting by the smallest -log(Likelihood)
|
||||
best10_scenari = (sorted(list(scenari.keys())))[:10]
|
||||
print("10 greatest Likelihoods", best10_scenari)
|
||||
|
|
@ -109,9 +100,13 @@ def plot_3epochs_thetafolder(folder_path, mu, tgen, breaks = 2, title = "Title")
|
|||
my_dpi = 300
|
||||
plt.figure(figsize=(5000/my_dpi, 2800/my_dpi), dpi=my_dpi)
|
||||
plt.plot(x, y, 'r-', lw=2, label = 'Lik='+greatest_likelihood)
|
||||
plt.yscale('log')
|
||||
#plt.xscale('log')
|
||||
plt.grid(True,which="both", linestyle='--')
|
||||
|
||||
for scenario in best10_scenari[1:]:
|
||||
x,y = scenari[scenario]
|
||||
print("\n---- Lik:",scenario,"\n\nt=", x,"\n\nN=",y, "\n\n")
|
||||
#print("\n---- Lik:",scenario,"\n\nt=", x,"\n\nN=",y, "\n\n")
|
||||
plt.plot(x, y, '--', lw=1, label = 'Lik='+scenario)
|
||||
plt.ylabel("Individuals (N)")
|
||||
plt.xlabel("Time (years)")
|
||||
|
|
@ -119,7 +114,6 @@ def plot_3epochs_thetafolder(folder_path, mu, tgen, breaks = 2, title = "Title")
|
|||
plt.title(title)
|
||||
#plt.gcf().set_size(1000, 500)
|
||||
plt.savefig(title+'_b'+str(breaks)+'.pdf')
|
||||
#plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue