|
mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Class to manage fitting a 2D Gaussian to data via the levmarInterface.
Can fit either the symmetric Gaussian, or the rotated asymmetric Gaussian. Individual parameters can be fixed, except in the asymmetric case \(\sigma_x, \sigma_y, \theta\) must currently be fixed together.
In addition to the requirements on fitterT specified by levmarInterface this class also requires the following in fitterT
| fitterT | a type meeting the above requirements. |
Definition at line 301 of file fitGaussian.hpp.
#include <math/fit/fitGaussian.hpp>
Inheritance diagram for mx::math::fit::fitGaussian2D< fitterT >:Public Member Functions | |
| void | setFixed (bool G0, bool G, bool x0, bool y0, bool sigma_x, bool sigma_y, bool theta) |
| Set whether each parameter is fixed. | |
| void | setFixed (bool G0, bool G, bool x0, bool y0, bool sigma) |
| Set whether each parameter is fixed. | |
| void | setGuess (realT G0, realT G, realT x0, realT y0, realT sigma) |
| Set the initial guess for a symmetric Gaussian. | |
| void | setGuess (realT G0, realT G, realT x0, realT y0, realT sigma_x, realT sigma_y, realT theta) |
| Set the initial guess for the general Gaussian. | |
| void | setArray (realT *data, int nx, int ny) |
| Set the data aray. | |
| void | setArray (realT *data, int nx, int ny, realT *mask) |
| Set the data aray, with a mask. | |
| 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 | y0 () |
| Get the center y-coordinate. | |
| realT | sigma () |
| Return the width parameter. | |
| realT | fwhm () |
| Return the full-width at half maximum. | |
| realT | sigma_x () |
| Return the width parameter on the long axis. | |
| realT | sigma_y () |
| Return the width parameter on the short axis. | |
| realT | theta () |
| Return the orientation of the long axis. | |
Public Member Functions inherited from mx::math::fit::levmarInterface< fitterT > | |
| levmarInterface () | |
| Default constructor. | |
| levmarInterface (realT *i_p, realT *i_x, int i_m, int i_n, void *i_adata) | |
| Setup constructor. | |
| ~levmarInterface () | |
| Destructor. | |
| void | nParams (int i_m) |
| Set number of parameters, but don't allocate. | |
| int | nParams () |
| Get the current number of parameters. | |
| void | allocate_params () |
| Allocate parameters array based on previous call to nParams. | |
| void | allocate_params (int i_m) |
| Set number of parameters and allocate. | |
| void | point_params (realT *i_p) |
| Point the parameter pointer at an externally allocated array. | |
| void | point_params (realT *i_p, int i_m) |
| 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. | |
| template<typename iosT , char comment = '#'> | |
| iosT & | dumpParameters (iosT &ios) |
| Output current parameters to a stream. | |
| template<char comment = '#'> | |
| std::ostream & | dumpParameters () |
| Dump the parameter vector to stdout. | |
| template<typename iosT , char comment = '#'> | |
| iosT & | dumpReport (iosT &ios, bool dumpParams=true) |
| Output current parameters to a stream. | |
| template<char comment = '#'> | |
| std::ostream & | dumpReport (bool dumpParams=true) |
| Dump a status report to stdout. | |
Public Attributes | |
| array2FitGaussian2D< realT > | arr |
Public Attributes inherited from mx::math::fit::levmarInterface< fitterT > | |
| 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. | |
Additional Inherited Members | |
Protected Attributes inherited from mx::math::fit::levmarInterface< fitterT > | |
| 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. | |
|
inline |
Do the fit.
Definition at line 441 of file fitGaussian.hpp.
References mx::math::fit::levmarInterface< fitterT >::fit(), and mx::math::six_fifths().
Referenced by SCENARIO().
|
inline |
Return the full-width at half maximum.
This is a simple scaling of the sigma() result
Definition at line 495 of file fitGaussian.hpp.
References mx::math::func::sigma2fwhm(), and mx::math::six_fifths().
|
inline |
Get the peak scaling.
Definition at line 465 of file fitGaussian.hpp.
|
inline |
Get the current value of G0, the constant.
Definition at line 459 of file fitGaussian.hpp.
|
inline |
Set the data aray.
| [in] | data | The 2D array of data to fit. |
| [in] | nx | the x size of the data |
| [in] | ny | the y size of the data |
Definition at line 402 of file fitGaussian.hpp.
Referenced by SCENARIO().
|
inline |
Set the data aray, with a mask.
| [in] | data | The 2D array of data to fit. |
| [in] | nx | the x size of the data |
| [in] | ny | the y size of the data |
| [in] | mask | Array of same size as data. Any 0 pixels in this array will be excluded from the fit. |
Definition at line 415 of file fitGaussian.hpp.
References mx::math::six_fifths().
|
inline |
Set whether each parameter is fixed.
Sets the parameter indices appropriately.
| [in] | G0 | if true, then G0 will be not be part of the fit |
| [in] | G | if true, then G will be not be part of the fit |
| [in] | x0 | if true, then x0 will be not be part of the fit |
| [in] | y0 | if true, then y0 will be not be part of the fit |
| [in] | sigma | if true, then sigma will be not be part of the fit |
Definition at line 353 of file fitGaussian.hpp.
|
inline |
Set whether each parameter is fixed.
Sets the parameter indices appropriately.
| [in] | G0 | if true, then G0 will be not be part of the fit |
| [in] | G | if true, then G will be not be part of the fit |
| [in] | x0 | if true, then x0 will be not be part of the fit |
| [in] | y0 | if true, then y0 will be not be part of the fit |
| [in] | sigma_x | if true, then sigma_x will be not be part of the fit |
| [in] | sigma_y | if true, then sigma_y will be not be part of the fit |
| [in] | theta | if true, then theta will be not be part of the fit |
Definition at line 337 of file fitGaussian.hpp.
|
inline |
Set the initial guess for a symmetric Gaussian.
Also works for the general case, setting the same width in both directions.
| [in] | G0 | the constant background level |
| [in] | G | the peak scaling |
| [in] | x0 | the center x-coordinate |
| [in] | y0 | the center y-coordinate |
| [in] | sigma | the width parameter |
Definition at line 367 of file fitGaussian.hpp.
Referenced by SCENARIO().
|
inline |
Set the initial guess for the general Gaussian.
| [in] | G0 | the constant background level |
| [in] | G | the peak scaling |
| [in] | x0 | the center x-coordinate |
| [in] | y0 | the center y-coordinate |
| [in] | sigma_x | the width parameter in the rotated x-direction (the long axis) |
| [in] | sigma_y | the width parameter in the rotated y-direction |
| [in] | theta | the angle of the long axis (always sigma_x) |
Definition at line 382 of file fitGaussian.hpp.
|
inline |
Return the width parameter.
As described for the symmetric Gaussian.
For the general Gaussian, this returns \( \sigma = \sqrt{ \sigma_x^2 + \sigma_y^2} \).
Definition at line 487 of file fitGaussian.hpp.
|
inline |
Return the width parameter on the long axis.
Definition at line 501 of file fitGaussian.hpp.
|
inline |
Return the width parameter on the short axis.
Definition at line 507 of file fitGaussian.hpp.
|
inline |
Return the orientation of the long axis.
Definition at line 513 of file fitGaussian.hpp.
|
inline |
Get the center x-coordinate.
Definition at line 471 of file fitGaussian.hpp.
Referenced by SCENARIO().
|
inline |
Get the center y-coordinate.
Definition at line 477 of file fitGaussian.hpp.
Referenced by SCENARIO().
| array2FitGaussian2D<realT> mx::math::fit::fitGaussian2D< fitterT >::arr |
Data array to pass to the levmar library. Contains the actual data plus the parameters if fixed.
Definition at line 308 of file fitGaussian.hpp.