コード例 #1
0
def test_muller_fit():
	variance = 0.1 # given in the ques
	rvs = generate_muller_rvs(variance)
	number_of_bins = int(1.88 * size(rvs) ** (2/5.0))
	integrand = lambda x : stats.norm.pdf(x, scale=variance)
	writer.append('testing box-muller')
	gof.do_chi(rvs, number_of_bins, integrand)
コード例 #2
0
def test_muller_fit():
    variance = 0.1  # given in the ques
    rvs = generate_muller_rvs(variance)
    number_of_bins = int(1.88 * size(rvs)**(2 / 5.0))
    integrand = lambda x: stats.norm.pdf(x, scale=variance)
    writer.append('testing box-muller')
    gof.do_chi(rvs, number_of_bins, integrand)
コード例 #3
0
def run_problem1(sample_size):
	u = zeros([sample_size,1])
	u = [random.random() for u in u]
	f_x = [-1 * log(1-u) for u in u]
	g_x = [cos(f_x) for f_x in f_x]
	mu = mean(g_x)
	writer.append("problem 1 mean is "+str(mu))
コード例 #4
0
def run_problem1(sample_size):
    u = zeros([sample_size, 1])
    u = [random.random() for u in u]
    f_x = [-1 * log(1 - u) for u in u]
    g_x = [cos(f_x) for f_x in f_x]
    mu = mean(g_x)
    writer.append("problem 1 mean is " + str(mu))
コード例 #5
0
def test_gamma_fit():
    shape = 5  #given from hw1
    rvs = generate_gamma_rvs(shape)
    number_of_bins = int(1.88 * size(rvs)**(2 / 5.0))
    integrand = lambda x: stats.gamma(5).pdf(x)
    writer.append('testing gamma distribution')
    gof.do_chi(rvs, number_of_bins, integrand)
コード例 #6
0
def test_cauchy_fit(sample_size):
    rvs = generate_cauchy_rvs(sample_size)
    number_of_bins = int(1.88 * size(rvs)**(2 / 5.0))
    integrand = lambda x: stats.gamma(5).pdf(
        x)  #cauchy was derived from gamma through the rejection method
    writer.append('testing cauchy distribution with ' + str(sample_size) +
                  ' samples')
    gof.do_chi(rvs, number_of_bins, integrand)
コード例 #7
0
def run_problem2(sample_size):
    u = zeros([sample_size, 1])
    u = [random.random() for u in u]
    #u = [stats.norm.rvs() for u in u] #not sure whether to use normal or uniform rv
    f_x = [arccos((1 - u) - 1 / float(2 * pi)) for u in u]
    #f_x = [arccos(2*pi*(1-u)-1) for u in u] #not sure about the equation either - arccos evaluates to nan i.e., undefined
    g_x = [2 * pi * ((1 + cos(f_x))**(-2 / float(3))) for f_x in f_x]
    mu = mean(g_x)
    writer.append("problem 2 mean is " + str(mu))
コード例 #8
0
def run_problem2(sample_size):
	u = zeros([sample_size, 1])
	u = [random.random() for u in u]
	#u = [stats.norm.rvs() for u in u] #not sure whether to use normal or uniform rv
	f_x = [arccos((1-u)-1/float(2*pi)) for u in u]
	#f_x = [arccos(2*pi*(1-u)-1) for u in u] #not sure about the equation either - arccos evaluates to nan i.e., undefined
	g_x = [2*pi*((1+cos(f_x))**(-2/float(3))) for f_x in f_x]
	mu = mean(g_x)
	writer.append("problem 2 mean is "+str(mu))
コード例 #9
0
def main():
	r = zeros((1e6,3))
	for i in range(r.shape[0]):
		for j in range(r.shape[1]):
			r[i,j] = random.exponential()
	c1 = r[:,0] + 2*r[:,1] + 3*r[:,2]
	# ques a
	id_a = c1 > 15
	#ques b
	id_b= c1 < 1
	out_a = r[id_a, 0] + 2*r[id_a, 1] + 3*r[id_a, 2]
	out_b = r[id_b, 0] + 2*r[id_b, 1] + 3*r[id_b, 2]
	writer.write('')
	writer.append('a: '+str(mean(out_a)))
	writer.append('b: '+str(mean(out_b)))
コード例 #10
0
def main():
	print 'Brewing numbers... '
	writer.write('GOODNESS OF FIT TEST FOR FIVE DISTRIBUTIONS\n')
	goodness_of_fit_lcg.main()#question 1
	writer.append('\n')
	goodness_of_fit_rand.main()#question 2
	writer.append('\n')
	goodness_of_fit_boxmuller.main()#question 3
	writer.append('\n')
	goodness_of_fit_cauchy.main()#question 4
	writer.append('\n')
	goodness_of_fit_gamma.main()#question 5
	print 'Done. Results written to result/result.txt'
コード例 #11
0
def compare_chisquare(actual, expected):
    writer.append('chisquared - actual: ' + str(actual) + ' expected: ' +
                  str(expected))
    if actual <= expected:
        writer.append('Accept null hypothesis i.e., good fit')
    else:
        writer.append('Reject null hypothesis i.e., bad fit')
コード例 #12
0
def test_random_fit():
    rvs = generate_random_rvs()
    number_of_bins = int(1.88 * size(rvs)**(2 / 5.0))
    integrand = lambda x: 1  #pdf for uniform rv
    writer.append('testing random')
    gof.do_chi(rvs, number_of_bins, integrand)
コード例 #13
0
def main():
	test_cauchy_fit(1000)
	writer.append('\n')
	test_cauchy_fit(10000)
コード例 #14
0
def compare_chisquare(actual, expected):
	writer.append('chisquared - actual: '+str(actual)+' expected: '+ str(expected))
	if actual <= expected:
		writer.append('Accept null hypothesis i.e., good fit')
	else:
		writer.append('Reject null hypothesis i.e., bad fit')
コード例 #15
0
def calculate_stats(rvs):
    writer.append('mean: ' + str(mean(rvs)) + ' variance: ' + str(var(rvs)))
コード例 #16
0
def main():
    likelihood = rnd_multi_walk(100)
    writer.append("random walk likelihood is " + str(likelihood))
コード例 #17
0
def main():
	likelihood = rnd_multi_walk(100)
	writer.append("random walk likelihood is "+str(likelihood))
コード例 #18
0
def test_lcg_fit():
	rvs = generate_lcg_rvs()
	number_of_bins = int(1.88 * size(rvs) ** (2/5.0))
	integrand = lambda x : 1 #pdf for uniform rv
	writer.append('testing lcg')
	gof.do_chi(rvs, number_of_bins, integrand)
コード例 #19
0
def test_cauchy_fit(sample_size):
	rvs = generate_cauchy_rvs(sample_size)
	number_of_bins = int(1.88 * size(rvs) ** (2/5.0))
	integrand = lambda x : stats.gamma(5).pdf(x) #cauchy was derived from gamma through the rejection method
	writer.append('testing cauchy distribution with '+str(sample_size)+' samples')
	gof.do_chi(rvs, number_of_bins, integrand)
コード例 #20
0
def main():
    test_cauchy_fit(1000)
    writer.append('\n')
    test_cauchy_fit(10000)
コード例 #21
0
def calculate_stats(rvs):
	writer.append('mean: '+str(mean(rvs))+' variance: '+str(var(rvs)))