Skip to content

Commit 92f00a6

Browse files
authored
Update website and generate data for most listed languages (#17)
* reword index and methodology * axis normalize website * detail results graph issues * add c output * add ocaml program and outputs * add dart program and outputs * add perl script and outputs * add php script and outputs * update swift script and add output * update scala script and add some outputs * update ruby script and add outputs * update c++ and outputs * fix elixir script and add outputs * fix elixir script and add some outputs * fix lisp script and add outputs * SF, todo outputs resource limits * update kotlin and rust script. add outputs * SF, remove old and add missing outputs * fix r script and add outputs * fix haskell script and add outputs * fix clojure script and add outputs * bash v1 * bash batch for faster * bash is slow so just gen numbers instead of full workflow * fix bash script and add outputs * attempt resource exhaustion for bill * add T3 for perl and scala * remove old scripts, regenerate graphs, update website --------- Co-authored-by: spencermwoo <spencermwoo>
1 parent d203270 commit 92f00a6

File tree

229 files changed

+34777
-2527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+34777
-2527
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# randomness-in-programming-languages
2-
An example of random number generation in different programming [languages](/sources#future-languages)
2+
An example of random number generation in different programming [languages](/sources#completed-languages)
33

44
# hacktoberfest
55
A hactoberfest-friendly project
66

7+
# file structure
8+
Overview of folder layout
9+
710
## Contribute
811
Create an example of generating a million random numbers and calculating the percentage for each bucket.
912

analysis/analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22

3-
from stats import analysis_all
3+
from stats import analysis_all, write_analysis
44
from graph import plot_multis, plot_individuals, plot_analysis
55

66
# Generate Graphs
@@ -11,6 +11,7 @@
1111
# Graph Analysis
1212
# ====
1313
analysisList = analysis_all()
14+
write_analysis(analysisList)
1415
plot_analysis(analysisList)
1516

1617
# ===

analysis/graph.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import matplotlib.pyplot as plt
22

33
from util import read_output_files_and_perform, perform_probability_per_language, parse
4+
from stats import normalize_group, perc
45

56
# this plots multiple result files
67
def multiplot(languages, numbers, trials, *args):
@@ -10,7 +11,10 @@ def multiplot(languages, numbers, trials, *args):
1011
for (language, filename, x, y) in perform_probability_per_language(languages, numbers, trials):
1112
_plot(x, y, language)
1213

13-
_plot_graph('number', 'probability', f'multi_{numbers}_{trials}', True)
14+
fewer = False
15+
if numbers == 1000:
16+
fewer = True
17+
_plot_graph('number', 'probability', f'multi_{numbers}_{trials}', True, fewer)
1418

1519
def singleplot_all(languages, numbers, trials, include_expected):
1620
for language in languages:
@@ -27,10 +31,11 @@ def singleplot(language, numbers, trials, include_expected=False):
2731
filename = f'{language}_{numbers}_{trials}'
2832
with open(filename) as file:
2933
for line in file:
30-
n, probability = parse(line)
34+
if ":" in line:
35+
n, probability = parse(line)
3136

32-
x.append(n)
33-
y.append(probability)
37+
x.append(n)
38+
y.append(probability)
3439
# deviations.append(calculate_deviation(n, probability, expected))
3540

3641
_plot(x, y, language)
@@ -47,9 +52,17 @@ def _plot(x, y, label):
4752
def _bar(x, y):
4853
plt.bar(x, y, width=0.4, label=y)
4954

50-
def _plot_graph(x_axis, y_axis, title, save=False):
55+
def _plot_graph(x_axis, y_axis, title, save=False, fewer=False):
5156
plt.legend(loc='best')
5257

58+
# plt.margins(0.1)
59+
# plt.figure(figsize=(20,5))
60+
61+
# plt.figure(figsize=[12.8, 9.6])
62+
# if fewer:
63+
# plt.locator_params(axis='x', nbins=10)
64+
# plt.locator_params(axis='y', nbins=10)
65+
5366
plt.xlabel(x_axis)
5467
plt.ylabel(y_axis)
5568

@@ -66,22 +79,31 @@ def plot_individuals(include_expected=False):
6679
read_output_files_and_perform(singleplot_all, include_expected)
6780

6881
def plot_multis():
82+
plt.figure(figsize=(25.6, 19.2))
6983
read_output_files_and_perform(multiplot)
7084

7185
def plot_analysis(analysisList):
86+
plt.figure(figsize=(25.6, 19.2))
7287
numbers, trials = None, None
7388
for trialList in analysisList:
7489

7590
# trialList = normalize_group(trialList)
91+
# ymin = 0
92+
# ymax = 0
7693
for i, analysis in enumerate(trialList):
7794
std, filename = analysis
7895

7996
language, numbers, trials = filename.split("_")
8097

81-
# if i==0: plt.axis(ymin=std-perc(std))
82-
# elif i==len(trialList)-1: plt.axis(ymax=std+perc(std))
98+
if i==0: ymin = plt.ylim(ymin=max(std, 0))
99+
elif i==len(trialList)-1: plt.ylim(ymax=std)
83100

101+
# TODO: each language should use the same color in all graphs
84102
_bar(language, std)
103+
104+
# TODO: why y-axis has negative scale (???)
105+
# plt.axis(xmin=0, ymin=ymin, ymax=ymax)
106+
# print(plt.axis())
85107
_plot_graph('language', 'std', f'analysis_{numbers}_{trials}', True)
86108

87109
return

analysis/stats.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import statistics as st
22
import heapq
3-
# from sklearn import preprocessing
3+
from sklearn import preprocessing
44

5-
from util import read_output_files_and_perform, perform_probability_per_language
5+
from util import read_output_files_and_perform, perform_probability_per_language, write_to_file
66

77
def calculate_standard_deviation(language, data, sample_size):
88
# if language == 'expected':
@@ -29,11 +29,23 @@ def analysis_one(languages, numbers, trials):
2929
# split by trial, however variance is already split
3030
return [heapq.heappop(resHeap) for i in range(len(resHeap))]
3131

32-
# def normalize_group(analysisList):
33-
# return preprocessing.minmax_scale(analysisList, feature_range=(analysisList[0], analysisList[-1]))
32+
def write_analysis(analysisList):
33+
for trialList in analysisList:
34+
d = []
35+
numbers, trials = '', ''
36+
for i, analysis in enumerate(trialList):
3437

35-
# def perc(num):
36-
# return 0
38+
language, numbers, trials = analysis[1].split("_")
39+
40+
d.append(f'{language}:{analysis[0]}')
41+
42+
write_to_file(f'graphs/multi_{numbers}_{trials}_data', '\n'.join(d))
43+
44+
def normalize_group(analysisList):
45+
return preprocessing.minmax_scale(analysisList, feature_range=(analysisList[0], analysisList[-1]))
46+
47+
def perc(num):
48+
return 0
3749

3850
def analysis_all():
3951
analysisList = read_output_files_and_perform(analysis_one)

analysis/util.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def read_output_files_and_perform(func, *args):
1515

1616
return r
1717

18+
def write_to_file(filename, data):
19+
with open(filename, 'w') as f:
20+
f.write(data)
21+
1822
# def calculate_probability(filename):
1923
# with open(filename) as file:
2024
# x, y = [], []
@@ -33,10 +37,11 @@ def perform_probability_per_language(languages, numbers, trials):
3337
with open(filename) as file:
3438
x, y = [], []
3539
for line in file:
36-
n, probability = parse(line)
40+
if ":" in line:
41+
n, probability = parse(line)
3742

38-
x.append(n)
39-
y.append(probability)
43+
x.append(n)
44+
y.append(probability)
4045

4146
yield (language, filename, x,y)
4247

0 commit comments

Comments
 (0)