28 this->dimension = dimension;
31 this->cov = covariance_type::Identity(dimension, dimension);
32 this->mean = value_type::Zero(dimension, 1);
42 this->cov = covariance;
45 dimension = cov.rows();
47 if (mean.rows() != dimension)
64 if (point.rows() != dimension)
70 -0.5 * (point - mean).transpose() * cov.inverse() * (point - mean);
71 double e = exp(inner(0, 0));
85 if (point.rows() != dimension)
91 dist = (point - mean).transpose() * cov.inverse() * (point - mean);
93 return std::sqrt(dist(0, 0));
108 float fRand1, fRand2;
114 fRand1 =
float(rand()) / RAND_MAX;
115 fRand2 =
float(rand()) / RAND_MAX;
118 gaussianSample(d) = sqrt(-2 * log(fRand1)) * cos(2 *
M_PI * fRand2);
146 float fRand1, fRand2;
152 fRand1 =
float(rand()) / RAND_MAX;
153 fRand2 =
float(rand()) / RAND_MAX;
156 gaussianSample(d) = sqrt(-2 * log(fRand1)) * cos(2 *
M_PI * fRand2);
166 A(i, u) = sqrt(cov(i, u));
189 if (samples.rows() != dimension)
194 int numberSamples = samples.cols();
197 mean = value_type::Zero(dimension, 1);
199 for (
int i = 0; i < numberSamples; i++)
201 mean += samples.block(0, i, mean.rows(), 1);
204 mean = mean / numberSamples;
209 for (
int s = 0; s < numberSamples; s++)
211 meanadj.block(0, s, meanadj.rows(), 1) -= mean;
215 cov = meanadj * meanadj.transpose() / numberSamples;
226 this->mean = prototype.
getMean();
235 if ((dimension != -1) && (mean.rows() != dimension))
240 if ((dimension != -1) && (cov.rows() != dimension))
247 dimension = cov.rows();
257 if ((dimension != -1) && (mean.rows() != dimension))
264 dimension = mean.rows();
265 this->cov = Eigen::MatrixXd::Identity(dimension, dimension);
274 if ((dimension != -1) && (cov.rows() != dimension))
279 if ((dimension != -1) && (cov.cols() != dimension))
284 if ((dimension == -1) && (cov.rows() != cov.cols()))
291 dimension = cov.rows();
292 this->mean = Eigen::VectorXd::Zero(dimension);
302Gaussian::isSymmetric(
const covariance_type& matrix)
304 if (matrix.rows() != matrix.cols())
309 for (
int r = 0; r < matrix.rows(); r++)
311 for (
int c = 0;
c < matrix.cols();
c++)
313 if (matrix(r,
c) != matrix(
c, r))
315 throw CovarianceNotSymmetricException();
class A(deque< T, A >)) ARMARX_OVERLOAD_STD_HASH_FOR_ITERABLE((class T
Enables hashing of std::list.
const covariance_type & getCovariance() const
Eigen::VectorXd value_type
double evaluate(const value_type &point)
int getDimensions() const
Eigen::MatrixXd samples_type
void set(const Gaussian &prototype)
Eigen::MatrixXd covariance_type
void setCovariance(const covariance_type &cov)
void setMean(const value_type &mean)
value_type drawSampleDiagonalCovariance()
const value_type & getMean() const
void generateFromSamples(const samples_type &samples)
double mahalanobis(const value_type &point)