DecompLib
A simple library for decomposition of spectra using a response matrix.
Decomposition Functions

Functions used to decompose the input spectrum. More...

Functions

template<typename ParamType >
long long performDecomposition (DataVector< ParamType > &data, RespMatrix< ParamType > &respMatrix, DecompVector< ParamType > &paramSet, ParamType minThresh=1e-6, ParamType convThresh=0.005, bool printBadSafety=true)
 Performs a decomposition of data using respMatrix and the initial guess in paramSet, it then outputs the result in paramSet. More...
 
template<typename ParamType >
bool testConvergence (ParamType *oldVals, ParamType *newVals, int numRespFuncs, ParamType minThresh, ParamType convThresh)
 Tests if two parameter sets vary more than convThresh. More...
 
template<typename ParamType >
int testSafety (DataVector< ParamType > &data, RespMatrix< ParamType > &respMatrix, DecompVector< ParamType > &paramSet, ParamType minThresh, ParamType convThresh, bool printBadSafety=true)
 Tests the inputs that would go into performDecomposition for safety. More...
 

Detailed Description

Functions used to decompose the input spectrum.

The function performDecomposition takes the inputs and iterates until it has attained convergence.

testConvergence is used by performDecomposition to check if it has obtained convergence in that iteration

Function Documentation

template<typename ParamType >
long long performDecomposition ( DataVector< ParamType > &  data,
RespMatrix< ParamType > &  respMatrix,
DecompVector< ParamType > &  paramSet,
ParamType  minThresh = 1e-6,
ParamType  convThresh = 0.005,
bool  printBadSafety = true 
)

Performs a decomposition of data using respMatrix and the initial guess in paramSet, it then outputs the result in paramSet.

Template Parameters
ParamTypeThe floating point type that is to be used for the calculations
Parameters
dataThe DataVector with the spectrum to be decomposed
respMatrixThe RespMatrix which holds the set of response functions to use to decompose the data spectrum
paramSetThe DecompVector which contains the initial guess and will contain the final decomposition parameters
minThreshThe value below which parameters are not tested for determining convergence defaults to 1.0e-6
convThreshThe maximum fractional change between iterations allowed before parameters are considered unconverged defaults to 0.005
printBadSafetyPrint what failed in a safety check
Returns
The number of iterations, or negative values for errors
Error Value Description
-1 A row or column of the response matrix contains all zeros
-2 One of the initial decomposition parameters is less than or equal to zero
-3 The data vector is either all zeros or contains one or more negative numbers
-4 The number of bins in the input spectrum is not the same as the number of bins in a response function
-5 The number of response functions is not the same as the number of bins in the DecompVector
-6 The minimum value to be tested for convergence is less than or equal to zero
-7 The maximum change allowed to be considered converged is less than or equal to zero
-8 The number of bins in the input spectrum does not exceed the number of response functions
This function uses the expectation maximization algorithm in "J. Tain, D. Cano-Ott, Algorithms for the analysis of beta-decay total absorption spectra, NIMA 571 (3) (2007) 728-738" The iterative formula presented in Equation 20 of that paper can be seen below (with the paper's indexing errors corrected).

\[ f_{\mu}^{(s+1)} = \frac{1}{\sum\limits_{j}R_{\mu{}j}} \sum\limits_{i}\frac{f_{\mu{}}^{(s)} R_{\mu{}i}d_i}{\sum\limits_{\alpha}R_{\alpha{}i}f_{\alpha}^{(s)}} \]

Where \(f_{\mu}^{(s+1)}\) contains the decomposition weights / spectrum for iteration \((s+1)\), \(R_{\mu{}\nu{}}\) contains the response matrix, and \(d_{i}\) contains the initial spectrum to be decomposed.

The formula above is slightly rearranged to yield the algorithm used in the function below.

Definition at line 62 of file Decomposition.h.

References DataVector< ParamType >::getElement(), DecompVector< ParamType >::getElement(), RespMatrix< ParamType >::getMatrixPtr(), RespMatrix< ParamType >::getNumRespFuncs(), RespMatrix< ParamType >::getRespFuncsLens(), RespMatrix< ParamType >::getSummedRowPtr(), RespMatrix< ParamType >::getTransposePtr(), DecompVector< ParamType >::setElement(), testConvergence(), and testSafety().

template<typename ParamType >
bool testConvergence ( ParamType *  oldVals,
ParamType *  newVals,
int  numRespFuncs,
ParamType  minThresh,
ParamType  convThresh 
)

Tests if two parameter sets vary more than convThresh.

Template Parameters
ParamTypeThe floating point type contained in the arrays of values to check for convergence
Parameters
oldValsThe array of parameters at the beginning of the current iteration
newValsThe array of parameters at the end of the current iteration
numRespFuncsThe number of response functions for the decomposition / the length of oldVals and newVals
minThreshThe value that causes a parameter to be ignored if both the old and new val sets have a parameter whose value is below minThresh it is not considered for determining convergence
convThreshThe maximum fractional change allowed before a pair of parameters are considered un-converged

Definition at line 34 of file Helper.h.

Referenced by performDecomposition().

template<typename ParamType >
int testSafety ( DataVector< ParamType > &  data,
RespMatrix< ParamType > &  respMatrix,
DecompVector< ParamType > &  paramSet,
ParamType  minThresh,
ParamType  convThresh,
bool  printBadSafety = true 
)

Tests the inputs that would go into performDecomposition for safety.

Template Parameters
ParamTypeThe floating point type that is to be used for the calculations
Parameters
dataThe DataVector with the spectrum to be decomposed
respMatrixThe RespMatrix which holds the set of response functions to use to decompose the data spectrum
paramSetThe DecompVector which contains the initial guess and will contain the final decomposition parameters
minThreshThe value below which parameters are not tested for determining convergence defaults to 1.0e-6
convThreshThe maximum fractional change between iterations allowed before parameters are considered unconverged defaults to 0.005
printBadSafetyPrint what failed in a safety check
Returns
Negative values for errors, zero otherwise
Error Value Description
-1 A row or column of the response matrix contains all zeros
-2 One of the initial decomposition parameters is less than or equal to zero
-3 The data vector is either all zeros or contains one or more negative numbers
-4 The number of bins in the input spectrum is not the same as the number of bins in a response function
-5 The number of response functions is not the same as the number of bins in the DecompVector
-6 The minimum value to be tested for convergence is less than or equal to zero
-7 The maximum change allowed to be considered converged is less than or equal to zero
-8 The number of bins in the input spectrum does not exceed the number of response functions

Definition at line 79 of file Helper.h.

References DataVector< ParamType >::getLength(), DecompVector< ParamType >::getLength(), RespMatrix< ParamType >::getNumRespFuncs(), RespMatrix< ParamType >::getRespFuncsLens(), DataVector< ParamType >::isSafe(), DecompVector< ParamType >::isSafe(), and RespMatrix< ParamType >::isSafe().

Referenced by performDecomposition().