# Learning a Beta (Migrated from community.research.microsoft.com) • ### 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.. = Bernoulli(0.9349)
ePost.. = Bernoulli(0.9703)
ePost.. = Bernoulli(0.9534)
ePost.. = Bernoulli(0.9625)
ePost.. = Bernoulli(0.9385)
ePost.. = Bernoulli(0.9633)
ePost.. = Bernoulli(0.9702)
ePost.. = Bernoulli(0.9712)
ePost.. = Bernoulli(0.9464)
ePost.. = Bernoulli(0.9383)
ePost.. = Bernoulli(0.9304)
ePost.. = Bernoulli(0.9624)
ePost.. = Bernoulli(0.9562)
ePost.. = Bernoulli(0.9742)
ePost.. = Bernoulli(0.9723)
ePost.. = Bernoulli(0.9801)
ePost.. = Bernoulli(0.9642)
ePost.. = Bernoulli(0.9744)
ePost.. = Bernoulli(0.9871)
ePost.. = Bernoulli(0.9008)
ePost.. = Bernoulli(0.936)
ePost.. = Bernoulli(0.8536)
ePost.. = Bernoulli(0.8915)
ePost.. = Bernoulli(0.8399)
ePost.. = Bernoulli(0.9636)
ePost.. = Bernoulli(0.9721)
ePost.. = Bernoulli(0.9796)
ePost.. = Bernoulli(0.9706)
ePost.. = Bernoulli(0.9651)
ePost.. = Bernoulli(0.9828)
ePost.. = Bernoulli(0.9746)
ePost.. = Bernoulli(0.9518)
ePost.. = Bernoulli(0.9729)
ePost.. = Bernoulli(0.9609)
ePost. . = Bernoulli(0.9009)
ePost. . = Bernoulli(0.9361)
ePost.. = Bernoulli(0.9541)
ePost.. = Bernoulli(0.9647)
ePost.. = Bernoulli(0.956)
ePost. . = Bernoulli(0.9515)
ePost. . = Bernoulli(0.951)
ePost. . = Bernoulli(0.943)
ePost. . = 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

• 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