예제 #1
0
    def test_log_factor_hessian(self):
        delta = 0.00001
        y1 = 1.0
        y0 = 2.0
        theta = -2.0
        alpha = 1.0
        beta = 0.0
        c = 0.25
        # simulate the gradient
        true_hessian_approx_theta = (tools.log_likelihood_factor_gradient(y1, y0, theta + delta, alpha, beta, c) -
                                     tools.log_likelihood_factor_gradient(y1, y0, theta, alpha, beta, c)) / delta
        # calculate
        calc_hessian = tools.log_likelihood_factor_hessian(y1, y0, theta, alpha, beta, c)

        self.assertTrue(abs(calc_hessian - true_hessian_approx_theta) < 1e-4)
예제 #2
0
    def test_log_factor_gradient(self):
        delta = 0.00001
        y1 = 1.0
        y0 = 2.0
        theta = -2.0
        alpha = 1.0
        beta = 0.0
        # simulate the gradient
        true_gradient_approx_theta = (clib.log_likelihood_2PL(y1, y0, theta + delta, alpha, beta) -
                                      clib.log_likelihood_2PL(y1, y0, theta, alpha, beta)) / delta
        # calculate
        calc_gradient = tools.log_likelihood_factor_gradient(y1, y0, theta, alpha, beta)

        self.assertTrue(abs(calc_gradient - true_gradient_approx_theta) < 1e-4)

        # simulate the gradient
        c = 0.25
        true_gradient_approx_theta = (clib.log_likelihood_2PL(y1, y0, theta + delta, alpha, beta, c) -
                                      clib.log_likelihood_2PL(y1, y0, theta, alpha, beta, c)) / delta
        # calculate
        calc_gradient = tools.log_likelihood_factor_gradient(y1, y0, theta, alpha, beta, c)

        self.assertTrue(abs(calc_gradient - true_gradient_approx_theta) < 1e-4)