mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
mx::math::fit::fitGaussian1D< _realT > Class Template Reference

template<typename _realT>
class mx::math::fit::fitGaussian1D< _realT >

Class to manage fitting a 1D Gaussian to data via the levmarInterface.

Fits the following function to the data: \( G(x) = G_0 + G\exp[-(0.5/\sigma^2)((x-x_0)^2)]\)

Can use a vector of x-coordinates, or use the array index as the position corresponding to each y-value. A mask can be provided, where any 0 entries cause that position to be ignored.

Any of the parameters can be fixed, and not included in the fit.

Template Parameters
fitterTa type meeting the above requirements.

Definition at line 144 of file fitGaussian.hpp.

#include <math/fit/fitGaussian.hpp>

Inheritance diagram for mx::math::fit::fitGaussian1D< _realT >:

Public Member Functions

void setFixed (bool G0, bool G, bool x0, bool sigma)
 Set whether each parameter is fixed.
void setGuess (realT G0, realT G, realT x0, realT sigma)
 Set the initial guess for a symmetric Gaussian.
void setArray (realT *data, int nx)
 Set the data aray.
void setArray (realT *data, realT *coords, int nx)
 Set the data aray.
int fit ()
 Do the fit.
realT G0 ()
 Get the current value of G0, the constant.
realT G ()
 Get the peak scaling.
realT x0 ()
 Get the center x-coordinate.
realT sigma ()
 Return sigma.
Public Member Functions inherited from mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >
 levmarInterface ()
 Default constructor.
 ~levmarInterface ()
 Destructor.
void nParams (int i_m)
 Set number of parameters, but don't allocate.
void allocate_params ()
 Allocate parameters array based on previous call to nParams.
void point_params (realT *i_p)
 Point the parameter pointer at an externally allocated array.
void set_params (realT *i_p)
 Copy parameters to the parameter array.
realT * get_params ()
 Get current pointer array address.
void set_itmax (int i_itmax)
 Set the maximum number of iterations.
int get_itmax ()
 Get the maximum number of iterations.
void allocate_work ()
 Allocate the work and covar matrices.
void set_opts (int n, realT val)
 Set one of the minimization options to val.
void set_opts_default (int n=-1)
 Set one or all of the minimization options to the default.
realT get_opts (int n)
 Get the current value of an option.
int fit ()
 Perform the fit.
realT get_initial_norm ()
 Returns the L2-norm before minimization occurs.
realT get_final_norm ()
 Returns the L2-norm at the end of the minimization.
int get_iterations ()
 Get the number of iterations taken during the minimization.
int get_reason_code ()
 Get a code specifying the reason minimization terminated.
std::string get_reason_string ()
 Get the descriptive string describing the reason minimization terminated.
int get_fevals ()
 Get the number of function evaluations during the minimization.
int get_jevals ()
 Get the number of jacobian evaluations during the minimization.
int get_nlinsys ()
 Get the number of linear system solutions during the minimization.
double get_deltaT ()
 Get the elapsed time of the fit.
iosT & dumpParameters (iosT &ios)
 Output current parameters to a stream.
iosT & dumpReport (iosT &ios, bool dumpParams=true)
 Output current parameters to a stream.

Additional Inherited Members

Public Attributes inherited from mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >
realT * x
 I: measurement vector. NULL implies a zero vector.
int n
 I: measurement vector dimension.
realT opts [LM_OPTS_SZ]
 Options passed to the minimization routines. See set_opts for details.
realT info [LM_INFO_SZ]
 Information regarding the minimization.
double deltaT
 Elapsed time of the fitting procedure.
realT * work
 Working memory passed to the levmar routines.
int work_sz
 The current size of the work array.
realT * covar
 Covariance matrix corresponding to LS solution; mxm.
int covar_sz
 The current size of the covar array.
bool getCovar
 Controls whether the covar array is allocated.
void * adata
 Pointer to possibly additional data, passed uninterpreted to func & jacf.
Protected Attributes inherited from mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >
realT * p
 Parameter array. On input is the initial estimates. On output has the estimated solution.
realT * init_p
 Parameter array on input, saved for comparison.
int m
 Parameter vector dimension (i.e. number of unknowns).
bool own_p
 Flag indicating whether the p array is owned by this object (for de-allocation).
int itmax
 Maximum number of iterations, default is 100.

Member Function Documentation

◆ fit()

template<typename _realT>
int mx::math::fit::fitGaussian1D< _realT >::fit ( )
inline

Do the fit.

Definition at line 218 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< fitterT >::fit().

◆ G()

template<typename _realT>
realT mx::math::fit::fitGaussian1D< _realT >::G ( )
inline

Get the peak scaling.

Definition at line 235 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::p.

Referenced by setFixed(), and setGuess().

◆ G0()

template<typename _realT>
realT mx::math::fit::fitGaussian1D< _realT >::G0 ( )
inline

Get the current value of G0, the constant.

Returns
the current value of G0, which is p[0].

Definition at line 229 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::p.

Referenced by setFixed(), and setGuess().

◆ setArray() [1/2]

template<typename _realT>
void mx::math::fit::fitGaussian1D< _realT >::setArray ( realT * data,
int nx )
inline

Set the data aray.

Definition at line 199 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::n.

◆ setArray() [2/2]

template<typename _realT>
void mx::math::fit::fitGaussian1D< _realT >::setArray ( realT * data,
realT * coords,
int nx )
inline

Set the data aray.

Definition at line 208 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::n.

◆ setFixed()

template<typename _realT>
void mx::math::fit::fitGaussian1D< _realT >::setFixed ( bool G0,
bool G,
bool x0,
bool sigma )
inline

Set whether each parameter is fixed.

Sets the parameter indices appropriately.

Parameters
[in]G0if true, then G0 will be not be part of the fit
[in]Gif true, then G will be not be part of the fit
[in]x0if true, then x0 will be not be part of the fit
[in]sigmaif true, then sigma will be not be part of the fit

Definition at line 173 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::allocate_params(), G(), G0(), sigma(), and x0().

◆ setGuess()

template<typename _realT>
void mx::math::fit::fitGaussian1D< _realT >::setGuess ( realT G0,
realT G,
realT x0,
realT sigma )
inline

Set the initial guess for a symmetric Gaussian.

Also works for the general case, setting the same width in both directions.

Parameters
[in]G0the constant background level
[in]Gthe peak scaling
[in]x0the center x-coordinate
[in]sigmathe width parameter

Definition at line 186 of file fitGaussian.hpp.

References G(), G0(), mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::p, sigma(), and x0().

◆ sigma()

template<typename _realT>
realT mx::math::fit::fitGaussian1D< _realT >::sigma ( )
inline

Return sigma.

Definition at line 249 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::p.

Referenced by setFixed(), and setGuess().

◆ x0()

template<typename _realT>
realT mx::math::fit::fitGaussian1D< _realT >::x0 ( )
inline

Get the center x-coordinate.

Definition at line 241 of file fitGaussian.hpp.

References mx::math::fit::levmarInterface< gaussian1D_fitter< _realT > >::p.

Referenced by setFixed(), and setGuess().


The documentation for this class was generated from the following file: