Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Statistics-Basic/MiniScript/statistics-basic.mini
Normal file
39
Task/Statistics-Basic/MiniScript/statistics-basic.mini
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Stats = {}
|
||||
Stats.count = 0
|
||||
Stats.sum = 0
|
||||
Stats.sumOfSquares = 0
|
||||
Stats.histo = null
|
||||
|
||||
Stats.add = function(x)
|
||||
self.count = self.count + 1
|
||||
self.sum = self.sum + x
|
||||
self.sumOfSquares = self.sumOfSquares + x*x
|
||||
bin = floor(x*10)
|
||||
if not self.histo then self.histo = [0]*10
|
||||
self.histo[bin] = self.histo[bin] + 1
|
||||
end function
|
||||
|
||||
Stats.mean = function()
|
||||
return self.sum / self.count
|
||||
end function
|
||||
|
||||
Stats.stddev = function()
|
||||
m = self.sum / self.count
|
||||
return sqrt(self.sumOfSquares / self.count - m*m)
|
||||
end function
|
||||
|
||||
Stats.histogram = function()
|
||||
for i in self.histo.indexes
|
||||
print "0." + i + ": " + "=" * (self.histo[i]/self.count * 200)
|
||||
end for
|
||||
end function
|
||||
|
||||
for sampleSize in [100, 1000, 10000]
|
||||
print "Samples: " + sampleSize
|
||||
st = new Stats
|
||||
for i in range(sampleSize)
|
||||
st.add rnd
|
||||
end for
|
||||
print "Mean: " + st.mean + " Standard Deviation: " + st.stddev
|
||||
st.histogram
|
||||
end for
|
||||
Loading…
Add table
Add a link
Reference in a new issue