Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
4
Task/Statistics-Basic/Jq/statistics-basic-1.jq
Normal file
4
Task/Statistics-Basic/Jq/statistics-basic-1.jq
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Usage: prng N width
|
||||
function prng {
|
||||
cat /dev/urandom | tr -cd '0-9' | fold -w "$2" | head -n "$1"
|
||||
}
|
||||
32
Task/Statistics-Basic/Jq/statistics-basic-2.jq
Normal file
32
Task/Statistics-Basic/Jq/statistics-basic-2.jq
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# $histogram should be a JSON object, with buckets as keys and frequencies as values;
|
||||
# $keys should be an array of all the potential bucket names (possibly integers)
|
||||
# in the order to be used for display:
|
||||
def pp($histogram; $keys):
|
||||
([$histogram[]] | add) as $n # for scaling
|
||||
| ($keys|length) as $length
|
||||
| $keys[]
|
||||
| "\(.) : \("*" * (($histogram[tostring] // 0) * 20 * $length / $n) // "" )" ;
|
||||
|
||||
# `basic_stats` computes the unadjusted standard deviation
|
||||
# and assumes the sum of squares (ss) can be computed without concern for overflow.
|
||||
# The histogram is based on allocation to a bucket, which is made
|
||||
# using `bucketize`, e.g. `.*10|floor`
|
||||
def basic_stats(stream; bucketize):
|
||||
# Use
|
||||
reduce stream as $x ({histogram: {}};
|
||||
.count += 1
|
||||
| .sum += $x
|
||||
| .ss += $x * $x
|
||||
| ($x | bucketize | tostring) as $bucket
|
||||
| .histogram[$bucket] += 1 )
|
||||
| .mean = (.sum / .count)
|
||||
| .stddev = (((.ss/.count) - .mean*.mean) | sqrt) ;
|
||||
|
||||
basic_stats( "0." + inputs | tonumber; .*10|floor)
|
||||
| "
|
||||
|
||||
Basic statistics for \(.count) PRNs in [0,1]:
|
||||
mean: \(.mean)
|
||||
stddev: \(.stddev)
|
||||
Histogram dividing [0,1] into 10 equal intervals:",
|
||||
pp(.histogram; [range(0;10)] )
|
||||
5
Task/Statistics-Basic/Jq/statistics-basic-3.jq
Normal file
5
Task/Statistics-Basic/Jq/statistics-basic-3.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for n in 100 1000 1000000 100000000; do
|
||||
echo "Basic statistics for $n PRNs in [0,1]"
|
||||
prng $n 10 | jq -nrR -f basicStats.jq
|
||||
echo
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue