Loading...
Searching...
No Matches
casacore::GaussianNDParam< T > Class Template Reference
Functionals_module_internal_classes

More...

`#include <GaussianNDParam.h>`

## Public Types

enum | { HEIGHT , CENTER }
Public Types inherited from casacore::Function< T, U >
typedef FunctionTraits< T >::ArgType | ArgType
typedef const ArgType * | FunctionArg

## Public Member Functions

| GaussianNDParam ()
| Constructs a Gaussian using the indicated height, mean, variance & covariance.
| GaussianNDParam (uInt ndim)
| GaussianNDParam (uInt ndim, const T &height)
| GaussianNDParam (uInt ndim, const T &height, const Vector< T > &mean)
| GaussianNDParam (uInt ndim, const T &height, const Vector< T > &mean, const Vector< T > &variance)
| GaussianNDParam (uInt ndim, const T &height, const Vector< T > &mean, const Matrix< T > &covar)
| GaussianNDParam (const GaussianNDParam &other)
| Copy constructor (deep copy).
template<class W>
| GaussianNDParam (const GaussianNDParam< W > &other)
GaussianNDParam< T > & | operator= (const GaussianNDParam< T > &other)
| Copy assignment (deep copy).
virtual | ~GaussianNDParam ()
| Destructor.
virtual const String & | name () const
| Give name of function.
virtual uInt | ndim () const
| Variable dimensionality.
T | height () const
| Get or set the peak height of the Gaussian.
void | setHeight (const T &height)
T | flux () const
| The analytical integrated area underneath the Gaussian.
void | setFlux (const T &flux)
Vector< T > | mean () const
| The center ordinate of the Gaussian.
void | setMean (const Vector< T > &mean)
Vector< T > | variance () const
| The FWHM of the Gaussian is sqrt(8*variance*log(2)).
void | setVariance (const Vector< T > &variance)
Matrix< T > | covariance () const
| The covariance Matrix defines the correlations between all the axes.
void | setCovariance (const Matrix< T > &covar)
Public Member Functions inherited from casacore::Function< T, U >
| Function ()
| Constructors.
| Function (const uInt n)
| Function (const Vector< T > &in)
| Function (const FunctionParam< T > &other)
template<class W, class X>
| Function (const Function< W, X > &other)
virtual | ~Function ()
| Destructor.
uInt | nparameters () const
| Returns the number of parameters.
virtual U | eval (FunctionArg x) const =0
| Evaluate the function object.
T & | operator[] (const uInt n)
| Manipulate the nth parameter (0-based) with no index check.
const T & | operator[] (const uInt n) const
virtual U | operator() () const
| Evaluate this function object at xor at x, y.
virtual U | operator() (const ArgType &x) const
virtual U | operator() (const Vector< ArgType > &x) const
virtual U | operator() (FunctionArg x) const
virtual U | operator() (const ArgType &x, const ArgType &y) const
virtual U | operator() (const ArgType &x, const ArgType &y, const ArgType &z) const
Bool & | mask (const uInt n)
| Manipulate the mask associated with the nth parameter (e.g.
const Bool & | mask (const uInt n) const
const FunctionParam< T > & | parameters () const
| Return the parameter interface.
FunctionParam< T > & | parameters ()
const Vector< ArgType > & | argp () const
| Get arg_p and parset_p.
Bool | parsetp () const
void | lockParam ()
| Compiler cannot always find the correct 'const' version of parameter access.
void | unlockParam ()
virtual void | setMode (const RecordInterface &mode)
| get/set the function mode.
virtual void | getMode (RecordInterface &mode) const
virtual Bool | hasMode () const
| return True if the implementing function supports a mode.
ostream & | print (ostream &os) const
| Print the function (i.e.
virtual Function< T, U > * | clone () const =0
| Return a copy of this object from the heap.
virtual Function< typename FunctionTraits< T >::DiffType > * | cloneAD () const
virtual Function< typename FunctionTraits< T >::BaseType > * | cloneNonAD () const
Public Member Functions inherited from casacore::Functional< FunctionTraits< T >::ArgType, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const FunctionTraits< T >::ArgType &x) const=0
| Map a Domain x into a Range y value.
Public Member Functions inherited from casacore::Functional< Vector< FunctionTraits< T >::ArgType >, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const Vector< FunctionTraits< T >::ArgType > &x) const=0
| Map a Domain x into a Range y value.

## Protected Member Functions

