Esempio n. 1
0
    def test_dchi2(self):
        """Unit test for the chi-squared gradient created by the dchi2 function.

        The chi-squared gradient is [0, 10] for the following data::

            data =              |  1.0  1.5  2.0  2.5  3.0 |,

            back_calc =         |  0.9  1.45 2.0  2.55 3.1 |,

            back_calc_grad =    |  0.1  0.2  0.3  0.2  0.1 |
                                | -0.2 -0.1  0.0  0.1  0.2 |,

            errors =            |  0.1  0.1  0.1  0.1  0.1 |.
        """

        # Calculate the gradient elements.
        grad = zeros(2, float64)
        dchi2(grad, 2, self.data, self.back_calc, self.back_calc_grad, self.errors)

        # Assert, to a precision of 13 decimal places, that the gradient is [0, 10].
        self.assertAlmostEqual(grad[0], 0.0, places=13)
        self.assertAlmostEqual(grad[1], 10.0, places=13)

        # Delete the gradient data.
        del grad
Esempio n. 2
0
    def test_dchi2(self):
        """Unit test for the chi-squared gradient created by the dchi2 function.

        The chi-squared gradient is [0, 10] for the following data::

            data =              |  1.0  1.5  2.0  2.5  3.0 |,

            back_calc =         |  0.9  1.45 2.0  2.55 3.1 |,

            back_calc_grad =    |  0.1  0.2  0.3  0.2  0.1 |
                                | -0.2 -0.1  0.0  0.1  0.2 |,

            errors =            |  0.1  0.1  0.1  0.1  0.1 |.
        """

        # Calculate the gradient elements.
        grad = zeros(2, float64)
        dchi2(grad, 2, self.data, self.back_calc, self.back_calc_grad,
              self.errors)

        # Assert, to a precision of 13 decimal places, that the gradient is [0, 10].
        self.assertAlmostEqual(grad[0], 0.0, places=13)
        self.assertAlmostEqual(grad[1], 10.0, places=13)

        # Delete the gradient data.
        del grad
Esempio n. 3
0
    def func_exp_chi2_grad(self, params=None, times=None, values=None, errors=None):
        """Target function for the gradient (Jacobian matrix) to minfx, for exponential fit .

        @param params:  The vector of parameter values.
        @type params:   numpy rank-1 float array
        @keyword times: The time points.
        @type times:    numpy array
        @param values:  The measured values.
        @type values:   numpy array
        @param errors:  The standard deviation of the measured intensity values per time point.
        @type errors:   numpy array
        @return:        The Jacobian matrix with 'm' rows of function derivatives per 'n' columns of parameters, which have been summed together.
        @rtype:         numpy array
        """

        # Get the back calc.
        back_calc = self.func_exp(params=params, times=times)

        # Get the Jacobian, with partial derivative, with respect to r2eff and i0.
        exp_grad = self.func_exp_grad(params=params, times=times)

        # Transpose back, to get rows.
        exp_grad_t = transpose(exp_grad)

        # n is number of fitted parameters.
        n = len(params)

        # Define array to update parameters in.
        jacobian_chi2_minfx = zeros([n])

        # Update value elements.        
        dchi2(dchi2=jacobian_chi2_minfx, M=n, data=values, back_calc_vals=back_calc, back_calc_grad=exp_grad_t, errors=errors)

        # Return Jacobian matrix.
        return jacobian_chi2_minfx
Esempio n. 4
0
    def func_exp_chi2_grad(self,
                           params=None,
                           times=None,
                           values=None,
                           errors=None):
        """Target function for the gradient (Jacobian matrix) to minfx, for exponential fit .

        @param params:  The vector of parameter values.
        @type params:   numpy rank-1 float array
        @keyword times: The time points.
        @type times:    numpy array
        @param values:  The measured values.
        @type values:   numpy array
        @param errors:  The standard deviation of the measured intensity values per time point.
        @type errors:   numpy array
        @return:        The Jacobian matrix with 'm' rows of function derivatives per 'n' columns of parameters, which have been summed together.
        @rtype:         numpy array
        """

        # Get the back calc.
        back_calc = self.func_exp(params=params, times=times)

        # Get the Jacobian, with partial derivative, with respect to r2eff and i0.
        exp_grad = self.func_exp_grad(params=params, times=times)

        # Transpose back, to get rows.
        exp_grad_t = transpose(exp_grad)

        # n is number of fitted parameters.
        n = len(params)

        # Define array to update parameters in.
        jacobian_chi2_minfx = zeros([n])

        # Update value elements.
        dchi2(dchi2=jacobian_chi2_minfx,
              M=n,
              data=values,
              back_calc_vals=back_calc,
              back_calc_grad=exp_grad_t,
              errors=errors)

        # Return Jacobian matrix.
        return jacobian_chi2_minfx