locked
case block in F# RRS feed

  • Question

  • Is there an example for using Variable.Case in F#?
    Wednesday, January 18, 2012 10:40 PM

Answers

  • #light

    open System
    open MicrosoftResearch.Infer
    open MicrosoftResearch.Infer.Models
    open MicrosoftResearch.Infer.Distributions
    open MicrosoftResearch.Infer.Factors
           
    let a = Variable.Discrete [|0.2;0.8|]
    let b = Variable.New<bool>()

    let case0 = Variable.Case(a, 0)
    b.SetTo (Variable<bool>.Constant false)
    case0.Dispose()

    let case1 = Variable.Case(a, 1)
    b.SetTo (Variable<bool>.Constant true)
    case1.Dispose()

    let engine = new InferenceEngine()
    let post = engine.Infer<Bernoulli>(b)
    Console.WriteLine("b: " + post.ToString())
    • Marked as answer by Variable.New Tuesday, January 24, 2012 4:03 AM
    Monday, January 23, 2012 9:46 AM
    Owner

All replies

  • #light

    open System
    open MicrosoftResearch.Infer
    open MicrosoftResearch.Infer.Models
    open MicrosoftResearch.Infer.Distributions
    open MicrosoftResearch.Infer.Factors
           
    let a = Variable.Discrete [|0.2;0.8|]
    let b = Variable.New<bool>()

    let case0 = Variable.Case(a, 0)
    b.SetTo (Variable<bool>.Constant false)
    case0.Dispose()

    let case1 = Variable.Case(a, 1)
    b.SetTo (Variable<bool>.Constant true)
    case1.Dispose()

    let engine = new InferenceEngine()
    let post = engine.Infer<Bernoulli>(b)
    Console.WriteLine("b: " + post.ToString())
    • Marked as answer by Variable.New Tuesday, January 24, 2012 4:03 AM
    Monday, January 23, 2012 9:46 AM
    Owner
  • You can equivalently use the 'using' construct: 

    using (Variable.Case(a, 0)) (fun _ ->   
      b.SetTo (Variable<bool>.Constant false)  
    )  
    
    

    Tuesday, January 24, 2012 9:33 AM
    Owner