コード例 #1
0
ファイル: utest.py プロジェクト: ReiMatsuzaki/opt_cbf
    def test_geometric_grad_hess_part(self):
        method = 'c1'
        num = 4
        h = 0.0001
        ns = range(num)
        abx4 = np.array([0.1, 1.5, 0.23])
        xs = [abx4[0], abx4[0]*abx4[1], abx4[0]*abx4[1]**2, abx4[2]]
        ref_g_et = [num_pd(func0_et123_4,  abx4, h, 3, n, method)
                    for n in range(3)]
        ref_h_et = [[num_pd2(func0_et123_4, abx4, h, 3, n, m, method)
                     for n in range(3)] for m in range(3)]
	g_full = np.array([num_pd(func0, xs, h, num, n, method)
                           for n in ns])
	h_full = np.array([[num_pd2(func0, xs, h, num, n1, n2, method)
			    for n1 in ns] for n2 in ns])
        calc_g_et = opt_cbf.geometric_grad(g_full, abx4, 3)
        calc_h_et = opt_cbf.geometric_hess(g_full, h_full, abx4, 3)
        for (ref, calc) in zip(ref_g_et, calc_g_et):
            self.assertAlmostEqual(ref, calc)
        for (ref_list, calc_list) in zip(ref_h_et, calc_h_et):
            for (ref, calc) in zip(ref_list, calc_list):
                self.assertAlmostEqual(ref, calc)
コード例 #2
0
ファイル: utest.py プロジェクト: ReiMatsuzaki/opt_cbf
    def test_geometric_grad_hess(self):
        method = 'c1'
        num = 4
        h = 0.0001
        ns = range(num)
        ab = np.array([ 0.1, 1.5])
        xs = [ab[0]*ab[1]**n for n in ns]
        ref_g_et = [num_pd(func0_et, ab, h, 2, n, method)
                    for n in [0, 1]]
        ref_h_et = [[num_pd2(func0_et, ab, h, 2, n, m, method)
                     for n in [0, 1]] for m in [0, 1]]
	g_full = np.array([num_pd(func0, xs, h, num, n, method)
                           for n in ns])
	h_full = np.array([[num_pd2(func0, xs, h, num, n1, n2, method)
			    for n1 in ns] for n2 in ns])
        calc_g_et = opt_cbf.geometric_grad(g_full, ab)
        calc_h_et = opt_cbf.geometric_hess(g_full, h_full, ab)
        for (ref, calc) in zip(ref_g_et, calc_g_et):
            self.assertAlmostEqual(ref, calc)

        for (ref_list, calc_list) in zip(ref_h_et, calc_h_et):
            for(ref, calc) in zip(ref_list, calc_list):
                self.assertAlmostEqual(ref, calc)