I would like to draw samples from the following conditional distribution of the following (don't ask why):
fRandomFunction[x_, y_] :=
PDF[MultinormalDistribution[{3, 3}, {{0.5, 0}, {0, 0.5}}], {x, y}] +
PDF[MultinormalDistribution[{6, 6}, {{0.6, -0.5}, {-0.5, 0.6}}], {x,
y}] + PDF[MultinormalDistribution[{6, 6}, {{1, 0.5}, {0.5, 1}}], {x, y}] +
PDF[MultinormalDistribution[{6, 4}, {{0.6, 0.5}, {0.5, 0.6}}], {x,
y}] + PDF[MultinormalDistribution[{2, 8}, {{0.2, 0}, {0, 0.2}}], {x, y}]
At the moment I am using Mathematica's inbuilt ProbabilityDistribution
function to draw individual independent samples:
fGenerateSample[aX_] :=
RandomVariate[
ProbabilityDistribution[fRandomFunction[aX, y], {y, 0, Infinity}], {1}
][[1]]
If I map this onto a random list of X inputs, this takes quite a while to output an independent sample:
lInputs = RandomVariate[NormalDistribution[5, 1], {1}];
lSamples = fGenerateSample /@ lInputs // Timing;
This takes about 1/20 second to execute on my computer. I would like a way of speeding this process up. Does anyone know of a way I could generate a single sample at a faster rate from the conditional density here?
Note this problem is quite different from my actual problem, where I need to essentially do a NestList
with my fGenerateSample
function, up to 100,000 times. That is why speed is of the essence.
fRandomFunction
a conditional distribution when it is the sum of 5 multivariate normal densities. Also,fRandomFunction
is not a proper density until you divide by 5. And finally why doesy
go from 0 to positive infinity whenfRandomFunction
deals with values ofy
between minus and plus infinity? Or am I totally misunderstanding what you've written. (My running of your code takes about a minute rather than 1/20 of a second so I also need a new machine.) $\endgroup$