locked
Convert 2 variable of Gaussian into a bivariate Gaussian? RRS feed

  • Question

  • I have 2 variable of Gaussian formed from some factors, and I would like to form a Variable of bivariate Gaussian from them.

        let a = Variable.GaussianFromMeanAndVariance(0.01.0)
        let b = Variable.GaussianFromMeanAndVariance(1.02.0)
        let range = Range 2
        let x = Variable.Array range
        x.[0] <- a
        x.[1] <- b
        printfn "%A" (engine.Infer x)
        let y = Variable.Vector(x)
        printfn "%A" (engine.Infer y)

    The above doesn't work.

    I know if I have a VariableArray<double>, then I can simply use Variable.Vector.

    But here I have 2 Variables instead of a Variable Array

    Update:

    I got a workaround, it is quite ugly, and maybe very inefficient.


        let a = Variable.GaussianFromMeanAndVariance(0.01.0)
        let b = Variable.GaussianFromMeanAndVariance(1.02.0)
        let range = Range 2
        let x = Variable.Array<double> range
        using(Variable.ForEach range) (fun rangeBlock -> (Variable.IfBlock (rangeBlock.Index == 0)) (fun _ -> x.[range] <- a) (fun _ -> x.[range] <- b))
        printfn "%A" (engine.Infer x)
        let y = Variable.Vector(x)
        printfn "%A" (engine.Infer y)

    • Edited by colinfang Friday, October 24, 2014 5:06 PM
    Friday, October 24, 2014 4:19 PM

Answers

  • You must use Variable.Copy when making a copy of a variable:

        x.[0] <- Variable.Copy(a)
        x.[1] <- Variable.Copy(b)
    

    • Marked as answer by colinfang Friday, October 24, 2014 7:25 PM
    Friday, October 24, 2014 5:37 PM
    Owner