Package target_functions :: Module chi2
[hide private]
[frames] | no frames]

Module chi2

source code

Module containing functions for calculating the chi-squared value, gradient, and Hessian.

Functions [hide private]
float
chi2(data, back_calc_vals, errors)
Function to calculate the chi-squared value.
source code
 
dchi2(dchi2, M, data, back_calc_vals, back_calc_grad, errors)
Calculate the full chi-squared gradient.
source code
float
dchi2_element(data, back_calc_vals, back_calc_grad_j, errors)
Calculate the chi-squared gradient element j.
source code
 
d2chi2(d2chi2, M, data, back_calc_vals, back_calc_grad, back_calc_hess, errors)
Calculate the full chi-squared Hessian.
source code
float
d2chi2_element(data, back_calc_vals, back_calc_grad_j, back_calc_grad_k, back_calc_hess_jk, errors)
Calculate the chi-squared Hessian element {j, k}.
source code
Variables [hide private]
  __package__ = 'target_functions'

Imports: dot, sum, transpose


Function Details [hide private]

chi2(data, back_calc_vals, errors)

source code 

Function to calculate the chi-squared value.

The chi-squared equation

The equation is:

                   _n_
                   \    (yi - yi(theta)) ** 2
   chi^2(theta)  =  >   ---------------------
                   /__      sigma_i ** 2
                   i=1

where

  • i is the index over data sets.
  • theta is the parameter vector.
  • yi are the values of the measured data set.
  • yi(theta) are the values of the back calculated data set.
  • sigma_i are the values of the error set.
Parameters:
  • data (numpy rank-1 size N array) - The vector of yi values.
  • back_calc_vals (numpy rank-1 size N array) - The vector of yi(theta) values.
  • errors (numpy rank-1 size N array) - The vector of sigma_i values.
Returns: float
The chi-squared value.

dchi2(dchi2, M, data, back_calc_vals, back_calc_grad, errors)

source code 

Calculate the full chi-squared gradient.

The chi-squared gradient

The equation is:

                        _n_
   dchi^2(theta)        \   / yi - yi(theta)     dyi(theta) \ 
   -------------  =  -2  >  | --------------  .  ---------- |
      dthetaj           /__ \   sigma_i**2        dthetaj   /
                        i=1

where

  • i is the index over data sets.
  • j is the parameter index of the gradient.
  • theta is the parameter vector.
  • yi are the values of the measured data set.
  • yi(theta) are the values of the back calculated data set.
  • dyi(theta)/dthetaj are the values of the back calculated gradient for parameter j.
  • sigma_i are the values of the error set.
Parameters:
  • dchi2 (numpy rank-1 size M array) - The chi-squared gradient data structure to place the gradient elements into.
  • M (int) - The dimensions of the gradient.
  • data (numpy rank-1 size N array) - The vector of yi values.
  • back_calc_vals (numpy rank-1 size N array) - The vector of yi(theta) values.
  • back_calc_grad (numpy rank-2 size MxN array) - The matrix of dyi(theta)/dtheta values.
  • errors (numpy rank-1 size N array) - The vector of sigma_i values.

dchi2_element(data, back_calc_vals, back_calc_grad_j, errors)

source code 

Calculate the chi-squared gradient element j.

The chi-squared gradient

The equation is:

                        _n_
   dchi^2(theta)        \   / yi - yi(theta)     dyi(theta) \ 
   -------------  =  -2  >  | --------------  .  ---------- |
      dthetaj           /__ \   sigma_i**2        dthetaj   /
                        i=1

where

  • i is the index over data sets.
  • j is the parameter index of the gradient.
  • theta is the parameter vector.
  • yi are the values of the measured data set.
  • yi(theta) are the values of the back calculated data set.
  • dyi(theta)/dthetaj are the values of the back calculated gradient for parameter j.
  • sigma_i are the values of the error set.