void | repack (Matrix< T > &covar) const
| Functions to convert between internal Vector of parameters and the Covariance Matrix.
void | unpack (const Matrix< T > &covar)

## Protected Attributes

uInt | itsDim
| dimensionality
T | itsFlux2Hgt
| factor to convert from flux to height
Protected Attributes inherited from casacore::Function< T, U >
FunctionParam< T > | param_p
| The parameters and masks.
Vector< ArgType > | arg_p
| Aid for non-contiguous argument storage.
Bool | parset_p
| Indicate parameter written.
Bool | locked_p
| Indicate that parameters are expected to be locked from changing.

## Detailed Description

template<class T>
class casacore::GaussianNDParam< T >

A Multi-dimensional Gaussian parameter handling.

### Intended use:

Internal

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25
Test programs:
  tGaussianND
Demo programs:
  dGaussianND

### Prerequisite

- FunctionParam class
- Function class

### Synopsis

A GaussianND is used to calculate Gaussian functions of any dimension. A Gaussian1D class exists which is more appropriate for one dimensional Gaussian functions, and a Gaussian2D class exists for two dimensional functions.

A statistical description of the multi-dimensional Gaussian is used (see Kendall & Stuart "The Advanced Theory of Statistics"). A Gaussian is defined in terms of its height, mean (which is the location of the peak value), variance, (a measure of the width of the Gaussian), and covariance which skews the distribution with respect to the Axes.

In the general description the variance and covariance are specified using a covariance matrix. This is defined as (for a 4 dimensional Gaussian):

V = | s1*s1 r12*s1*s2 r13*s1*s3 r14*s1*s4 |
| r12*s1*s2 s2*s2 r23*s2*s3 r24*s2*s4 |
| r13*s1*s3 r23*s2*s3 s3*s3 r34*s3*s4 |
| r14*s1*s4 r24*s2*s4 r34*s3*s4 s4*s4 |

where s1 (sigma1) is the standard deviation of the Gaussian with respect to the first axis, and r12 (rho12) is the correlation between the the first and second axis. The correlation MUST be between -1 and 1, and this class checks this as well as ensuring that the diagonal is positive.

Warning: It is possible to have symmetric matrices that are of the above described form (ie; symmetric with -1 <= rho(ij) <=1) that do not generate a Gaussian function; This is because the Matrix is NOT positive definite (The limits on rho(ij) are upper limits); This class does check that the covariance Matrix is positive definite and will throw an exception (AipsError) if it is not;

The covariance Matrix can be specified by only its upper or lower triangular regions (ie. with zeros in the other triangle), otherwise it MUST be symmetric.

The Gaussian that is constructed from this covariance Matrix (V), along with mean (u) and height (h) is:

f(x) = h*exp(-1/2 * (x-u) * V^(-1) * (x-u))
casacore::exp
LatticeExprNode exp(const LatticeExprNode &expr)

where x, and u are vectors whose length is the dimensionality of the Gaussian and V^(-1) is the inverse of the covariance Matrix defined above. For a two dimensional Gaussian with zero mean this expression reduces to:

f(x) = h*exp(-1/(2*(1-r12^2))*(x1^2/s1^2 - 2*r12*x1*x2/(s1*s2) + x2^2/s2^2))

The amplitude of the Gaussian can be defined in two ways, either using the peak height (as is done in the constructors, and the setHeight function) or using the setFlux function. The flux in this context is the analytic integral of the Gaussian over all dimensions. Using the setFlux function does not modify the shape of the Gaussian just its height.

All the parameters of the Gaussian except its dimensionality can be modified using the set/get functions.

The parameter interface (see FunctionParam class), is used to provide an interface to the Fitting classes. There are always 4 parameter sets.
Warning: Note that the actual variance/covariance parameters are the inverse matrix of the variance/covariance matrix given by the user
; The actual parameters are in order:

1. height (1 term). No assumptions on what quantity the height represents, and it can be negative (enumerated by HEIGHT)
2. mean (ndim terms) (enumerated by CENTER).
3. variance (ndim terms). The variance is always positive, and an exception (AipsError) will be thrown if you try to set a negative value.
4. covariance (ndim*(ndim-1)/2 terms) The order is (assuming ndim=5) v12,v13,v14,v15,v23,v24,v25,v34,v35,v45. The restrictions described above for the covariance (ie. -1 < r12 < +1) are enforced.

### Example

Construct a two dimensional Gaussian with mean=(0,1), variance=(.1,7) and height = 1;

