23 #ifndef NORMALPDF_INL_HH 24 #define NORMALPDF_INL_HH 40 const blitz::Array< T, 2 >& samples
44 covariance_.resize(dim, dim);
51 for (
int i = 0; i < num_samples; ++i)
53 mean_(all) += samples(i, all);
55 mean_ /= (T)num_samples;
57 for (
int i = 0; i < num_samples; ++i) {
59 blitz::Array<T, 1> sample_demeaned(dim);
60 sample_demeaned = samples(i, all) - mean_;
61 for (
int cov_row = 0; cov_row < dim; ++cov_row)
62 for (
int cov_col = cov_row; cov_col < dim; ++cov_col) {
63 covariance_(cov_row, cov_col) += sample_demeaned(cov_row) *
64 sample_demeaned(cov_col);
66 covariance_(cov_col, cov_row) = covariance_(cov_row, cov_col);
69 covariance_ /= (T)num_samples;
74 const blitz::Array<T, 1> &mean,
75 const blitz::Array<T, 2> &information
76 ) : mean_(mean), information_matrix_(information) {
86 blitz::Array<double, 2> cov_d(blitz::cast<double>(
covariance_));
98 const blitz::Array<T, 1>& sample) {
99 blitz::Array<T, 1> sample_demeaned(pdf.
mean_.extent(0));
100 sample_demeaned = sample - pdf.
mean_;
105 T dot_product = (T)
atb::dot(sample_inf, sample_demeaned);
106 return std::sqrt(dot_product);
111 #endif // NORMALPDF_INL_HH
blitz::Array< T, 1 > mean_
T operator()(const NormalPDF< T > &pdf, const blitz::Array< T, 1 > &sample)
void invertCovariance()
Calculates information_matrix_ don't use information_matrix_ before calling this method.
NormalPDF(const blitz::Array< T, 2 > &samples)
Estimate PDF from given set of samples.
Query specific information about different data types.
Encapsulates a normal pdf.
void invert(blitz::Array< double, 2 > const &A, blitz::Array< double, 2 > &Ainv)
Compute the inverse of matrix A.
int BlitzIndexT
The native integer type for indexing blitz++ Arrays.
blitz::TinyVector< BaseT, Dim > mvMult(MatrixT const &m, blitz::TinyVector< BaseT, Dim > const &v)
Quadratic Matrix * Vector product (generic).
blitz::Array< T, 2 > covariance_
bool all(blitz::TinyMatrix< bool, NRows, NColumns > const &matrix)
all() reduction for boolean blitz::TinyMatrix.
blitz::Array< T, 2 > information_matrix_
double dot(blitz::Array< DataT, 1 > const &vec1, blitz::Array< DataT, 1 > const &vec2)
Calculation of the inner product (dot product) of the given vectors.