mardi 5 janvier 2021

Checking random sample component identity in Julia

I have created a mixture of k=3 simple normal distributions in Julia as following (Distributions.jl):

mixm = MixtureModel(Normal[
     Normal(-2.0, 1.2),    
     Normal(0.0, 1.0),    
     Normal(2.0, 2.5)], 
     [0.2,0.5, 0.3])

And then I sampled using:

sample = rand(mixm, 10)

So we get 10 samples belonging to an of the 3 normals. This is a 10-element array. How can I find which component each element comes from?

I assume this must be easy since Julia randomly chooses one of the two normals to sample element i in the array sample.

I want to exploint an if loop so that I store the elements of each component to two separate lists.




Aucun commentaire:

Enregistrer un commentaire