Exemple #1
0
def md(mu=1019,sigma=209):
	phi = []
	for i in range(400,1600,50):
		phi.append(gaussian.pdf(i,mu,sigma))
	stddraw.setYscale(0,1.1*max(phi))
	stdstats.plotLines(phi)
	stddraw.show()
Exemple #2
0
def main():
    n = int(sys.argv[1])
    stddraw.setYscale(-4, 4)
    stddraw.setYscale(0, 5)
    stddraw.setPenRadius(0.1)

    x = [0.0] * (n+1)
    y = [0.0] * (n+1)

    for i in range(n+1):
        x[i] = -0.4 + 0.8 * i/n
        y[i] = gaussian.pdf(x[i])

    for i in range(n):
        stddraw.line(x[i], y[i], x[i+1], y[i+1])
    stddraw._show()
Exemple #3
0
def main():
    n = int(sys.argv[1])
    p = float(sys.argv[2])
    trials = int(sys.argv[3])
    t = int(sys.argv[4])
    q = evaluate(n, p, trials)
    stdio.writeln(q)

    norm = exTimes(n, p, trials, t)
    phi = stdarray.create1D(n + 1, 0.0)
    stddev = math.sqrt(n) / 2.0
    for i in range(n + 1):
        phi[i] = gaussian.pdf(i, n / 2.0, stddev)

    stddraw.setCanvasSize(1000, 400)
    stddraw.setYscale(0, 1.1 * max(max(norm), max(phi)))
    stdstats.plotBars(norm)
    stdstats.plotLines(phi)
    stddraw.show()
Exemple #4
0
# draw the results to standard draw. Also draw the predicted Gaussian
# distribution function, thereby allowing easy comparison of the
# experimental results to the theoretically predicted results.

n = int(sys.argv[1])
trials = int(sys.argv[2])

freq = stdarray.create1D(n + 1, 0)
for t in range(trials):
    heads = stdrandom.binomial(n, 0.5)
    freq[heads] += 1

norm = stdarray.create1D(n + 1, 0.0)
for i in range(n + 1):
    norm[i] = 1.0 * freq[i] / trials

phi = stdarray.create1D(n + 1, 0.0)
stddev = math.sqrt(n) / 2.0
for i in range(n + 1):
    phi[i] = gaussian.pdf(i, n / 2.0, stddev)

stddraw.setCanvasSize(1000, 400)
stddraw.setYscale(0, 1.1 * max(max(norm), max(phi)))
stdstats.plotBars(norm)
stdstats.plotLines(phi)
stddraw.show()

#-----------------------------------------------------------------------

# python bernoulli.py 20 100000
Exemple #5
0
# distribution function, thereby allowing easy comparison of the
# experimental results to the theoretically predicted results.

n = int(sys.argv[1])
trials = int(sys.argv[2])

freq = stdarray.create1D(n+1, 0)
for t in range(trials):
    heads = stdrandom.binomial(n, 0.5)
    freq[heads] += 1
    
norm = stdarray.create1D(n+1, 0.0)
for i in range(n+1):
    norm[i] = 1.0 * freq[i] / trials
    
phi = stdarray.create1D(n+1, 0.0)
stddev = math.sqrt(n)/2.0
for i in range(n+1):
    phi[i] = gaussian.pdf(i, n/2.0, stddev)
    
stddraw.setCanvasSize(1000, 400)
stddraw.setYscale(0, 1.1 * max(max(norm), max(phi)))
stdstats.plotBars(norm)
stdstats.plotLines(phi)
stddraw.show()

#-----------------------------------------------------------------------

# python bernoulli.py 20 100000

import sys
import math
import stddraw
import stdrandom
import stdstats
import gaussian

n = int(sys.argv[1])
trials = int(sys.argv[2])

freq = (n + 1) * [0]
for t in range(trials):
    heads = stdrandom.binomial(n, 0.5)
    #n-ta seke partab kon, beshmor chanta shir miyad
    freq[heads] += 1

norm = [0.0] * (n + 1)
for i in range(n + 1):
    norm[i] = 1.0 * freq[i] / trials

#rasm tozi normal
phi = [0.0] * (n + 1)
stddev = math.sqrt(n) / 2.0
for i in range(n + 1):
    phi[i] = gaussian.pdf(n, n / 2, stddev)
stddraw.setCanvasSize(1000, 400)
stddraw.setYscale(0, 1.0, max(max(norm), max(phi)))
stdstats.plotBars(norm)
stdstats.plotLines(phi)
stddraw.show()