Dynamic BN

The engine.
Post Reply
shenxu
Posts: 11
Joined: Wed Sep 08, 2010 6:51 pm

Dynamic BN

Post by shenxu »

Hi,

I am using your SMILE lib, and it works good! I am just wandering, if there is any dynamic Bayesian Net libs in SMILE? And is there any simple documents for that?

Thanks a lot!
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

SMILE supports dynamic BNs (DBNs), but the only docs available is this forum thread:

http://genie.sis.pitt.edu/forum/viewtopic.php?f=2&t=223

Feel free to ask more questions on the forum - I'll try to help.
amirsad
Posts: 3
Joined: Mon Apr 24, 2017 7:59 pm

Re: Dynamic BN

Post by amirsad »

Hi,

I'm also looking for a simple document or example how to create and initialize Dynamic Bayesian Networks using SMILE.
I could not find any documentation (except for parameter learning in Wiki), and the link in the previous post does not seem to be up to date.
Is there any resource I am missing?
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

Is there any resource I am missing?
Unfortunately, we don't have proper docs for DBNs in SMILE yet. The link in this thread points to our old forum, which is no longer active. On this forum, use the following link:
http://support.bayesfusion.com/forum/vi ... ?f=2&t=223
ale.mnc
Posts: 9
Joined: Tue Jul 11, 2017 8:45 am

Re: Dynamic BN

Post by ale.mnc »

Hello,
I am reading the draft related to DBNs.
I am wondering how to get access to a specific probability matrix at a specific temporal slice in order to modify the probabilities.

Thank you in advance!
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

You need to get the node's definition and cast it to DSL_cpt, then call GetTemporalProbabilities:

Code: Select all

DSL_cpt* cptDef = static_cast<DSL_cpt *>(net.GetNode(handle)->Definition());
const DSL_Dmatrix* probs = cptDef->GetTemporalProbabilities();
ale.mnc
Posts: 9
Joined: Tue Jul 11, 2017 8:45 am

Re: Dynamic BN

Post by ale.mnc »

That way, I only get access to the matrix but I cannot modify the probabilities.
In case of no temporal slices, I use the following code to get access and modify the probabilities.

DSL_nodeDefinition *successDef = net.GetNode(handle)->Definition();
DSL_doubleArray sp(successDef->GetMatrix()->GetSize());
sp[0] = 0.8; sp[1] = 0.2;
res = successDef->SetDefinition(sp);

Do you have any similar approach in case of temporal slices?
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

Use one of these two methods of the DSL_cpt class:

Code: Select all

int SetTemporalProbabilities(int order, const DSL_Dmatrix &probs); 
int SetTemporalProbabilities(int order, const DSL_doubleArray &probs);
ale.mnc
Posts: 9
Joined: Tue Jul 11, 2017 8:45 am

Re: Dynamic BN

Post by ale.mnc »

I tried the following code to get access to node "Ignition" and modify the CPT at time slice 0.

Code: Select all

int handle = net.FindNode("Ignition");
		if (handle < 0)
		{
			return handle;
		}
		DSL_cpt* cptDef = static_cast<DSL_cpt *>(net.GetNode(handle)->Definition());
		DSL_doubleArray prob0(cptDef->GetTemporalProbabilities(0)->GetSize());
		prob0[0] = 0.99;prob0[1] = 0.01;
		res = cptDef->SetTemporalProbabilities(0, prob0);
Unfortunately the code is crashing and I do not understand the reason.
After updating the beliefs, I try to print the matrix of the beliefs of a target node "Safe" using this code:

Code: Select all

net.UpdateBeliefs();
	DSL_node *f = net.GetNode(target);
	const DSL_beliefVector &beliefs = *f->Value()->GetMatrix();
	for (int i = 0; i < 6; i++)
	{
		printf("Safe=%g at time %d\n", beliefs[i,1], i);
	}
Can you please suggest any possible mistake in my codes?
Thank you!
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

Unfortunately the code is crashing and I do not understand the reason.
Where exactly does the crash happen?
ale.mnc
Posts: 9
Joined: Tue Jul 11, 2017 8:45 am

Re: Dynamic BN

Post by ale.mnc »

I believe it crashes at the GetSize(); to initialize the size of "prob0" to be equal to the CPT size.
shooltz[BayesFusion]
Site Admin
Posts: 1441
Joined: Mon Nov 26, 2007 5:51 pm

Re: Dynamic BN

Post by shooltz[BayesFusion] »

Code: Select all

    DSL_doubleArray prob0(cptDef->GetTemporalProbabilities(0)->GetSize());
The temporal probabilities have positive orders (related to the order of the incoming temporal arcs). Calling DSL_cpt::GetTemporalProbabilities(0) returns NULL, which is dereferenced for GetSize(). This causes the crash.

For the conditional probabilities between the node in the same slice use non-temporal functions.
Post Reply