locked
How to accomplish the very first step RRS feed

  • Question

  • Trying to learn both Infer.net and all the theroy behind at the same time it isn't easy. Here's what I'm stepping over right now: I read the Whodunit example in "An Introduction to Infer.NET" and thought I understood it well. Now I'm trying to model the simple example (two variables: culprit and weapon) in my very first lines in infer.net and got stuck with two things:

    1. After defining the two Enum-Variables (culprit, weapon), how do I model their cause-effect relationship (First the "culprit experiment" and then the "weapon experiment"? 

    2. How do I define the different probabilities for the weapon variable conditioned on the different possible culprits?

    A small example in "An Introduction to Infer.NET" on how this example can be cast into code would make the document a real introduction. 

    Any help would greatly be appreciated.

    Thursday, February 5, 2015 5:44 PM

Answers

  • It'll be something like:

    var murderer = Variable.Bernoulli(priorMurderer1);
    var weapon = Variable.New<int>();
    weapon.SetValueRange(new Range(2));
    
    using (Variable.If(murderer))
    {
    	weapon.SetTo(Variable.Discrete(new[] { priorWeapon1GivenMurderer1, priorWeapon2GivenMurderer1 }));
    }
    
    using (Variable.IfNot(murderer))
    {
    	weapon.SetTo(Variable.Discrete(new[] { priorWeapon2GivenMurderer1, priorWeapon2GivenMurderer2 }));
    }
    
    weapon.ObservedValue = (weaponObserved == Weapon1) ? 0 : 1;
    var posterior = engine.Infer<Bernoulli>(murderer);

    A much more extensive example of a similar type of a model can be found here.

    -Y-

    Friday, February 6, 2015 2:28 PM

All replies

  • It'll be something like:

    var murderer = Variable.Bernoulli(priorMurderer1);
    var weapon = Variable.New<int>();
    weapon.SetValueRange(new Range(2));
    
    using (Variable.If(murderer))
    {
    	weapon.SetTo(Variable.Discrete(new[] { priorWeapon1GivenMurderer1, priorWeapon2GivenMurderer1 }));
    }
    
    using (Variable.IfNot(murderer))
    {
    	weapon.SetTo(Variable.Discrete(new[] { priorWeapon2GivenMurderer1, priorWeapon2GivenMurderer2 }));
    }
    
    weapon.ObservedValue = (weaponObserved == Weapon1) ? 0 : 1;
    var posterior = engine.Infer<Bernoulli>(murderer);

    A much more extensive example of a similar type of a model can be found here.

    -Y-

    Friday, February 6, 2015 2:28 PM
  • Thanks a lot for giving me directions. That helps a lot!

    Christoph

    Monday, February 9, 2015 2:43 PM