Menu

Manupulating data in Potential Tables

edj
2011-05-25
2012-09-14
  • edj

    edj - 2011-05-25

    Hi guys

    I am using unbbayes as API in my project. I would like to manupulate the data
    in the Potential tables of a Bayesian Network in unbbayes. I having a problem
    with how the data in Potential tables is organized. I can see that we can use
    linear coordinates or multi-dimensional coordinates to access the data. I
    thought I had an idea of how the multi-dimensional coordinates are organized
    up until I tried to derive the linear coordinates from them. I suspected that
    my problem could have emanated from not understanding how the states are
    modelled. Are they represented by numbers from 0 up to n-1(where n is the
    number of states a variable have). If possible can somebody help me with an
    illustration, using example coordinates, how these coordinates can be
    converted back and forth. Thank you.

     
  • Rommel Novaes Carvalho

    Hi there,

    I was searching on my gmail account to find the answer for your question. I
    was sure I had answered this before! :-)

    Here is a question I received via e-mail:

    Rommel,

    If i have to get the following ouput from he potential table (see values
    below), what are the methods I should use

    Potential table of Node C

    state 0 of Node B and state 0 of Node C corresponds to value 0.5

    state 0 of Node B and state 1 of Node C corresponds to value 0.3

    state 1 of Node B and state 0 of Node C corresponds to value 0.5

    state 1 of Node B and state 1 of Node C corresponds to value 0.7

    Thanks.

    --

    Regards,

    UnBBayes User

    My answer was:

    I am answering without checking the code (from the top of my head), so I
    might get some methods wrong, but you will get the idea.


    ProbabilisticNode node = ...;

    ProbabilisticNode parentNode = ...;

    PotentialTable table = ((PotentialTable)node.getProbabilisticFunction());

    // To get B at state 1 and child node at state 1 (0.7) do

    // number of the variables on the table = number of parents + 1 from the child
    node

    int numberOfVariables = 1 + 1;

    int coord = new coord;

    // coordinate of 0 is always the child node

    coord = 1;

    // for the parents you have to ask for the index

    coord = 1;

    float probability = table.getValueAt(coord);


    As I said, I might have something wrong, but that is the overall idea.

    I hope this answers your question!

    Best,

    Rommel

     
  • Rommel Novaes Carvalho

    Summary:

    ProbabilisticNode node = ...;
    ProbabilisticNode parentNode = ...;
    PotentialTable table = ((PotentialTable)node.getProbabilisticFunction());
    // To get B at state 1 and child node at state 1 (0.7) do
    // number of the variables on the table = number of parents + 1 from the child node
    int numberOfVariables = 1 + 1;
    int[] coord = new coord[numberOfVariables];
    // coordinate of 0 is always the child node
    coord[0] = 1;
    // for the parents you have to ask for the index
    coord[table.indexOfVariable(parentNode)] = 1;
    float probability = table.getValueAt(coord);
    

    I hope this looks better as a code.

    Best,

    Rommel

     

Log in to post a comment.