Exemplo n.º 1
0
    def test_d2func_exp_off_minimum(self):
        """Unit test for the Hessian returned by the d2func_exp() function at a position away from the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
        """

        # The off-minimum parameter values.
        I0 = 500.0
        R = 2.0
        params = [R / self.scaling_list[0], I0 / self.scaling_list[1]]

        # Get the chi-squared Hessian.
        hess = d2func_exp(params)

        # Printout.
        print("The Hessian at %s is:\n%s" % (params, hess))

        # Check that the Hessian matches the numerically derived values.
        self.assertAlmostEqual(hess[0][0],
                               -4.11964848e+02 * self.scaling_list[0]**2, 3)
        self.assertAlmostEqual(
            hess[0][1],
            7.22678641e-01 * self.scaling_list[0] * self.scaling_list[1], 3)
        self.assertAlmostEqual(
            hess[1][0],
            7.22678641e-01 * self.scaling_list[0] * self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][1],
                               2.03731472e-02 * self.scaling_list[1]**2, 3)
Exemplo n.º 2
0
    def test_d2func_exp(self):
        """Unit test for the Hessian returned by the d2func_exp() function at the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
        """

        # Get the chi-squared Hessian.
        hess = d2func_exp(self.params)

        # Printout.
        print("The Hessian at the minimum is:\n%s" % hess)

        # Check that the Hessian matches the numerically derived values.
        self.assertAlmostEqual(hess[0][0],  4.72548021e+03*self.scaling_list[0]**2, 3)
        self.assertAlmostEqual(hess[0][1], -3.61489336e+00*self.scaling_list[0]*self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][0], -3.61489336e+00*self.scaling_list[0]*self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][1],  2.31293027e-02*self.scaling_list[1]**2, 3)
Exemplo n.º 3
0
    def d2func_exp(self, params):
        """Wrapper function for the C module, for converting numpy arrays.

        @param params:  The parameter array from the minimisation code.
        @type params:   numpy array
        @return:        The Hessian generated by the C module converted to numpy format.
        @rtype:         numpy float64 rank-2 array
        """

        # Convert if necessary.
        if isinstance(params, ndarray):
            params = params.tolist()

        # Call the C code.
        d2chi2 = d2func_exp(params)

        # Return the chi2 Hessian as a numpy array.
        return array(d2chi2, float64)
Exemplo n.º 4
0
    def d2func_exp(self, params):
        """Wrapper function for the C module, for converting numpy arrays.

        @param params:  The parameter array from the minimisation code.
        @type params:   numpy array
        @return:        The Hessian generated by the C module converted to numpy format.
        @rtype:         numpy float64 rank-2 array
        """

        # Convert if necessary.
        if isinstance(params, ndarray):
            params = params.tolist()

        # Call the C code.
        d2chi2 = d2func_exp(params)

        # Return the chi2 Hessian as a numpy array.
        return array(d2chi2, float64)
Exemplo n.º 5
0
    def test_d2func_exp_off_minimum(self):
        """Unit test for the Hessian returned by the d2func_exp() function at a position away from the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
        """

        # The off-minimum parameter values.
        I0 = 500.0
        R = 2.0
        params = [R/self.scaling_list[0], I0/self.scaling_list[1]]

        # Get the chi-squared Hessian.
        hess = d2func_exp(params)

        # Printout.
        print("The Hessian at %s is:\n%s" % (params, hess))

        # Check that the Hessian matches the numerically derived values.
        self.assertAlmostEqual(hess[0][0], -4.11964848e+02*self.scaling_list[0]**2, 3)
        self.assertAlmostEqual(hess[0][1],  7.22678641e-01*self.scaling_list[0]*self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][0],  7.22678641e-01*self.scaling_list[0]*self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][1],  2.03731472e-02*self.scaling_list[1]**2, 3)
Exemplo n.º 6
0
    def test_d2func_exp(self):
        """Unit test for the Hessian returned by the d2func_exp() function at the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/Hessian.log.
        """

        # Get the chi-squared Hessian.
        hess = d2func_exp(self.params)

        # Printout.
        print("The Hessian at the minimum is:\n%s" % hess)

        # Check that the Hessian matches the numerically derived values.
        self.assertAlmostEqual(hess[0][0],
                               4.72548021e+03 * self.scaling_list[0]**2, 3)
        self.assertAlmostEqual(
            hess[0][1],
            -3.61489336e+00 * self.scaling_list[0] * self.scaling_list[1], 3)
        self.assertAlmostEqual(
            hess[1][0],
            -3.61489336e+00 * self.scaling_list[0] * self.scaling_list[1], 3)
        self.assertAlmostEqual(hess[1][1],
                               2.31293027e-02 * self.scaling_list[1]**2, 3)