Parameters:
  • data (numpy rank-1 size N array) - The vector of yi values.
  • back_calc_vals (numpy rank-1 size N array) - The vector of yi(theta) values.
  • back_calc_grad_j (numpy rank-1 size N array) - The vector of dyi(theta)/dthetaj values for parameter j.
  • errors (numpy rank-1 size N array) - The vector of sigma_i values.
Returns: float
The chi-squared gradient element j.

d2chi2(d2chi2, M, data, back_calc_vals, back_calc_grad, back_calc_hess, errors)

source code 

Calculate the full chi-squared Hessian.

The chi-squared Hessian

The equation is:

                         _n_
   d2chi^2(theta)        \       1      / dyi(theta)   dyi(theta)                        d2yi(theta)   \ 
   ---------------  =  2  >  ---------- | ---------- . ----------  -  (yi-yi(theta)) . --------------- |
   dthetaj.dthetak       /__ sigma_i**2 \  dthetaj      dthetak                        dthetaj.dthetak /
                         i=1

where

  • i is the index over data sets.
  • j is the parameter index for the first dimension of the Hessian.
  • k is the parameter index for the second dimension of the Hessian.
  • theta is the parameter vector.
  • yi are the values of the measured data set.
  • yi(theta) are the values of the back calculated data set.
  • dyi(theta)/dthetaj are the values of the back calculated gradient for parameter j.
  • d2yi(theta)/dthetaj.dthetak are the values of the back calculated Hessian for the parameters j and k.
  • sigma_i are the values of the error set.
Parameters:
  • d2chi2 (numpy rank-2 size MxM array) - The chi-squared Hessian data structure to place the Hessian elements into.
  • M (int) - The size of the first dimension of the Hessian.
  • data (numpy rank-1 size N array) - The vector of yi values.
  • back_calc_vals (numpy rank-1 size N array) - The vector of yi(theta) values.
  • back_calc_grad (numpy rank-2 size MxN array) - The matrix of dyi(theta)/dtheta values.
  • back_calc_hess (numpy rank-3 size MxMxN array) - The matrix of d2yi(theta)/dtheta.dtheta values.
  • errors (numpy rank-1 size N array) - The vector of sigma_i values.

d2chi2_element(data, back_calc_vals, back_calc_grad_j, back_calc_grad_k, back_calc_hess_jk, errors)

source code 

Calculate the chi-squared Hessian element {j, k}.

The chi-squared Hessian

The equation is:

                         _n_
   d2chi^2(theta)        \       1      / dyi(theta)   dyi(theta)                        d2yi(theta)   \ 
   ---------------  =  2  >  ---------- | ---------- . ----------  -  (yi-yi(theta)) . --------------- |
   dthetaj.dthetak       /__ sigma_i**2 \  dthetaj      dthetak                        dthetaj.dthetak /
                         i=1

where

  • i is the index over data sets.
  • j is the parameter index for the first dimension of the Hessian.
  • k is the parameter index for the second dimension of the Hessian.
  • theta is the parameter vector.
  • yi are the values of the measured data set.
  • yi(theta) are the values of the back calculated data set.
  • dyi(theta)/dthetaj are the values of the back calculated gradient for parameter j.
  • d2yi(theta)/dthetaj.dthetak are the values of the back calculated Hessian for the parameters j and k.
  • sigma_i are the values of the error set.
Parameters:
  • data (numpy rank-1 size N array) - The vector of yi values.
  • back_calc_vals (numpy rank-1 size N array) - The vector of yi(theta) values.
  • back_calc_grad_j (numpy rank-1 size N array) - The vector of dyi(theta)/dthetaj values for parameter j.
  • back_calc_grad_k (numpy rank-1 size N array) - The vector of dyi(theta)/dthetak values for parameter k.
  • back_calc_hess_jk (numpy rank-1 size N array) - The vector of d2yi(theta)/dthetaj.dthetak values at {j, k}.
  • errors (numpy rank-1 size N array) - The vector of sigma_i values.
Returns: float
The chi-squared Hessian element {j,k}.