uInt ndim = 2;
Float height = 1;
Vector<Float> mean(ndim); mean(0) = 0, mean(1) = 1;
Vector<Float> variance(ndim); variance(0) =.1, variance(1) = 7;
GaussianND<Float> g(ndim, height, mean, variance);
Vector<Float> x(ndim); x = 0;
cout << "g("<< x <<") = " << g(x) <<endl; // g([0,0])=1*exp(-1/2*1/7);
x(1)++;
cout << "g("<< x <<") = " <<g(x) <<endl; // g([0,1])= 1
cout << "Height: " << g.height() <<endl; // Height: 1
cout << "Flux: " << g.flux() << endl; // Flux: 2*Pi*Sqrt(.1*7)
cout << "Mean: " << g.mean() << endl; // Mean: [0, -1]
cout << "Variance: " << g.variance() <<endl; // Variance: [.1, 7]
cout << "Covariance: "<< g.covariance()<<endl;// Covariance: [.1, 0]
// [0, 7]
g.setFlux(1);
cout << "g("<< x <<") = " <<g(x) <<endl; //g([0,1])=1/(2*Pi*Sqrt(.7))
cout << "Height: " << g.height() <<endl; // Height: 1/(2*Pi*Sqrt(.7))
cout << "Flux: " << g.flux() << endl; // Flux: 1
cout << "Mean: " << g.mean() << endl; // Mean: [0, -1]
cout << "Variance: " << g.variance() <<endl; // Variance: [.1, 7]
cout << "Covariance: "<< g.covariance()<<endl;// Covariance: [.1, 0]
// [0, 7]
casacore::GaussianNDParam::variance
Vector< T > variance() const
The FWHM of the Gaussian is sqrt(8*variance*log(2)).
casacore::GaussianNDParam::height
T height() const
Get or set the peak height of the Gaussian.
Definition GaussianNDParam.h:232
casacore::GaussianNDParam::ndim
virtual uInt ndim() const
Variable dimensionality.
Definition GaussianNDParam.h:228
casacore::GaussianNDParam::mean
Vector< T > mean() const
The center ordinate of the Gaussian.
casacore::GaussianND
Definition GaussianND.h:177
casacore::Vector
Definition Vector.h:82
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Float
float Float
Definition aipstype.h:52

### Motivation

A Gaussian Functional was needed for modeling the sky with a series of components. It was later realised that it was too general and Gaussian2D was written.

### Template Type Argument Requirements (T)

- T should have standard numerical operators and exp() function. Current implementation only tested for real types.

### To Do

- Nothing I know off, apart from possible optimization

Definition at line 180 of file GaussianNDParam.h.

## Member Enumeration Documentation

## anonymous enum

template<class T>

anonymous enum

Enumerator
HEIGHT |
CENTER |

Definition at line 184 of file GaussianNDParam.h.

## Constructor & Destructor Documentation

## GaussianNDParam() [1/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( |  | ) |

Constructs a Gaussian using the indicated height, mean, variance & covariance.

ndim defaults to 2, mean defaults to 0, height to Pi^(-ndim/2) (the flux is unity) variance defaults to 1.0, covariance defaults to 0.0,

Referenced by casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), GaussianNDParam(), GaussianNDParam(), and operator=().

## GaussianNDParam() [2/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | uInt | ndim | ) |

explicit

References ndim().

## GaussianNDParam() [3/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | uInt | ndim,
|  | const T & | height )

References height(), and ndim().

## GaussianNDParam() [4/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | uInt | ndim,
|  | const T & | height,
|  | const Vector< T > & | mean )

References height(), mean(), and ndim().

## GaussianNDParam() [5/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | uInt | ndim,
|  | const T & | height,
|  | const Vector< T > & | mean,
|  | const Vector< T > & | variance )

References height(), mean(), ndim(), and variance().

## GaussianNDParam() [6/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | uInt | ndim,
|  | const T & | height,
|  | const Vector< T > & | mean,
|  | const Matrix< T > & | covar )

References height(), mean(), and ndim().

## GaussianNDParam() [7/8]

template<class T>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | const GaussianNDParam< T > & | other | ) |

Copy constructor (deep copy).

References GaussianNDParam().

## GaussianNDParam() [8/8]

template<class T>
template<class W>

casacore::GaussianNDParam< T >::GaussianNDParam | ( | const GaussianNDParam< W > & | other | ) |

inline

Definition at line 209 of file GaussianNDParam.h.

