Skip to content
Extraits de code Groupes Projets
Valider f3a01787 rédigé par Anzo's avatar Anzo
Parcourir les fichiers

updated with multiprocessing

parent 17ad0128
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Aucun aperçu pour ce type de fichier
......@@ -11,6 +11,7 @@ def hist_distributivity_graph(N,RESOLUTION,seed,data):
graphs histograms
see values function in main module
"""
plt.clf()
for name in data:
print("building "+str(name)+" histogram...")
xlabel= "Value"
......@@ -41,6 +42,33 @@ def ecdf_graph(N,RESOLUTION,seed,data):
graph.savefig(name+'_ecdf.png', bbox_inches='tight')
return
def compare_ecdf(N, RESOLUTION, seed, data):
"""
Create graphs superposing ecdf
"""
plt.clf()
BW = 0.337
name = "compare_ecdf_"
for e in data:
name += e+"_"
#subdata = {k : data[k] for k in names}
print("graphing "+str(name)+"...")
xlabel = "Value"
ylabel = "Density"
title_name="N = "+str(N)+"\n seed = "+str(seed)
if N == 0:
title_name = "seed = "+str(seed)
graph=sns.displot(data,legend=True
, kind="ecdf")
graph.set(title=title_name)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
#plt.legend()
plt.savefig(name+'.png', bbox_inches='tight')
return
def compare(N, RESOLUTION, seed, data):
"""
Create graphs superposing two, already generated,
......@@ -66,6 +94,33 @@ def compare(N, RESOLUTION, seed, data):
graph.set(title=title_name)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
graph.axes.set
plt.legend()
plt.savefig(name+'.png', bbox_inches='tight')
plt.savefig(name+'.png', bbox_inches='tight')
return
def lineplot_wrap(data, xlabel, ylabel, title, iterN):
plt.clf()
print("graphing "+str(title)+"...")
for e in data:
plt.plot(iterN, data[e], marker="o", label="seed="+str(e))
#graph = sns.lineplot(data, legend=True, x=iterN)
plt.title(title)
plt.legend()
plt.xscale('log')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(title.replace(" ", "_")+".png", bbox_inches="tight")
def lineplot_mean_alot(data, xlabel, ylabel, title, iterN):
plt.clf()
print("graphing "+str(title)+"...")
for e in data:
plt.plot(iterN, data[e], marker="o", alpha=0.05
, color="red")
plt.plot(iterN, [0.5]*len(iterN), color="blue",linestyle='dotted')
plt.title(title)
plt.xscale('log')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(title+".png", bbox_inches="tight")
......@@ -7,6 +7,7 @@ import stats
import scipy
import seaborn as sns
import csv
import multiprocessing
#shut up stupid warnings from not "the-most-up-to-date" libraries
import warnings
......@@ -72,7 +73,7 @@ def write_stats(data, name):
return
def write_stats_chi(data, name, RES):
fields=["chi","p"]
fields=["name","chi","p"]
val = stats.chisquared_uniform(data,RES)
chi = val[0]
p = val[1]
......@@ -86,16 +87,60 @@ def write_stats_chi(data, name, RES):
"p" : str(p)})
return
if __name__=="__main__":
##INIT PARAMS##
def mean_evolves(generator,number,iterN):
datas = {}
for i in range(number):
seed = int(datetime.now().timestamp()+i)
sub_data = iteratives(iterN, seed, generator)
res = []
for a in sub_data:
res.append(np.mean(sub_data[a]))
datas[str(seed)] = res
return datas
def pipeline(generator):
N = 1000000
RESOLUTION = 100
iterN = [100, 1000000, 100000000]
iterN = [100,10000,1000000,100000000]
iterNmean = [100, 1000, 10000, 100000, 1000000]
seed = int(datetime.now().timestamp())
name_ = type(generator).__name__
sns.set_theme(style="darkgrid")
data=values(N,seed,[generator])
#generate a lot of diagrams
graph.hist_distributivity_graph(N,RESOLUTION,seed,data)
for name in data:
write_stats(data[name],name)
write_stats_chi(data[name],name,RESOLUTION)
data_iter = iteratives(iterN, seed, generator)
graph.compare(0, RESOLUTION, seed, data_iter)
graph.compare(0, RESOLUTION, seed, data_iter)
data_alot = mean_evolves(generator, 500, iterNmean)
graph.lineplot_mean_alot(data_alot, "Size", "Mean"
, "Mean values evolution for "+name_, iterNmean)
if __name__=="__main__":
#init generators
generators = [ParkMiller(), KnuthLewis(), Marsaglia()
, LavauxJenssens(), Haynes(), MitchelMoore()
, MersenneTwister(), BlumBlumShub()]
for a in generators:
p = multiprocessing.Process(target=pipeline, args=[a])
p.start()
"""
##INIT PARAMS##
N = 1000000
RESOLUTION = 100
iterN = [100, 10000, 1000000, 100000000]
#init seed on timesystem
seed = int(datetime.now().timestamp())
......@@ -104,8 +149,16 @@ if __name__=="__main__":
sns.set_theme(style="darkgrid")
#generate N random values for each RNG
data = values(N,seed,generators)
#data = values(N,seed,generators)
#graph.compare_ecdf(0, RESOLUTION, seed
# , iteratives([100,1000,1000000], seed, ParkMiller()))
a = mean_evolves(ParkMiller(), 500, [100,1000])
graph.lineplot_mean_alot(a, "Size", "Mean"
, "Mean Value evolution for ParkMiller"
,[100,1000])
#generate a lot of diagrams
graph.hist_distributivity_graph(N,RESOLUTION,seed,data)
for name in data:
......@@ -116,3 +169,4 @@ if __name__=="__main__":
graph.ecdf_graph(0, RESOLUTION, seed, data_iter)
graph.compare(0, RESOLUTION, seed, data_iter)
"""
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter