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)
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)
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))
Example #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))
Example #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)
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)
Example #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))
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))
Example #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)))
Example #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'
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')
Example #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)
def main():
	test_cauchy_fit(1000)
	writer.append('\n')
	test_cauchy_fit(10000)
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')
def calculate_stats(rvs):
    writer.append('mean: ' + str(mean(rvs)) + ' variance: ' + str(var(rvs)))
Example #16
0
def main():
    likelihood = rnd_multi_walk(100)
    writer.append("random walk likelihood is " + str(likelihood))
def main():
	likelihood = rnd_multi_walk(100)
	writer.append("random walk likelihood is "+str(likelihood))
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)
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)
def main():
    test_cauchy_fit(1000)
    writer.append('\n')
    test_cauchy_fit(10000)
def calculate_stats(rvs):
	writer.append('mean: '+str(mean(rvs))+' variance: '+str(var(rvs)))