PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] How to specify the weights in a MixtureModel in Julia Distributions.jl?

 October 07, 2022     julia, normal-distribution, statistics     No comments   

Issue

In Distributions.jl we can specify the priors of a mixture model. But we cannot specify the weights. For example, if I want to make a mixture like this:

pdf(Normal(2, 3), x)*w1.+pdf(Normal(5, 10), x)*w2

I cannot really specify the weights. And the priors are required to add up to 1 for obv reasons. So, is there a way to specify the weights in MixtureModel? Something like:

MixtureModel(Normal[
        Normal(2, 3),
        Normal(5, 10)
        ], **weights=[w1, w2]**)

Thanks


Solution

This is covered in the Distributions.jl documentation on mixture model constructors — you want the prior argument. See

https://juliastats.org/Distributions.jl/v0.14/mixture.html#Constructors-1

Here's a quick plot of their first example. The [0.2, 0.5, 0.3] are the weights:

julia> using Distributions, Plots

julia> d = MixtureModel(Normal[
          Normal(-2.0, 1.2),
          Normal(0.0, 1.0),
          Normal(3.0, 2.5)], [0.2, 0.5, 0.3])
MixtureModel{Normal}(K = 3)
components[1] (prior = 0.2000): Normal{Float64}(μ=-2.0, σ=1.2)
components[2] (prior = 0.5000): Normal{Float64}(μ=0.0, σ=1.0)
components[3] (prior = 0.3000): Normal{Float64}(μ=3.0, σ=2.5)


julia> x = -10:0.1:10
-10.0:0.1:10.0

julia> plot(x, pdf.(d, x), legend=nothing, xlabel="x", ylabel="pdf")

Which produces

enter image description here



Answered By - Chris Foster
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing