14 m_mu = Mat::zeros(k, 1, CV_64FC1);
21 mu.convertTo(
m_mu, CV_64FC1);
32 this->
m_Q = rhs.
m_Q.empty() ? Mat() : rhs.
m_Q.clone();
43 this->
m_Q = rhs.
m_Q.empty() ? Mat() : rhs.
m_Q.clone();
58 for (
int y = 0; y < this->
m_sigma.rows; y++) {
59 double *pSigma = this->
m_sigma.ptr<
double>(y);
60 const double *pRhsSigma = rhs.
m_sigma.ptr<
double>(y);
61 for (
int x = 0; x < this->
m_sigma.cols; x++) {
62 pSigma[x] =
static_cast<double>( a * (pSigma[x] + this->
m_mu.at<
double>(x, 0) * this->
m_mu.at<
double>(y, 0)) +
63 (1.0 - a) * (pRhsSigma[x] + rhs.
m_mu.at<
double>(x, 0) * rhs.
m_mu.at<
double>(y, 0)));
67 addWeighted(this->
m_mu, a, rhs.
m_mu, 1.0 - a, 0.0, this->m_mu);
93 DGM_ASSERT_MSG(point.size() ==
m_mu.size(),
"Wrong input point size");
94 DGM_ASSERT_MSG(point.type() ==
m_mu.type(),
"Wrong input point type");
101 addWeighted(
m_mu, a, point, (1.0 - a), 0.0,
m_mu);
105 for (
int y = 0; y <
m_sigma.rows; y++) {
106 double *pSigma =
m_sigma.ptr<
double>(y);
107 for (
int x = 0; x <
m_sigma.cols; x++) {
108 double cr = (point.at<
double>(x, 0) -
m_mu.at<
double>(x, 0)) * (point.at<
double>(y, 0) -
m_mu.at<
double>(y, 0));
109 pSigma[x] = cr +
static_cast<double>(a * (pSigma[x] - cr));
115 addWeighted(this->
m_mu, a, point, 1.0 - a, 0.0, mu);
119 for (
int y = 0; y <
m_sigma.rows; y++) {
120 double *pSigma =
m_sigma.ptr<
double>(y);
121 for (
int x = 0; x <
m_sigma.cols; x++) {
122 pSigma[x] =
static_cast<double>(a * (pSigma[x] +
m_mu.at<
double>(x, 0) *
m_mu.at<
double>(y, 0)) +
123 (1.0 - a) * point.at<
double>(x, 0) * point.at<
double>(y, 0) -
124 mu.at<
double>(x, 0) * mu.at<
double>(y, 0));
137 DGM_ASSERT_MSG(mu.size() ==
m_mu.size(),
"Wrong mu size");
138 DGM_ASSERT_MSG(mu.type() ==
m_mu.type(),
"Wrong mu type");
148 DGM_ASSERT_MSG(sigma.size() ==
m_sigma.size(),
"Wrong sigma size");
149 DGM_ASSERT_MSG(sigma.type() ==
m_sigma.type(),
"Wrong sigma type");
167 long double det = MAX(LDBL_EPSILON, sqrtl(static_cast<long double>(determinant(
m_sigma))));
168 long double sPi = powl(2 * static_cast<long double>(Pi), static_cast<long double>(k) / 2);
178 DGM_ASSERT_MSG(x.size() ==
m_mu.size(),
"Wrong x size");
179 DGM_ASSERT_MSG(x.type() ==
m_mu.type(),
"Wrong x type");
181 subtract(x,
m_mu, X);
183 gemm(X, p1, 1.0, Mat(), 0.0, p2, GEMM_1_T);
184 double value = -0.5 * p2.at<
double>(0, 0);
192 DGM_ASSERT_MSG(x.size() ==
m_mu.size(),
"Wrong x size");
193 DGM_ASSERT_MSG(x.type() ==
m_mu.type(),
"Wrong x type");
195 return mathop::Euclidian<double, double>(
m_mu, x);
201 DGM_ASSERT_MSG(x.size() ==
m_mu.size(),
"Wrong x size");
202 DGM_ASSERT_MSG(x.type() ==
m_mu.type(),
"Wrong x type");
210 DGM_ASSERT_MSG(x.
getMu().size() ==
m_mu.size(),
"Wrong x.mu size");
211 DGM_ASSERT_MSG(x.
getMu().type() ==
m_mu.type(),
"Wrong x.mu type");
215 cv::Scalar tr = trace(p);
224 double res =
static_cast<double>(tr.val[0] + dst*dst - k - ln) / 2;
236 gemm(
m_Q, X, 1,
m_mu, 1, res, GEMM_1_T);
245 if (!
m_Q.empty())
m_Q.release();
258 Mat L(D, D, CV_64FC1); L.setTo(0);
259 for (
int d = 0; d < D; d++) L.at<
double>(d, d) = E.at<
double>(d, 0);
264 gemm(L, F, 1, Mat(), 0, res);
void clear(void)
Clears class variables.
void addPoint(const Mat &point, bool approximate=false)
Adds new k-dimensional point (sample) for Gaussian distribution approximation.
Mat getSigmaInv(void) const
Returns .
Mat calculateQ(void) const
double getMahalanobisDistance(const Mat &x) const
Returns the Mahalanobis distance between argument point x and the center of multivariate normal distr...
void setSigma(Mat &sigma)
Sets .
Mat getSample(void) const
Returns a random vector (sample) from multivariate normal distribution.
double getValue(Mat &x, Mat &aux1=EmptyMat, Mat &aux2=EmptyMat, Mat &aux3=EmptyMat) const
Returns unscaled value of the Gaussian function.
CKDGauss & operator+=(const CKDGauss &rhs)
Compound merge operator.
long double getAlpha(void) const
Returns .
CKDGauss(dword k)
Constructor.
double getKullbackLeiberDivergence(const CKDGauss &x) const
Returns the Kullback-Leiber divergence from the multivariate normal distribution to argument multiva...
double getEuclidianDistance(const Mat &x) const
Returns the Euclidian distance between argument point x and the center of multivariate normal distrib...
Mat getSigma(void) const
Returns .
void setMu(Mat &mu)
Sets .
void reset_SigmaInv_Q_Alpha(void)
CKDGauss & operator=(const CKDGauss &rhs)
Copy operator.
Multivariate Gaussian distribution class.
Mat getMu(void) const
Returns .
static const bool USE_SAFE_SIGMA
T N(T mu=0, T sigma=1)
Returns a floating-point random number with normal distribution.