Generate Multiple random multidimensional normal distribution in MATLAB - matlab

I want to generate multiple(1000) random multidimensional(10000) normal distributions with different densities in matlab.
I know how to generate a multivariate normal distribution using mvnrnd() function but I was wondering if I could do it in a automated way. Maybe have the mean and sigma generated by rand function then feed it into the mvnrnd() function somehow?
Also would it be possible to generate some(300) of these in a hyper spherical formation where the means are distributed spherically in the multidimensional space. They should have the same density and spread/sigma.
Thank you for your input in advance.

Related

Random Number From Normal Distributions in Matlab

Is randn() in Matlab actually using an inverse normal distribution to generate the random numbers from normal distributions?
This manual page says:
NormalTransform: Transformation algorithm used by randn(s, ...) to
generate normal pseudorandom values. Possible values are 'Ziggurat',
'Polar', or 'Inversion'.
You specifically asked about inversion, so I'm assuming you're already familiar with it. Here are links in case you want to know more about the Ziggurat or polar methods.

How to generate n independent normal random variables in Matlab

I am new to this, and I'd like to know whether there's a function or any way I can generate n independent normal random variables in Matlab?
randn will produce independent random variates from a Normal distribution.
In general, you have to trust that the sequence of variates produced by a pseudo-random number generator are statistically independent. Smart people who are experts in designing RNGs have worked hard to try to achieve that.
You can use these two below,
randn
which will give you normally distributed random numbers.
rand
which will give you uniformly distributed random numbers.

How to estimate multi-dimensional probability distribution from data using Matlab?

Hi I'm trying to estimate the data distribution using Matlab.
For one dimensional data, I can definitely use ksdensity.
However my problems is that I need multi-dimensional joint distribution and conditional distribution.
I've tried kde tools from UCI. It is not functioning in my case and I cannot figure out why. So I'm asking for another tool I can possibly use..
Edit
The toolbox is not working and giving extreme results. I used 1e5 points and it might because the points are too dense.
KDE toolbox result
ksdensity result

matlab - pdf for multivariate uniform distribution

The pdf for the multivariate normal distribution in MATLAB is mvnpdf(...). What about the case where multiple variables are uniformly distributed: Is there a function to describe their joint distribution analogous to the multivariate normal distribution? If there is no such function, is there a trick to handle this case?
The simplest way how several variables can be uniformly distributed is if they are mutually independent; in that case you simply have a uniform distribution over the hypercube in the space spanned by the variables. In order to get samples from this distribution, you just separately generate samples for each of the variables.
The point where a "trick" might be necessary is if you have dependencies between the variables even though the marginal distribution for each of them is still uniform. In this case you have to describe the dependency structure, and I'm not aware of any standard way to do this (the way dependencies between normally distributed variables are described by a correlation matrix).
Of course such distributions exist: For two dimensions, one possibility would be to have a joint distribution that looks like a solution to the "eight rooks" problem:
Another one actually derives from the introductory Matlab example, the magic square:
Both of these examples are discrete distributions, but can be produced at arbitrary granularity, or simply interpreted as piecewise constant continuous distributions.
As you can see there are many possibilities for a multivariate distribution each of whose marginal distributions are uniform. The question you have to answer for yourself is what kind of dependencies, if any, you are interested in?
If I'm understanding the question properly, we want to calculate the pdf of a multivariate uniform distribution. By definition, the pdf is constant for all values in the support the distribution. Thus to calculate the pdf all that is required is to calculate the norming constant, which is given by the inverse of the integral of the support. That is to say, the pdf is given by
f(x) = 1 / integral(A)
where A is the support set, and x is an element in A. If an analytic solution to integral(A) is not available, then a numerical integrator can be employed.

Defining your own probability density function in MATLAB

Is it possible to define your own probability density function in MATLAB or Octave and use it
for generating random numbers?
MATLAB and Octave have default functions like rand, randn built in to draw points at random from a uniform, or normal distributions but there seems to be no documentation of how to define my very own proability density function.
Sampling from an arbitrary random distribution is not always trivial. For well known distributions there are tricks to implement them and most of them are implemented in stats toolbox as Oli said.
If your distribution of interest is of difficult form, there are many sampling algorithms that may help you, such as, rejection sampling, slice sampling, Metropolis–Hastings algorithm.
If your distribution is discrete, or can be approximated by a discrete distribution fairly well, then you can just do multinomial sampling using randsamp.
If you have the stats toolbox, you can use random(), as it has a lot of useful PDFs built-in.
I've had to do that a few times recently, and it's not exactly an easy thing to accomplish. My favorite technique was to use Inverse transform sampling.
The idea is quite simple:
create a cdf
use a uniform random number generator.
identify the RV that maps to your cdf value.