Statistics/Basic: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: optimize the generation of random numbers.) |
(Added R implementation) |
||
Line 3,198: | Line 3,198: | ||
0.9: +++++++++++++++++++++++++++++++++++++++++++++++++</pre> |
0.9: +++++++++++++++++++++++++++++++++++++++++++++++++</pre> |
||
=={{header|R}}== |
|||
The challenge of processing a trillion numbers is generating them in the first place. As the errors below show, allocating 7.5 TB for such a vector is simply impractical. The workaround is to generate them, process individual data points and then discard them. The downside in this case is the time. |
|||
<lang R> |
|||
#Abhishek Ghosh, 10th January 2018 |
|||
#Generate the sets |
|||
a = runif(10,min=0,max=1) |
|||
b = runif(100,min=0,max=1) |
|||
c = runif(1000,min=0,max=1) |
|||
d = runif(10000,min=0,max=1) |
|||
#Print out the set of 10 values |
|||
cat("a = ",a) |
|||
#Print out the Mean and Standard Deviations of each of the sets |
|||
cat("Mean of a : ",mean(a)) |
|||
cat("Standard Deviation of a : ", sd(a)) |
|||
cat("Mean of b : ",mean(b)) |
|||
cat("Standard Deviation of b : ", sd(b)) |
|||
cat("Mean of c : ",mean(c)) |
|||
cat("Standard Deviation of c : ", sd(c)) |
|||
cat("Mean of d : ",mean(d)) |
|||
cat("Standard Deviation of d : ", sd(d)) |
|||
#Plotting the histogram of d |
|||
hist(d) |
|||
#Following lines error out due to insufficient memory |
|||
cat("Mean of a trillion random values in the range [0,1] : ",mean(runif(10^12,min=0,max=1))) |
|||
cat("Standard Deviation of a trillion random values in the range [0,1] : ", sd(runif(10^12,min=0,max=1))) |
|||
</lang> |
|||
Output |
|||
<pre> |
|||
a = 0.3884718 0.6324655 0.9288667 0.1948398 0.5636742 0.2746207 0.4712035 0.2624648 0.45492 0.3328236> |
|||
Mean of a : 0.4504351 |
|||
Standard Deviation of a : 0.2171919 |
|||
Mean of b : 0.5240795 |
|||
Standard Deviation of b : 0.2654211 |
|||
Mean of c : 0.5000978 |
|||
Standard Deviation of c : 0.2882098 |
|||
Mean of d : 0.4991501 |
|||
Standard Deviation of d : 0.2911486 |
|||
Error: cannot allocate vector of size 7450.6 Gb |
|||
Error: cannot allocate vector of size 7450.6 Gb |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<lang racket> |
<lang racket> |