locked
Learning a Beta (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • laura posted on 02-06-2009 12:10 PM

    I am trying to learn a coin parameter epsilon from am uninformative / vague prior. Although posteriors of individual trials are about 0.9, the inference procedure reports that the mean of the coin is still 0.5.

    Did I do something wrong? I thought this worked previously....

     

    for all uRange
            epsilon.[uRange] <- Variable.Beta(1.0,1.0)
            for all sRange
                e.[uRange].[sRange] <- Variable.Bernoulli(epsilon.[uRange])

     

    posterior of trials "e"

    ePost.[0].[1] = Bernoulli(0.9349)
    ePost.[0].[2] = Bernoulli(0.9703)
    ePost.[0].[3] = Bernoulli(0.9534)
    ePost.[0].[4] = Bernoulli(0.9625)
    ePost.[0].[5] = Bernoulli(0.9385)
    ePost.[0]. = Bernoulli(0.9633)
    ePost.[0].[7] = Bernoulli(0.9702)
    ePost.[0]. = Bernoulli(0.9712)
    ePost.[1].[0] = Bernoulli(0.9464)
    ePost.[1].[1] = Bernoulli(0.9383)
    ePost.[1].[2] = Bernoulli(0.9304)
    ePost.[1].[3] = Bernoulli(0.9624)
    ePost.[1].[4] = Bernoulli(0.9562)
    ePost.[2].[0] = Bernoulli(0.9742)
    ePost.[2].[1] = Bernoulli(0.9723)
    ePost.[2].[2] = Bernoulli(0.9801)
    ePost.[2].[3] = Bernoulli(0.9642)
    ePost.[2].[4] = Bernoulli(0.9744)
    ePost.[2].[5] = Bernoulli(0.9871)
    ePost.[3].[0] = Bernoulli(0.9008)
    ePost.[3].[1] = Bernoulli(0.936)
    ePost.[3].[2] = Bernoulli(0.8536)
    ePost.[3].[3] = Bernoulli(0.8915)
    ePost.[3].[4] = Bernoulli(0.8399)
    ePost.[4].[0] = Bernoulli(0.9636)
    ePost.[4].[1] = Bernoulli(0.9721)
    ePost.[4].[2] = Bernoulli(0.9796)
    ePost.[4].[3] = Bernoulli(0.9706)
    ePost.[4].[4] = Bernoulli(0.9651)
    ePost.[5].[0] = Bernoulli(0.9828)
    ePost.[5].[1] = Bernoulli(0.9746)
    ePost.[5].[2] = Bernoulli(0.9518)
    ePost.[5].[3] = Bernoulli(0.9729)
    ePost.[5].[4] = Bernoulli(0.9609)
    ePost..[0] = Bernoulli(0.9009)
    ePost..[1] = Bernoulli(0.9361)
    ePost.[7].[0] = Bernoulli(0.9541)
    ePost.[7].[1] = Bernoulli(0.9647)
    ePost.[7].[2] = Bernoulli(0.956)
    ePost..[0] = Bernoulli(0.9515)
    ePost..[1] = Bernoulli(0.951)
    ePost..[2] = Bernoulli(0.943)
    ePost..[3] = Bernoulli(0.9385)

    posterior of epsilon

    epsilonPost = [|0.5; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5|]

         

    this output is generated by

        let epsilonPost = inferenceEngine.Infer<DistributionArray<Beta>>(epsilon)
            let epsilonPostMeans =
                epsilonPost.ToArray()
                |> Array.map (fun beta ->
                    beta.GetMean()
                    )
            

    I could swear this used to work...

     

    Laura

     

    Friday, June 3, 2011 4:43 PM

Answers

  • laura replied on 02-09-2009 3:51 PM

    The issue was not related to the Beta  distribution.

    It seems as if there were 50 update iterations on the variable "e" , but only one on "epsilon".

    See thread on "multiple Infer calls" for details.

     

    Laira

    Friday, June 3, 2011 4:43 PM

All replies

  • laura replied on 02-06-2009 12:13 PM

     *sigh* is there a way to disable the smileys???? I'm an oldschool smiley user anyway

    Friday, June 3, 2011 4:43 PM
  • John Guiver replied on 02-09-2009 11:27 AM

    Hi Laura

    The following F# code seems to do the correct thing. Let me know if this what you were trying to do.

    John

     #light

    // Reference the Infer.NET DLLs

    #r @"C:\Program Files\Microsoft Research\Infer.NET 2.2\bin\Release\Infer.Compiler.dll"
    #r @"C:\Program Files\Microsoft Research\Infer.NET 2.2\bin\Release\Infer.Runtime.dll"

    open MicrosoftResearch.Infer
    open MicrosoftResearch.Infer.Models
    open MicrosoftResearch.Infer.Distributions
    open MicrosoftResearch.Infer.Factors

    let data =
    [|
        [|
    true;true;false;true;true;false|];
        [|
    true;true;true;false;true|]
    |]

    // Sizes of the inner arrays

    let sizes = data |> Array.map ( fun d -> d.Length)

    // Outer range

    let uRange = Range(sizes.Length)

    // The sizes as a variable array

    let sizesVar = Variable.Constant(sizes, uRange)

    // The inner variable range

    let sRange = Range(sizesVar.[uRange])

    // The Bernoulli parameters

    let epsilon = Variable.Array<double>(uRange)
    epsilon.[uRange] <- Variable.Beta(1.0,1.0).ForEach(uRange)

    // The draws from the Bernoullis

    let e = Variable.Array<_>(Variable.Array<bool>(sRange), uRange)
    e.[uRange].[sRange] <- Variable.Bernoulli(epsilon.[uRange]).ForEach(sRange)

    // The observations:

    e.ObservedValue <- data
    let ie = InferenceEngine(VariationalMessagePassing())
    ie.ShowProgress =
    false
    let epsPosteriors = Distribution< >.ToArray<Beta[>(ie.Infer< >(epsilon))
    let epsPosteriorMeans = epsPosteriors |> Array.map ( fun post -> post.GetMean())
    printf
    "Epsilon posterior means: %A" epsPosteriorMeans
    ()
    Friday, June 3, 2011 4:43 PM
  • laura replied on 02-09-2009 12:32 PM

    Friday, June 3, 2011 4:43 PM
  • laura replied on 02-09-2009 3:51 PM

    The issue was not related to the Beta  distribution.

    It seems as if there were 50 update iterations on the variable "e" , but only one on "epsilon".

    See thread on "multiple Infer calls" for details.

     

    Laira

    Friday, June 3, 2011 4:43 PM