Saturday, August 29, 2015

Perkun. The impossible states.

I hope you remember that a Perkun (http://sourceforge.net/projects/perkun/) model can be represented as a collection of directed graphs, each graph for one action (fixed values of the output variables). It may happen that in these graphs certain states cannot be achieved. It is the case in the file dorban_general.perkun. It contains the following variables:

input variable where_is_Dorban:{place_Wyzima,place_Shadizar,place_Novigrad};
input variable do_I_see_vampire:{false,true};
output variable action:{do_nothing,goto_Wyzima,goto_Shadizar,goto_Novigrad};
hidden variable where_is_vampire:{place_Wyzima,place_Shadizar,place_Novigrad};


Obviously Dorban cannot see the vampire if it is in a different town. What does it mean? For example that the following state is impossible:

where_is_Dorban=>place_Wyzima
do_I_see_vampire=>true
where_is_vampire=>place_Shadizar

There is an instruction for the model section that denotes that. It is called "impossible". Grep the file dorban_general.perkun for this instruction.


$ grep "impossible" dorban_general.perkun
impossible({where_is_Dorban=>place_Wyzima, do_I_see_vampire=>false, where_is_vampire=>place_Wyzima}); # Dorban must see vampire
impossible({where_is_Dorban=>place_Wyzima, do_I_see_vampire=>true, where_is_vampire=>place_Shadizar}); # Dorban cannot see vampire
impossible({where_is_Dorban=>place_Wyzima, do_I_see_vampire=>true, where_is_vampire=>place_Novigrad}); # Dorban cannot see vampire
impossible({where_is_Dorban=>place_Shadizar, do_I_see_vampire=>false, where_is_vampire=>place_Shadizar}); # Dorban must see vampire
impossible({where_is_Dorban=>place_Shadizar, do_I_see_vampire=>true, where_is_vampire=>place_Wyzima}); # Dorban cannot see vampire
impossible({where_is_Dorban=>place_Shadizar, do_I_see_vampire=>true, where_is_vampire=>place_Novigrad}); # Dorban cannot see vampire
impossible({where_is_Dorban=>place_Novigrad, do_I_see_vampire=>false, where_is_vampire=>place_Novigrad}); # Dorban must see vampire
impossible({where_is_Dorban=>place_Novigrad, do_I_see_vampire=>true, where_is_vampire=>place_Wyzima}); # Dorban cannot see vampire
impossible({where_is_Dorban=>place_Novigrad, do_I_see_vampire=>true, where_is_vampire=>place_Shadizar}); # Dorban cannot see vampire


Its syntax is:
impossible(STATE_QUERY);

The STATE_QUERY contains values of the input and hidden variables.

OK. Now you know enough to execute the file dorban_general.perkun with perkun. Just one more word about the payoff. Dorban is a witcher and will try to find the vampire. In other words, he likes to see the vampire. Let us start:

$ perkun dorban_general.perkun
loop with depth 3
I expect the values of the variables: where_is_Dorban do_I_see_vampire
perkun>


We need to enter the values for where_is_Dorban and do_I_see_vampire. Let us assume Dorban is in Shadizar and the vampire is in Novigrad. This implies that Dorban cannot see the vampire.

perkun> place_Shadizar false
belief:
where_is_vampire=place_Wyzima where_is_Dorban=place_Shadizar do_I_see_vampire=false 0.5
where_is_vampire=place_Shadizar where_is_Dorban=place_Shadizar do_I_see_vampire=false 0
where_is_vampire=place_Novigrad where_is_Dorban=place_Shadizar do_I_see_vampire=false 0.5
optimal action:
action=goto_Wyzima
perkun>


There is something interesting about the belief. Perkun assumes with 50% that the vampire is in Wyzima and 50% that he is in Novigrad. Quite correct! The vampire is not in Shadizar, because Dorban cannot see him. The decision is goto_Wyzima. Let us do it:

perkun> place_Wyzima false
belief:
where_is_vampire=place_Wyzima where_is_Dorban=place_Wyzima do_I_see_vampire=false 0
where_is_vampire=place_Shadizar where_is_Dorban=place_Wyzima do_I_see_vampire=false 0
where_is_vampire=place_Novigrad where_is_Dorban=place_Wyzima do_I_see_vampire=false 1
optimal action:
action=goto_Novigrad
perkun> 


Now Dorban is sure that the vampire is in Novigrad! And he wants to go there! Correct.


No comments:

Post a Comment