def test_fit(): import random random.seed(1234) n = Normal.fit(Uniform.fit(Normal(2, 1.5).random(1000))) #print n.mean #print n.stddev assert abs(n.mean - 2) < 0.3 assert abs(n.stddev - 1.5) < 0.3
def normal_dist(mu=100, sigma=15): """ mainfunc """ dist = Normal(mu,sigma) dist_cdf = dist.cdf(x) sympy.Plot(dist_cdf) pass
def test_normal(): dps, mp.dps = mp.dps, 20 N = Normal(0, 1) assert N.mean == 0 assert N.variance == 1 assert N.probability(-1, 1) == erf(1 / sqrt(2)) assert N.probability(-1, 0) == erf(1 / sqrt(2)) / 2 N = Normal(2, 4) assert N.mean == 2 assert N.variance == 16 assert N.confidence(1) == (-oo, oo) assert N.probability(1, 3) == erf(1 / sqrt(32)) assert N.pdf(1).evalf() == (exp(Rational(-1, 32)) / (4 * sqrt(2 * pi))).evalf() for p in [0.1, 0.3, 0.7, 0.9, 0.995]: a, b = N.confidence(p) assert abs(float(N.probability(a, b).evalf()) - p) < 1e-10 N = Normal(0, 2 / sqrt(2 * pi)) assert N.pdf(0) == Rational(1, 2) mp.dps = dps
def compute_pref(mu1, mu2, sigma1_sq, sigma2_sq, margin): if mu1 < mu2: raise "mu1 must be greater than mu2" mu0 = mu1 - mu2 sigma0_sq = sigma1_sq + sigma2_sq sigma0 = math.sqrt(sigma0_sq) N = Normal(mu0, sigma0) prob_win = N.probability(margin, oo).evalf() prob_lost = N.probability(-oo, 0).evalf() prob_draw = 1. - (prob_lost + prob_win) return prob_win, prob_draw, prob_lost
def test_fit(): import random random.seed(1234) n = Normal.fit(Uniform.fit(Normal(2, 1.5).random(1000))) #print n.mean #print n.stddev assert abs(n.mean - 2) < 0.3 assert abs(n.stddev - 1.5) < 0.3 n = Normal.fit([1,2,3,4,5]) assert n.mean == 3 assert n.stddev == sqrt(2) n = Uniform.fit([1,2,3,4,5]) assert n.mean == 3 assert n.stddev == sqrt(2)
def getStdDev(distance, confidence, x=Normal(0, 1)): "Distance = end point - mean" confidenceDistance = x.confidence(confidence)[1] stddev = confidenceDistance * distance return stddev