References casacore::Function< T, U >::Function(), GaussianNDParam(), itsDim, and itsFlux2Hgt.

## ~GaussianNDParam()

template<class T>

virtual casacore::GaussianNDParam< T >::~GaussianNDParam | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## covariance()

template<class T>

Matrix< T > casacore::GaussianNDParam< T >::covariance | ( |  | ) | const

The covariance Matrix defines the correlations between all the axes.

## flux()

template<class T>

T casacore::GaussianNDParam< T >::flux | ( |  | ) | const

The analytical integrated area underneath the Gaussian.

Use these functions as an alternative to the height functions.

Referenced by setFlux().

## height()

template<class T>

T casacore::GaussianNDParam< T >::height | ( |  | ) | const

inline

Get or set the peak height of the Gaussian.

Definition at line 232 of file GaussianNDParam.h.

References HEIGHT, and casacore::Function< T, U >::param_p.

Referenced by casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), GaussianNDParam(), GaussianNDParam(), GaussianNDParam(), GaussianNDParam(), and setHeight().

## mean()

template<class T>

Vector< T > casacore::GaussianNDParam< T >::mean | ( |  | ) | const

The center ordinate of the Gaussian.

Referenced by casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), GaussianNDParam(), GaussianNDParam(), GaussianNDParam(), and setMean().

## name()

template<class T>

virtual const String & casacore::GaussianNDParam< T >::name | ( |  | ) | const

inline virtual

Give name of function.

Reimplemented from casacore::Function< T, U >.

Definition at line 224 of file GaussianNDParam.h.

## ndim()

template<class T>

virtual uInt casacore::GaussianNDParam< T >::ndim | ( |  | ) | const

inline virtual

Variable dimensionality.

Implements casacore::Function< T, U >.

Definition at line 228 of file GaussianNDParam.h.

References itsDim.

Referenced by casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), casacore::GaussianND< T >::GaussianND(), GaussianNDParam(), GaussianNDParam(), GaussianNDParam(), GaussianNDParam(), and GaussianNDParam().

## operator=()

template<class T>

GaussianNDParam< T > & casacore::GaussianNDParam< T >::operator= | ( | const GaussianNDParam< T > & | other | ) |

Copy assignment (deep copy).

References GaussianNDParam().

Referenced by casacore::GaussianND< T >::operator=().

## repack()

template<class T>

void casacore::GaussianNDParam< T >::repack | ( | Matrix< T > & | covar | ) | const

protected

Functions to convert between internal Vector of parameters and the Covariance Matrix.

## setCovariance()

template<class T>

void casacore::GaussianNDParam< T >::setCovariance | ( | const Matrix< T > & | covar | ) |

## setFlux()

template<class T>

void casacore::GaussianNDParam< T >::setFlux | ( | const T & | flux | ) |

References flux().

## setHeight()

template<class T>

void casacore::GaussianNDParam< T >::setHeight | ( | const T & | height | ) |

inline

Definition at line 233 of file GaussianNDParam.h.

References HEIGHT, height(), and casacore::Function< T, U >::param_p.

## setMean()

template<class T>

void casacore::GaussianNDParam< T >::setMean | ( | const Vector< T > & | mean | ) |

References mean().

## setVariance()

template<class T>

void casacore::GaussianNDParam< T >::setVariance | ( | const Vector< T > & | variance | ) |

References variance().

## unpack()

template<class T>

void casacore::GaussianNDParam< T >::unpack | ( | const Matrix< T > & | covar | ) |

protected

References casacore::Function< T, U >::Function(), casacore::Function< T, U >::nparameters(), and casacore::Function< T, U >::param_p.

## variance()

template<class T>

Vector< T > casacore::GaussianNDParam< T >::variance | ( |  | ) | const

The FWHM of the Gaussian is sqrt(8*variance*log(2)).

The variance MUST be positive

Referenced by casacore::GaussianND< T >::GaussianND(), GaussianNDParam(), and setVariance().

## Member Data Documentation

## itsDim

template<class T>

uInt casacore::GaussianNDParam< T >::itsDim

protected

dimensionality

Definition at line 265 of file GaussianNDParam.h.

Referenced by GaussianNDParam(), and ndim().

## itsFlux2Hgt

template<class T>

T casacore::GaussianNDParam< T >::itsFlux2Hgt

protected

factor to convert from flux to height

Definition at line 267 of file GaussianNDParam.h.

Referenced by GaussianNDParam().

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

- scimath/Functionals/GaussianNDParam.h