Author Topic: how to get the final CPT values  (Read 14618 times)

Offline coldfire

  • Newbie
  • *
  • Posts: 13
    • View Profile
how to get the final CPT values
« on: June 12, 2009, 18:09:41 »
hugin newbie..


Lets suppose I have two trees, each having 3 parents and 1 child,

I want to compare their probabilities as P1(A1|B1,C1,D1) and P2(A2|B2,C2,D2), where as the 3 parents are independent of each other.

how to do this via API?

Offline Martin

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 613
    • View Profile
Re: how to get the final CPT values
« Reply #1 on: June 15, 2009, 12:27:28 »
Here are some info to get you started. Please also consult the Hugin Java API javadoc - and the sample code provided in the bottom of the package overview in the javadoc as well (the build and propagate example demonstrates constructing a net in code and propagating evidence). Inspecting the methods on the Domain and DiscreteChanceNode classes in the documentation should be helpfull for your purpose.

Here are some of the basic steps for entering evidence and getting beliefs:
Acquire references to nodes and assuming the nodes are discrete, cast them to DiscreteChanceNode:
Code: [Select]
Domain d = ...;
DiscreteChanceNode A1 = (DiscreteChanceNode)d.getNodeByName("A1");
...

Enter evidence by selecting states for the parent nodes:
Code: [Select]
B1.selectState(...);
C1.selectState(...);
...

Then propagate evidence, and read out belief for specific state on target node:
Code: [Select]
d.propagate(...);
double belief = A1.getBelief(...);
...
« Last Edit: June 15, 2009, 12:29:02 by Martin Karlsen »
Hugin Expert A/S

Offline coldfire

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: how to get the final CPT values
« Reply #2 on: June 27, 2009, 17:26:10 »
(in connection to my initial post in the thread)

I have to generate the CPT for a v.simple scenario using Java API, of which I am not used to.

I have this (sample) problem of calculating the conditional probability table of the scenario that "Its raining"

it has two parent conditions,
either the ground is wet or not wet, and
either clouds are present or not present.

Now, the CPT table will contain 8 values to be filled in for the case of "is it raining or not".

(as it seems, the W and C are independent )

So, to find, P(R|W,C) = P(W|R,C) P(R|C) / P(W|C)

But, this formula doesnt solve my problem, I need to assume the 8 values that if,

- ground is Wet and Clouds are present than P(raining) is 1 else 0
- ground is Wet and Clouds are not present than P(raining) is 0.8 else
0.2
- ground is not Wet and Clouds are present than P(raining) is 0.2 else 0.8
- ground is not Wet and Clouds are not present than P(raining) is 0 else 1


Can I do it via some formula/API ? If even I have to put the CPT (conditional probability table) values myself, but what to do when I have to see the effect of "Likelihood" of some event (in this case the likelihood of W and C), i.e. lets say the likelihood of W is 70% and likelihood of C is 50%. How does it affect the CPT values ?????

Any formula or way to find CPT with likelihood condition ?

Thanks in advance.

Offline coldfire

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: how to get the final CPT values
« Reply #3 on: June 29, 2009, 11:22:24 »
what can be the EXPRESSION for the distribution of probabilities for the above scenario where

child node has two or more parents, and its probability depends on them. For less number of parents, its easier to adapt CPT values explicitly but for more parents its not feasible as the CPT size grows exponentially.

« Last Edit: June 29, 2009, 13:46:03 by coldfire »