Example #1
0
    def test_dfunc_exp(self):
        """Unit test for the gradient returned by the dfunc_exp() function at the minimum."""

        # Get the chi-squared gradient.
        grad = dfunc_exp(self.params)

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

        # Assert that the elements must be 0.0.
        self.assertAlmostEqual(grad[0], 0.0, 6)
        self.assertAlmostEqual(grad[1], 0.0, 6)
Example #2
0
    def test_dfunc_exp(self):
        """Unit test for the gradient returned by the dfunc_exp() function at the minimum."""

        # Get the chi-squared gradient.
        grad = dfunc_exp(self.params)

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

        # Assert that the elements must be 0.0.
        self.assertAlmostEqual(grad[0], 0.0, 6)
        self.assertAlmostEqual(grad[1], 0.0, 6)
Example #3
0
    def dfunc_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 gradient generated by the C module converted to numpy format.
        @rtype:         numpy float64 array
        """

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

        # Call the C code.
        dchi2 = dfunc_exp(params)

        # Return the chi2 gradient as a numpy array.
        return array(dchi2, float64)
Example #4
0
    def dfunc_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 gradient generated by the C module converted to numpy format.
        @rtype:         numpy float64 array
        """

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

        # Call the C code.
        dchi2 = dfunc_exp(params)

        # Return the chi2 gradient as a numpy array.
        return array(dchi2, float64)
Example #5
0
    def test_dfunc_exp_off_minimum(self):
        """Unit test for the gradient returned by the dfunc_exp() function at a position away from the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/integrate.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 gradient.
        grad = dfunc_exp(params)

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

        # Check that the gradient matches the numerically derived values.
        self.assertAlmostEqual(grad[0], 456.36655522098829*self.scaling_list[0], 3)
        self.assertAlmostEqual(grad[1], -10.8613338920982*self.scaling_list[1], 3)
Example #6
0
    def test_dfunc_exp_off_minimum(self):
        """Unit test for the gradient returned by the dfunc_exp() function at a position away from the minimum.

        This uses the data from test_suite/shared_data/curve_fitting/numeric_gradient/integrate.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 gradient.
        grad = dfunc_exp(params)

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

        # Check that the gradient matches the numerically derived values.
        self.assertAlmostEqual(grad[0],
                               456.36655522098829 * self.scaling_list[0], 3)
        self.assertAlmostEqual(grad[1],
                               -10.8613338920982 * self.scaling_list[1], 3)