def test_likelihoods(self): "Makes sure that the sparsified likelihood function procedure is reasonable." import time nug = random.normal()**2 * .3 fs = array([0]) A, pos, age_distribution = ages_and_data([300], fs, self.correction_factor_array, [self.age_lims[0]]) t1 = time.time() lp_small = mbgw.correction_factors.known_age_corr_likelihoods_f( pos, A, self.correction_factor_array, linspace(-5, 5, 500), nug, 's')[0] # print 'Small', time.time() - t1 t2 = time.time() lp_large = mbgw.correction_factors.known_age_corr_likelihoods_f( pos, A, self.correction_factor_array, linspace(-5, 5, 500), nug, 'l')[0] # print 'Large', time.time() - t2 x = linspace(-5, 5, 100) small = lp_small(x) large = lp_large(x) assert_almost_equal(small, large, 8)
def test_ages_and_data(self): "Makes sure that the ages drawn by ages_and_data match the age distributions." N_exam = ones(self.N) * 10000 A, pos, age_distribution = ages_and_data(N_exam, self.f_samp, self.correction_factor_array, self.age_lims) empirical_age_distributions = [] for j in xrange(self.N): A_ind = A[j]-self.age_lims[j][0] empirical_age_distributions.append(array([sum(A_ind==i) for i in xrange(len(age_distribution[j]))]) / 10000.) bin_sds = sqrt(age_distribution[j] * (1-age_distribution[j]) / 10000.) assert(all(abs(age_distribution[j]-empirical_age_distributions[j]) < 4*bin_sds))
def test_ages_and_data(self): "Makes sure that the ages drawn by ages_and_data match the age distributions." N_exam = ones(self.N) * 10000 A, pos, age_distribution = ages_and_data(N_exam, self.f_samp, self.correction_factor_array, self.age_lims) empirical_age_distributions = [] for j in xrange(self.N): A_ind = A[j] - self.age_lims[j][0] empirical_age_distributions.append( array([ sum(A_ind == i) for i in xrange(len(age_distribution[j])) ]) / 10000.) bin_sds = sqrt(age_distribution[j] * (1 - age_distribution[j]) / 10000.) assert (all( abs(age_distribution[j] - empirical_age_distributions[j]) < 4 * bin_sds))
def test_likelihoods(self): "Makes sure that the sparsified likelihood function procedure is reasonable." import time nug = random.normal()**2 * .3 fs = array([0]) A, pos, age_distribution = ages_and_data([300], fs, self.correction_factor_array, [self.age_lims[0]]) t1 = time.time() lp_small = mbgw.correction_factors.known_age_corr_likelihoods_f(pos, A, self.correction_factor_array, linspace(-5,5,500), nug, 's')[0] # print 'Small', time.time() - t1 t2 = time.time() lp_large = mbgw.correction_factors.known_age_corr_likelihoods_f(pos, A, self.correction_factor_array, linspace(-5,5,500), nug, 'l')[0] # print 'Large', time.time() - t2 x = linspace(-5, 5, 100) small = lp_small(x) large = lp_large(x) assert_almost_equal(small, large, 8)