Pruthvi P
Pruthvi P

Reputation: 534

Multivariate Gaussian Distribution in particle filter

While initialising the particles, i need to add some gaussian noise to it. For example

particle.x(i) = rect(1)+mgd(1,1,0,10);

here rect(1) gives the position, and mgd function is providing the noise

The details about the mgd function are:

My value of N and d are always 1, How can I implement the mgd function in opencv c++?

Upvotes: 1

Views: 1279

Answers (2)

Andrey  Smorodov
Andrey Smorodov

Reputation: 10850

Take a look at standard library "random", it includes methods for different distributions, including normal distribution.

In the case of uncorrelated variables, you can use independent 1D random number for each dimension (see KeillRandor's answer), otherwise it is not correct. For implementation you can look at MATLAB's code, to do it, type in script editor

mvnrnd

then right mouse click on just typed command and select open mvrnd in context menu. You'll see the MATLAB code for mvnrnd function.

Upvotes: 1

Яois
Яois

Reputation: 3858

OpenCV comes with a nice Random Number Generator class and also many useful functions. To initialize a d-dimensional vector with random gaussian noise, just do:

int d = 10; // dimension
float m = 0, cov = 0.1; // mean and covariance
vector<float> X(d,.0f); // your d-dimensional vector
cv::randn(X,m,cov); // <-

Cheers!

Upvotes: 1

Related Questions