How to model a mixture of 3 Normals in PyMC?

后端 未结 1 396
梦谈多话
梦谈多话 2020-12-19 03:03

There is a question on CrossValidated on how to use PyMC to fit two Normal distributions to data. The answer of Cam.Davidson.Pilon was to use a Bernoulli distribution to ass

相关标签:
1条回答
  • 2020-12-19 03:32

    there is a mc.Categorical object that does just this.

    p =  [0.2, 0.3, .5]
    t = mc.Categorical('test', p )
    t.random()
    #array(2, dtype=int32)
    

    It returns an int between 0 and len(p)-1. To model the 3 Normals, you make p a mc.Dirichlet object (it accepts a k length array as the hyperparameters; setting the values in the array to be the same is setting the prior probabilities to be equal). The rest of the model is nearly identical.

    This is a generalization of the model I suggested above.


    Update:

    Okay, so instead of having different means, we can collapse them all into 1:

    means = Normal( "means", 0, 0.001, size=3 )
    
    ...
    
    @mc.deterministic
    def mean(categorical=categorical, means = means):
       return means[categorical]
    
    0 讨论(0)
提交回复
热议问题