Structured CPT in infer.NET RRS feed

  • Question

  • Hi,

    Is is possible to define structured CPTs in infer.NET.In particular I am looking for a code that can define a "Multiplexer CPD" i.e

    P(Y|A,Z1,Z2,..,Zk)={ 1 , if Y=ZA;

                                    0 , otherwise }

    And A is the multiplexer variable and Val(A)={1,2,...,k}.The corresponding model looks li

    A---> Y<---Zk
             | |
             | |
          Z1 Z2

    E.g if the value of A is 2 the value of the deterministic variable Y will be equal to Z2.Therefore ,Y is a copy of ZA and the Random variable A ranges from 1 to k.

    Saturday, July 28, 2012 11:28 AM


  • Farhan

    Here is the basic model code for a single Y:

    // The model  
    var K = Variable.New<int>();  
    Range k = new Range(K);  
    var ZPrior = Variable.Array<Discrete>(k);  
    var Z = Variable.Array<int>(k);  
    Z[k] = Variable<int>.Random(ZPrior[k]);  
    var APrior = Variable.New<Discrete>();  
    var A = Variable<int>.Random(APrior);  
    var Y = Variable.New<int>();  
    using (Variable.Switch(A))  

    You can hook up priors for A and Z as follows, and infer Y:

    // Setting the data  
    APrior.ObservedValue = new Discrete(.2, .8);  
    Discrete[] zPriors = new Discrete[] { new Discrete(0.2, 0.3, 0.5), new Discrete(0.4, 0.5, 0.1) };  
    K.ObservedValue = zPriors.Length;  
    ZPrior.ObservedValue = zPriors;  
    // Inferring Y  
    var engine = new InferenceEngine();  
    If you want to observe Y instead and infer Z and/or A, the make Y a VariableArray rather than a Variable, and observe Y.
    • Marked as answer by Farhan Khawar Thursday, August 2, 2012 10:26 PM
    Monday, July 30, 2012 9:29 AM