Commits (2)
......@@ -33,7 +33,7 @@ if __name__=="__main__":
for i in range(the.nb_run):
print("\rRun {}".format(i), end = '')
system("python3 snp.py -o run -no "+" ".join(arg[1]))
system("python3 snp.py -o run -no -s " + str(np.random.randint(0, 10*the.nb_run)) + " "+" ".join(arg[1]))
print("\r")
# Data extraction
......@@ -70,7 +70,7 @@ if __name__=="__main__":
for attempt in data:
good = False
for t,v in attempt.items():
if t < time and v > value:
if t <= time and v >= value:
good = True
break
if good:
......@@ -84,19 +84,33 @@ if __name__=="__main__":
with open('proba.json', 'w') as outfile:
json.dump(data, outfile)
elif the.for_value is not None:
temps = np.linspace(0,temps_max,100)
P = probability(data,temps,the.for_value)
plt.plot(temps,P)
P = probability(data,range(1,temps_max+1),the.for_value)
plt.bar(range(1,temps_max+1), P)
plt.title("ERT for target {}".format(the.for_value))
plt.xlabel('run')
plt.ylabel('probability')
plt.ylim(0,1)
plt.show()
else:
temps = np.linspace(0,temps_max,100)
values = np.linspace(0,value_max,100)
temps = range(0,temps_max+2)
values = range(0,int(value_max+2))
X, Y = np.meshgrid(temps, values)
Z = probability(data,X,Y)
print(Z)
"""
fig, ax = plt.subplots()
cs = ax.contourf(X, Y, Z, 20)
cbar = fig.colorbar(cs)
"""
proba = np.linspace(0.0, 1.0, 11)
cs = plt.contourf(X, Y, Z, levels=proba)
cbar = plt.colorbar(cs)
cbar.set_label('probability')
plt.xlabel('run')
plt.ylabel('target')
plt.show()
#remove('run.csv')
from os import system
import json
import numpy as np
import matplotlib.pyplot as plt
Nb_run = 3
solvers = [
'-m num_greedy -n 45 -i 5 -r 0.08 -t 10000 -w 100 -a 0.01',
'-m bit_greedy -n 45 -i 5 -r 0.08 -t 10000 -w 100 -a 0.01'
]
datas = []
for solver in solvers:
print("python3 draw_ert.py --nb-run " + str(Nb_run) + " --save-proba " + solver)
system("python3 draw_ert.py --nb-run " + str(Nb_run) + " --save-proba " + solver)
with open('proba.json') as json_file:
data = json.load(json_file)
datas.append(data)
temps_max = 0
value_max = 0
value_min = np.inf
for data in datas:
for run in data:
m = max([int(k) for k,v in run.items()])
if m > temps_max:
temps_max = m
m = max([v for k,v in run.items()])
if m > value_max:
value_max = m
m = min([v for k,v in run.items()])
if m < value_min:
value_min = m
def probability(data,time,value):
num = 0
for attempt in data:
good = False
for t,v in attempt.items():
if int(t) <= time and v >= value:
good = True
break
if good:
num += 1
return num/len(data)
probability = np.vectorize(probability, excluded=[0])
j = 1
for v in [8379,8380,8400]:
for i in range(len(solvers)):
plt.subplot(320+j)
P = probability(datas[i],range(1,temps_max+1),v)
plt.bar(range(1,temps_max+1), P)
plt.title("ERT for target {} and solver\n{}".format(v, solvers[i]))
plt.xlabel('run')
plt.ylabel('probability')
plt.ylim(0,1)
j += 1
plt.tight_layout()
plt.show()
......@@ -41,7 +41,7 @@ def probability(data,time,value):
for attempt in data:
good = False
for t,v in attempt.items():
if int(t) < time and v > value:
if int(t) <= time and v >= value:
good = True
break
if good:
......