2 #ifndef vpdt_gaussian_h_ 3 #define vpdt_gaussian_h_ 25 # include <vcl_msvc_warnings.h> 31 template <
class F,
class Covar,
class Metric,
class Disambiguate=
void >
85 T d = Metric::sqr_distance_deriv(pt,
mean,
covar,g);
103 return Metric::sqr_distance(pt,
mean,
covar);
136 template<
class F,
class C,
class M >
146 template<
class F,
class C,
class M >
153 T logd = M::sqr_distance_deriv(pt,d.
mean,d.
covar,g);
155 return static_cast<T>(-logd/2);
177 const double two_pi = vnl_math::twopi;
178 double two_pi_n = two_pi;
179 for (
unsigned int i=1; i<d; ++i)
182 return static_cast<T>(std::sqrt(two_pi_n*Metric::covar_det(g.
mean,g.
covar)));
190 return std::numeric_limits<T>::quiet_NaN();
207 const double two_pi = vnl_math::twopi;
209 for (
unsigned int i=0; i<d; ++i)
210 val *= two_pi*g.
covar[i];
212 return static_cast<T>(std::sqrt(val));
220 for (
unsigned int i=0; i<d; ++i)
232 return static_cast<T>(val);
251 const double two_pi = vnl_math::twopi;
253 for (
unsigned int i=0; i<d; ++i)
254 val *= two_pi*g.
covar;
256 return static_cast<T>(std::sqrt(val));
265 for (
unsigned int i=0; i<d; ++i)
270 double s2 = 1/std::sqrt(2.0*g.
covar);
272 for (
unsigned int i=0; i<d; ++i)
276 return static_cast<T>(val);
292 return static_cast<T>(std::sqrt(vnl_math::twopi*g.
covar));
305 return static_cast<T>(val);
310 #endif // vpdt_gaussian_h_ static T partial_integral(const vpdt_gaussian< F, T > &g, const F &pt)
integrate from -infinity to pt.
T norm_const() const
compute the normalization constant (independent of sample point).
The distribution traits class.
F field_type
The field type.
static T partial_integral(const vpdt_gaussian< F, F > &g, const F &pt)
integrate from -infinity to pt.
T sqr_mahal_dist(const F &pt) const
The squared Mahalanobis distance to this point.
static T domain_integral(const vpdt_gaussian< F, T > &g)
integrate over the entire domain.
vpdt_field_traits< F >::scalar_type T
vpdt_norm_metric< F, typename vpdt_eigen_sym_matrix_gen< F >::type > Metric
static T partial_integral(const vpdt_gaussian< F, Covar > &, const F &)
integrate from -infinity to pt.
vpdt_field_traits< F >::scalar_type T
covar_type covar
the matrix covariance.
void compute_covar(matrix &c) const
Compute the covariance matrix of the distribution.
Forward declare integration helper struct.
T cumulative_prob(const F &pt) const
Evaluate the cumulative distribution function at a point.
A type generator for the default types (those used in vpdl)
unsigned int dimension() const
Return the dimension.
Metrics derived from norms.
Covar covar_type
The covariance type.
T density(const F &pt) const
Evaluate the unnormalized density at a point pt.
Metric metric_type
The metric type.
T & vpdt_index(vnl_vector< T > &v, unsigned int i)
Index into a vnl_vector.
vpdt_field_traits< F >::matrix_type matrix
the data type used for matrices.
vpdt_field_traits< F >::vector_type vector
vpdt_eigen_sym_matrix_gen< F >::type Covar
A Gaussian with variance independent in each dimension.
vpdt_field_traits< F >::scalar_type T
vpdt_gaussian(unsigned int var_dim=vpdt_field_traits< F >::dimension)
Constructor.
static T domain_integral(const vpdt_gaussian< F, F > &g)
integrate over the entire domain.
static T domain_integral(const vpdt_gaussian< F, F > &g)
integrate over the entire domain.
specialized template trait classes for properties of a field type
vpdt_gaussian(const F &m, const covar_type &c)
Constructor - from mean and variance.
void vpdt_set_size(vnl_vector< T > &v, unsigned int s)
Set the size of a vnl_vector.
The field traits class (scalar).
generate the vpdt_eigen_sys_matrix type from a field type.
void compute_mean(vector &m) const
Compute the mean of the distribution.
vpdt_field_traits< F >::scalar_type T
the data type used for scalars.
Overloaded functions to allow uniform API access to various field types.
vpdt_field_traits< F >::vector_type vector
the data type used for vectors.
A metric in field F with metric tensor Tensor.
A symmetric matrix represented in eigenvalue decomposition.
specialized template trait classes for properties of a distribution type
T gradient_density(const F &pt, vector &g) const
Compute the gradient of the density function, returned in g.
static T domain_integral(const vpdt_gaussian< F, Covar > &g)
integrate over the entire domain.
vpdt_field_traits< F >::scalar_type T
vpdt_dist_traits< vpdt_gaussian< F, C, M > >::scalar_type vpdt_gradient_log_density(const vpdt_gaussian< F, C, M > &d, const typename vpdt_dist_traits< vpdt_gaussian< F, C, M > >::field_type &pt, typename vpdt_dist_traits< vpdt_gaussian< F, C, M > >::field_type &g)
Compute the gradient of the log of the unnormalized density.
unsigned int vpdt_size(const vnl_vector< T > &v)
Access the size of a vnl_vector.
void vpdt_fill(vnl_vector< T > &v, const T &val)
Fill a vnl_vector.
vpdt_dist_traits< vpdt_gaussian< F, C, M > >::scalar_type vpdt_log_density(const vpdt_gaussian< F, C, M > &d, const typename vpdt_dist_traits< vpdt_gaussian< F, C, M > >::field_type &pt)
Compute the log of the unnormalized density.
static T partial_integral(const vpdt_gaussian< F, F > &g, const F &pt)
integrate from -infinity to pt.