I want to generate random sample (vector X):
X = [x1, x2, x3, ..., x_d]
where X follows a custom multivariate Probability Density Function.
I am using Python - scipy and I overvide the PDF function to follow a combination of multivariate normal distributions.
For example:
import plotly.graph_objects as go
import numpy as np
from scipy.stats._multivariate import multivariate_normal_gen, multivariate_normal, _squeeze_output
class multivar_rv(multivariate_normal_gen):
def pdf(self, x, mean=None, cov=1, allow_singular=True):
mean = [
[0, 1],
[2, 5]
]
cov = [
[
[1, 0],
[0, 1]
],
[
[1.5, 0],
[0, 1.5]
]
]
weight = [.5, .5]
return sum(weight[i] * multivariate_normal(mean[i], cov[i]).pdf(x) for i in range(len(mean)))
The following image shows the plot of the above code.
Now I want to generate samples given the above distribution, however if I use rvs() (from scipy.stats._multivariate.multivariate_normal_gen) the function is not overrided and the results will be generated from the default normal distribution:
P.rvs()
What do I have to do in order to change this and override this function so that the generated samples follow my PDF?
Thank you!