diff --git a/Random/__pycache__/graph.cpython-311.pyc b/Random/__pycache__/graph.cpython-311.pyc index 2aa0b3cb28e4111dd0991d20891f1d59472dc43b..c7675dbef627265d7065aaa70c3b625f417f1540 100644 Binary files a/Random/__pycache__/graph.cpython-311.pyc and b/Random/__pycache__/graph.cpython-311.pyc differ diff --git a/Random/graph.py b/Random/graph.py index 38f1c6a90cc6024816e50531c3ec190e4fa06771..037ab66c532e2d64961e33d9ecfd9f2acd0a72cc 100644 --- a/Random/graph.py +++ b/Random/graph.py @@ -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") diff --git a/Random/main.py b/Random/main.py index f10ead00d177568e27651478dd085c3ab074beb1..f6ba337fbf93a59ac111507d08d56849d8cd0dfc 100755 --- a/Random/main.py +++ b/Random/main.py @@ -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) + """