Tuesday, August 25, 2015

Perkun model.

The time has come to learn the last part of the Perkun (http://sourceforge.net/projects/perkun/) program: the model. We know already how to declare the variables (input,output or hidden ones) and how to define the payoff, i.e. tell Perkun which input variable values are good and which are not so good. In order to do its job Perkun needs to know how its decisions will affect the world, i.e. how the world state in the future depends on its state now and the Perkun's choices.

Imagine a world where we have only one variable - input variable alpha. Its value can be either false or true. Let us introduce an output variable beta which can control two actions:
  • do_nothing - alpha remains as it is now
  • switch - alpha switches to not alpha
Let us further assume that Perkun "likes" alpha=true, and "dislikes" alpha=false. For this simple world our Perkun program will look as follows:

values
{
    value false, true, do_nothing, switch;
}
variables
{
    input variable alpha:{false, true};
    output variable beta:{do_nothing, switch};
}
payoff
{
    set({alpha=>false},0.0);
    set({alpha=>true},100.0);
}
model
{
    set({alpha=>false},{beta=>do_nothing},{alpha=>false},1.0);
    set({alpha=>false},{beta=>do_nothing},{alpha=>true},0.0);
    set({alpha=>true},{beta=>do_nothing},{alpha=>false},0.0);
    set({alpha=>true},{beta=>do_nothing},{alpha=>true},1.0);

    set({alpha=>false},{beta=>switch},{alpha=>false},0.0);
    set({alpha=>false},{beta=>switch},{alpha=>true},1.0);
    set({alpha=>true},{beta=>switch},{alpha=>false},1.0);
    set({alpha=>true},{beta=>switch},{alpha=>true},0.0);
}

cout << model << eol;

The model section is filled with the set instructions, but they have slightly different syntax than the set instructions we know from the payoff section. Each set instruction in the model section has syntax:

set(INITIAL_STATE_QUERY,ACTION_QUERY,TERMINAL_STATE_QUERY,VALUE);

The INITIAL_STATE_QUERY and TERMINAL_STATE_QUERY are regular queries containing all input and hidden variables.

The ACTION_QUERY is a regular query containing all output variables.

The VALUE is a probability value.

In short set(A,B,C,D) means "if A and you do B then the probability to jump to C is D".

When you put the above Perkun code in a file and execute it with perkun it will write down:

# model
# {beta=>do_nothing}
set({alpha=>false },{beta=>do_nothing },{alpha=>false },1.00000);
set({alpha=>false },{beta=>do_nothing },{alpha=>true },0.00000);

# {beta=>switch}
set({alpha=>false },{beta=>switch },{alpha=>false },0.00000);
set({alpha=>false },{beta=>switch },{alpha=>true },1.00000);

# {beta=>do_nothing}
set({alpha=>true },{beta=>do_nothing },{alpha=>false },0.00000);
set({alpha=>true },{beta=>do_nothing },{alpha=>true },1.00000);

# {beta=>switch}
set({alpha=>true },{beta=>switch },{alpha=>false },1.00000);
set({alpha=>true },{beta=>switch },{alpha=>true },0.00000);


It will be done by the command "cout << model << eol;".

Note that the sum of the probabilities over the terminal state queries equals 1.0 for each initial state query and each action query. Perkun checks this with a certain tolerance (and shows a warning on models that violate this rule).

Creating the Perkun models is difficult. The difficulty is of the quantitative nature - they tend to be very big. If you skip the set instructions in the model section the model will be random. Try running with perkun the following code:

values { value false,true; }
variables {
input variable a:{false,true},b:{false,true},c:{false,true},d:{false,true},e:{false,true};
output variable f:{false,true},g:{false,true},h:{false,true};
}
payoff {}
model {}
cout << model << eol;


The model printed out will likely be bigger than 1MB of code. Remember, the models "explode" with the number of variables.

Congratulations, now you know everything what you have to tell Perkun. Values, variables, payoff, model. The time has come to see what Perkun can do for you given this information. It will attempt to maximize the expected value of the payoff function by appropriate choosing the actions. First you give it current values of the input variables, then it responds with the optimal action chosen (the values of the output variables). As you can see we will interact with Perkun and this interaction will involve both input and output. But this will be discussed in the next post.

No comments:

Post a Comment