def test_log_many(): correct = [-1.984832619482592, -0.2447556437138158, 0.6365617224898709, \ 0.1590602757612699, -0.2272345095098529, -0.1214549048852035, \ 0.1063727931042495, 0.09717057757496405, -0.05099522699996534, \ -0.07868250626810564, 0.02037098171372864] mu = modified_moments(log_x_minus_y, 10, 0.123) np.testing.assert_almost_equal(mu, correct)
def test_recursive_quad(): x, w = recursive_quad(modified_moments(rl1, 9, 0.5, 0.5)) exact = [2.69982, 0.475878, 0.826076, 0.238427, 0.470906, 0.153639, 0.325999, 0.112006, 0.248412, 0.0877162] for i in range(10): est = np.sum(w * x ** i) np.testing.assert_almost_equal(exact[i], est, 5)
def test_log_many(): correct = [-1.984832619482592, -0.2447556437138158, 0.6365617224898709, \ 0.1590602757612699, -0.2272345095098529, -0.1214549048852035, \ 0.1063727931042495, 0.09717057757496405, -0.05099522699996534, \ -0.07868250626810564, 0.02037098171372864] mu = modified_moments(log_x_minus_y, 10, 0.123) np.testing.assert_almost_equal(mu, correct)
def test_small_order_recursive_quad(): for N in range(2, 4): moments = modified_moments(rl1, N - 1, 0.5, 0.5) x, w = recursive_quad(moments) exact = [2.69982, 0.475878] for i in range(len(exact)): est = np.sum(w * x**i) np.testing.assert_almost_equal(exact[i], est, 5)
def test_value(): ay = 0.05 by = 0.05 pairs = [(4, 1.1977), (10, -0.376323), (20, 0.0743193), (30, -0.00279826), (31, -0.05510287928339709)] for n, exact in pairs: est = modified_moments(rl1, n, ay, by) np.testing.assert_almost_equal(est[-1], exact, 5)
def test_small_order_recursive_quad(): for N in range(2, 4): moments = modified_moments(rl1, N - 1, 0.5, 0.5) x, w = recursive_quad(moments) exact = [2.69982, 0.475878] for i in range(len(exact)): est = np.sum(w * x ** i) np.testing.assert_almost_equal(exact[i], est, 5)
def test_r3(): correct = [2.073823077631299, 0.2535989787775645, -0.2911113387007714, \ -0.08946188432319288, 0.04410566356714894, 0.02448735642709018, \ -0.005390367432553238, -0.005828732964372520, 0.0002538145298338417] a = 0.213 b = 0.85 moments = modified_moments(rl1, 8, a, b) est = modify_divide_r2(8, moments, a, b, correct[0], correct[1]) np.testing.assert_almost_equal(correct, est)
def test_recursive_quad(): x, w = recursive_quad(modified_moments(rl1, 9, 0.5, 0.5)) exact = [ 2.69982, 0.475878, 0.826076, 0.238427, 0.470906, 0.153639, 0.325999, 0.112006, 0.248412, 0.0877162 ] for i in range(10): est = np.sum(w * x**i) np.testing.assert_almost_equal(exact[i], est, 5)
def test_value(): ay = 0.05 by = 0.05 pairs = [(4,1.1977), (10,-0.376323), (20, 0.0743193), (30, -0.00279826), (31, -0.05510287928339709)] for n, exact in pairs: est = modified_moments(rl1, n, ay, by) np.testing.assert_almost_equal(est[-1], exact, 5)
def test_r3(): correct = [2.073823077631299, 0.2535989787775645, -0.2911113387007714, \ -0.08946188432319288, 0.04410566356714894, 0.02448735642709018, \ -0.005390367432553238, -0.005828732964372520, 0.0002538145298338417] a = 0.213 b = 0.85 moments = modified_moments(rl1, 8, a, b) est = modify_divide_r2(8, moments, a, b, correct[0], correct[1]) np.testing.assert_almost_equal(correct, est)
def test_recursive_quad2(): x, w = recursive_quad(modified_moments(rl1, 9, 0.5, 2.5)) exact = [ 0.7675150090814903, 0.01779131391448664, 0.2514125580305381, 0.01042604118726131, 0.1497329916946964, 0.007351040226216374, 0.1065156992309334, 0.005670755078910097, 0.08263150653792486, 0.004613594538086503 ] for i in range(10): est = np.sum(w * x**i) np.testing.assert_almost_equal(exact[i], est, 11)
def test_r5(): correct = [2.319371017897694, 0.3821621948981323, -0.4762089061831612, \ -0.1876037135232636, 0.09309106929258391, 0.06515743698013002, \ -0.01293167540460619, -0.01866314618738899, 0.0001560375793864460] a = 0.213 b = 0.85 moments = modified_moments(rl1, 8, a, b) r3 = modify_divide_r2(8, moments, a, b, 2.073823077631299, 0.2535989787775645) est = modify_divide_r2(8, r3, a, b, correct[0], correct[1]) np.testing.assert_almost_equal(correct, est)
def test_r5(): correct = [2.319371017897694, 0.3821621948981323, -0.4762089061831612, \ -0.1876037135232636, 0.09309106929258391, 0.06515743698013002, \ -0.01293167540460619, -0.01866314618738899, 0.0001560375793864460] a = 0.213 b = 0.85 moments = modified_moments(rl1, 8, a, b) r3 = modify_divide_r2(8, moments, a, b, 2.073823077631299, 0.2535989787775645) est = modify_divide_r2(8, r3, a, b, correct[0], correct[1]) np.testing.assert_almost_equal(correct, est)
def test_r5_more(): a = 1.2 b = 1.2 r1 = modified_moments(rl1, 13, a, b) r3 = modify_divide_r2(13, r1, a, b, mu_3_0(a, b), mu_3_1(a, b)) est = modify_divide_r2(13, r3, a, b, mu_5_0(a, b), mu_5_1(a, b)) exact = [0.236037, 0.119291, 0.0349751, 0.00321571, -0.00239632, -0.00140269, \ -0.000352242, -4.30148*10**-6, 0.0000340514, 0.0000145451, \ 2.60414*10**-6, -3.46627*10**-7, -2.41911*10**-7, -2.52412*10**-6] np.testing.assert_almost_equal(est, exact, 5)
def test_r5_more(): a = 1.2 b = 1.2 r1 = modified_moments(rl1, 13, a, b) r3 = modify_divide_r2(13, r1, a, b, mu_3_0(a, b), mu_3_1(a, b)) est = modify_divide_r2(13, r3, a, b, mu_5_0(a, b), mu_5_1(a, b)) exact = [0.236037, 0.119291, 0.0349751, 0.00321571, -0.00239632, -0.00140269, \ -0.000352242, -4.30148*10**-6, 0.0000340514, 0.0000145451, \ 2.60414*10**-6, -3.46627*10**-7, -2.41911*10**-7, -2.52412*10**-6] np.testing.assert_almost_equal(est, exact, 5)
def test_high_order_recursive_quad(): N = 100 x, w = recursive_quad(modified_moments(rl1, N - 1, 0.5, 0.5)) exact = dict() # I get 10 digits at N = 100 exact[100] = 0.007920933265917480 # I get 5 digits at N = 110 exact[110] = 0.007192320886184629 exact[121] = 0.01703712555375862 exact[150] = 0.005257679877042412 exact[200] = 0.003934647991362962 est = np.sum(w * x ** (N - 1)) np.testing.assert_almost_equal(exact[N], est, 9)
def test_high_order_recursive_quad(): N = 100 x, w = recursive_quad(modified_moments(rl1, N - 1, 0.5, 0.5)) exact = dict() # I get 10 digits at N = 100 exact[100] = 0.007920933265917480 # I get 5 digits at N = 110 exact[110] = 0.007192320886184629 exact[121] = 0.01703712555375862 exact[150] = 0.005257679877042412 exact[200] = 0.003934647991362962 est = np.sum(w * x**(N - 1)) np.testing.assert_almost_equal(exact[N], est, 9)
def test_recursive_quad2(): x, w = recursive_quad(modified_moments(rl1, 9, 0.5, 2.5)) exact = [0.7675150090814903, 0.01779131391448664, 0.2514125580305381, 0.01042604118726131, 0.1497329916946964, 0.007351040226216374, 0.1065156992309334, 0.005670755078910097, 0.08263150653792486, 0.004613594538086503] for i in range(10): est = np.sum(w * x ** i) np.testing.assert_almost_equal(exact[i], est, 11)
def test_mapped_recursive_quad2(): mapped_ay = map_singular_pt(0.2, 0.0, 1.0) mapped_by = map_distance_to_interval(0.3, 0.0, 1.0) moments = modified_moments(rl1, 10, mapped_ay, mapped_by) x, w = recursive_quad(moments) x, w = map_pts_wts(x, w, 0.0, 1.0) w = map_weights_by_inv_power(w, 1.0, 0.0, 1.0) exact = [2.332556553293539, 0.9603565576440610, 0.5636909785950152, \ 0.3894662160471265, 0.2949533988361775, 0.2365588120191993, \ 0.1971850086215070, 0.1689379319389373, 0.1477219765628722, \ 0.1312177383160300] for i in range(len(exact)): est = np.sum(w * x**i) np.testing.assert_almost_equal(exact[i], est, 9)
def test_mapped_recursive_quad2(): mapped_ay = map_singular_pt(0.2, 0.0, 1.0) mapped_by = map_distance_to_interval(0.3, 0.0, 1.0) moments = modified_moments(rl1, 10, mapped_ay, mapped_by) x, w = recursive_quad(moments) x, w = map_pts_wts(x, w, 0.0, 1.0) w = map_weights_by_inv_power(w, 1.0, 0.0, 1.0) exact = [2.332556553293539, 0.9603565576440610, 0.5636909785950152, \ 0.3894662160471265, 0.2949533988361775, 0.2365588120191993, \ 0.1971850086215070, 0.1689379319389373, 0.1477219765628722, \ 0.1312177383160300] for i in range(len(exact)): est = np.sum(w * x ** i) np.testing.assert_almost_equal(exact[i], est, 9)
def test_mapped_recursive_quad(): mapped_ay = map_singular_pt(0.5, 1.0, 2.0) mapped_by = map_distance_to_interval(0.5, 1.0, 2.0) moments = modified_moments(rl1, 10, mapped_ay, mapped_by) x, w = recursive_quad(moments) x, w = map_pts_wts(x, w, 1.0, 2.0) w = map_weights_by_inv_power(w, 1.0, 1.0, 2.0) exact = [0.9370728722124352, 1.342568485003826, 2.000243585190683, \ 3.091829672374373, 4.940760583752816, 8.128175556459884, \ 13.70706664710914, 23.59959784014733, 41.33761425072659, \ 73.44841816566141] for i in range(10): est = np.sum(w * x**i) np.testing.assert_almost_equal(exact[i], est, 10)
def test_mapped_recursive_quad(): mapped_ay = map_singular_pt(0.5, 1.0, 2.0) mapped_by = map_distance_to_interval(0.5, 1.0, 2.0) moments = modified_moments(rl1, 10, mapped_ay, mapped_by) x, w = recursive_quad(moments) x, w = map_pts_wts(x, w, 1.0, 2.0) w = map_weights_by_inv_power(w, 1.0, 1.0, 2.0) exact = [0.9370728722124352, 1.342568485003826, 2.000243585190683, \ 3.091829672374373, 4.940760583752816, 8.128175556459884, \ 13.70706664710914, 23.59959784014733, 41.33761425072659, \ 73.44841816566141] for i in range(10): est = np.sum(w * x ** i) np.testing.assert_almost_equal(exact[i], est, 10)
def test_distant_value(): ay = 5.0 by = 5.0 exact = 9.68812e-8 est = modified_moments(rl1, 9, ay, by) np.testing.assert_almost_equal(est[-1], exact, 5)
def test_distant_value(): ay = 5.0 by = 5.0 exact = 9.68812e-8 est = modified_moments(rl1, 9, ay, by) np.testing.assert_almost_equal(est[-1], exact, 5)