Reading Hugin Influence Diagram (.net) files

The engine.
Post Reply
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Reading Hugin Influence Diagram (.net) files

Post by fad777 »

Hi,
The API reads Hugin .net influence diagram files incorrectly. Specifically, the value/utility nodes lose their values; all the values are ones.
Please, could you help with this?
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

fad777 wrote:The API reads Hugin .net influence diagram files incorrectly. Specifically, the value/utility nodes lose their values; all the values are ones.
The support for Hugin in SMILE files dates back to late 1990's. The format was probably extended since then. If you post the file which loads incorrectly here, we'll be able to estimate how much effort is required to support it.
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

Please, find the file posted below.
Thanks for your reply.
net
{
node_size = (80 40);
HR_Monitor_Utility_Arrange = "0";
HR_Monitor_Chance_Utility = "1";
HR_Compile_SaveToMemory = "0";
HR_Desc = "";
HR_OOBN_CheckConsistency = "1";
HR_OOBN_FitExpand = "1";
HR_Zoom_ZoomFactor = "100";
HR_Groups_GroupColors = "";
HR_Groups_GroupNames = "";
HR_Groups_UserGroupsNo = "0";
HR_Color_Interface = "-1";
HR_Color_Instance = "-1";
HR_Color_Utility = "-1";
HR_Color_Decision = "-1";
HR_Color_ContinuousChance = "-1";
HR_Color_DiscreteChance = "-1";
HR_Monitor_InitSD = "2";
HR_Monitor_InitStates = "5";
HR_Monitor_OpenGraph = "0";
HR_Monitor_GraphPrecision = "100";
HR_Monitor_AutoUpdGraph = "0";
HR_Compile_MaxMinimalSeparators = "100000";
HR_Compile_ApproxEpsilon = "1.0E-5";
HR_Compile_Approximate = "0";
HR_Compile_Compress = "0";
HR_Compile_TriangMethod = "0";
HR_Propagate_AutoNormal = "1";
HR_Propagate_AutoSum = "1";
HR_Propagate_Auto = "1";
HR_Font_Italic = "0";
HR_Font_Weight = "400";
HR_Font_Size = "-12";
HR_Font_Name = "Arial";
HR_Grid_GridShow = "0";
HR_Grid_GridSnap = "0";
HR_Grid_Y = "40";
HR_Grid_X = "40";
}

node C16
{
label = "O4";
position = (56 123);
states = ("" "");
HR_LinkMode = "[D14:0]";
}

node C15
{
label = "S4";
position = (78 223);
states = ("" "");
HR_LinkMode = "[C11:0][U13:0][C16:0]";
}

decision D14
{
label = "D4";
position = (170 136);
states = ("" "" "");
HR_LinkMode = "[D13:0][C11:0][C12:0][U13:0]";
}

utility U13
{
label = "U4";
position = (184 243);
}

node C12
{
label = "O3";
position = (386 140);
states = ("" "");
HR_LinkMode = "[D13:0]";
}

node C11
{
label = "S3";
position = (400 267);
states = ("" "");
HR_LinkMode = "[C6:0][U9:0][C12:0]";
}

decision D13
{
label = "D3";
position = (492 111);
states = ("" "" "");
HR_LinkMode = "[C4:0][D5:0][C6:0][U9:0]";
}

utility U9
{
label = "U3";
position = (509 286);
}

node C14
{
label = "O1";
position = (1112 95);
states = ("GL" "GR");
HR_LinkMode = "[D10:0][D1_1:0][S1_1:0][S:0][D:0][C2:0][D1:0][D2:0][D2_1:0]";
HR_State_5 = "";
HR_State_4 = "";
HR_State_3 = "";
HR_State_2 = "";
HR_Desc = "";
HR_State_1 = "";
HR_State_0 = "";
HR_Group = "0";
}

node C13
{
label = "S1";
position = (1114 344);
states = ("TL" "TR");
HR_LinkMode = "[C14:0][U11:0][U2_1:0][O2_1:0][U1_1:0][U1:0][U2:0][O2:0]";
HR_Desc = "";
HR_State_1 = "";
HR_State_0 = "";
HR_Group = "0";
}

utility U11
{
label = "U1";
position = (1286 340);
HR_Desc = "";
HR_Group = "0";
}

decision D10
{
label = "D1";
position = (1283 143);
states = ("OL" "OR" "L");
HR_LinkMode = "[U11:0][U1_1:0][U1:0][U2:0][U2_1:0]";
HR_State_2 = "";
HR_Desc = "";
HR_State_1 = "";
HR_State_0 = "";
HR_Group = "0";
}

utility U7
{
label = "U2";
position = (879 325);
HR_Desc = "";
HR_Group = "0";
}

node C6
{
label = "S2";
position = (740 298);
states = ("TL" "TR");
HR_LinkMode = "[C13:0][U7:0][C4:0][U2:0][S2_1:0][O2:0][U1:0][U1_1:0]";
HR_State_0 = "";
HR_State_1 = "";
HR_Desc = "";
HR_Group = "0";
}

decision D5
{
label = "D2";
position = (870 147);
states = ("OL" "OR" "L");
HR_LinkMode = "[C14:0][C13:0][D10:0][U7:0][O2_1:0][S2_1:0][D2_1:0][U2:0][U1:0][U1_1:0]";
HR_State_0 = "";
HR_State_1 = "";
HR_Desc = "";
HR_State_2 = "";
HR_Group = "0";
}

node C4
{
label = "O2";
position = (738 100);
states = ("GL" "GR");
HR_LinkMode = "[D5:0][D2:0][D1:0][C2:0][D:0][S:0][S1_1:0][D1_1:0]";
HR_State_5 = "";
HR_State_4 = "";
HR_State_3 = "";
HR_State_2 = "";
HR_State_0 = "";
HR_State_1 = "";
HR_Desc = "";
HR_Group = "0";
}

potential (C16 | C15)
{
data
= (( 0.85 0.15 ) % C15=<0>
( 0.15 0.85 )); % C15=<1>
}

potential (C15)
{
data = ( 1 1 );
}

potential (D14 | C16)
{
data
= (( 1 1 1 ) % C16=<0>
( 1 1 1 )); % C16=<1>
}

potential (U13 | C15 D14)
{
data
= (( -100 % C15=<0> D14=<0>
10 % C15=<0> D14=<1>
-1 ) % C15=<0> D14=<2>
( 10 % C15=<1> D14=<0>
-100 % C15=<1> D14=<1>
-1 )); % C15=<1> D14=<2>
}

potential (C12 | C11 D14)
{
data
= ((( 0.5 0.5 ) % C11=<0> D14=<0>
( 0.5 0.5 ) % C11=<0> D14=<1>
( 0.85 0.15 )) % C11=<0> D14=<2>
(( 0.5 0.5 ) % C11=<1> D14=<0>
( 0.5 0.5 ) % C11=<1> D14=<1>
( 0.15 0.85 ))); % C11=<1> D14=<2>
}

potential (C11 | C15 D14)
{
data
= ((( 0.5 0.5 ) % C15=<0> D14=<0>
( 0.5 0.5 ) % C15=<0> D14=<1>
( 1 0 )) % C15=<0> D14=<2>
(( 0.5 0.5 ) % C15=<1> D14=<0>
( 0.5 0.5 ) % C15=<1> D14=<1>
( 0 1 ))); % C15=<1> D14=<2>
}

potential (D13 | D14 C12)
{
data
= ((( 1 1 1 ) % D14=<0> C12=<0>
( 1 1 1 )) % D14=<0> C12=<1>
(( 1 1 1 ) % D14=<1> C12=<0>
( 1 1 1 )) % D14=<1> C12=<1>
(( 1 1 1 ) % D14=<2> C12=<0>
( 1 1 1 ))); % D14=<2> C12=<1>
}

potential (U9 | C11 D13)
{
data
= (( -100 % C11=<0> D13=<0>
10 % C11=<0> D13=<1>
-1 ) % C11=<0> D13=<2>
( 10 % C11=<1> D13=<0>
-100 % C11=<1> D13=<1>
-1 )); % C11=<1> D13=<2>
}

potential (C14 | C13 D5)
{
data
= ((( 0.5 0.5 ) % C13=TL D5=OL
( 0.5 0.5 ) % C13=TL D5=OR
( 0.85 0.15 )) % C13=TL D5=L
(( 0.5 0.5 ) % C13=TR D5=OL
( 0.5 0.5 ) % C13=TR D5=OR
( 0.15 0.85 ))); % C13=TR D5=L
}

potential (C13 | C6 D5)
{
data
= ((( 0.5 0.5 ) % C6=TL D5=OL
( 0.5 0.5 ) % C6=TL D5=OR
( 1 0 )) % C6=TL D5=L
(( 0.5 0.5 ) % C6=TR D5=OL
( 0.5 0.5 ) % C6=TR D5=OR
( 0 1 ))); % C6=TR D5=L
}

potential (U11 | C13 D10)
{
data
= (( -100 % C13=TL D10=OL
10 % C13=TL D10=OR
-1 ) % C13=TL D10=L
( 10 % C13=TR D10=OL
-100 % C13=TR D10=OR
-1 )); % C13=TR D10=L
}

potential (D10 | D5 C14)
{
data
= ((( 1 1 1 ) % D5=OL C14=GL
( 1 1 1 )) % D5=OL C14=GR
(( 1 1 1 ) % D5=OR C14=GL
( 1 1 1 )) % D5=OR C14=GR
(( 1 1 1 ) % D5=L C14=GL
( 1 1 1 ))); % D5=L C14=GR
}

potential (U7 | C6 D5)
{
data
= (( -100 % C6=TL D5=OL
10 % C6=TL D5=OR
-1 ) % C6=TL D5=L
( 10 % C6=TR D5=OL
-100 % C6=TR D5=OR
-1 )); % C6=TR D5=L
}

potential (C6 | C11 D13)
{
data
= ((( 0.5 0.5 ) % C11=<0> D13=<0>
( 0.5 0.5 ) % C11=<0> D13=<1>
( 1 0 )) % C11=<0> D13=<2>
(( 0.5 0.5 ) % C11=<1> D13=<0>
( 0.5 0.5 ) % C11=<1> D13=<1>
( 0 1 ))); % C11=<1> D13=<2>
}

potential (D5 | D13 C4)
{
data
= ((( 1 1 1 ) % D13=<0> C4=GL
( 1 1 1 )) % D13=<0> C4=GR
(( 1 1 1 ) % D13=<1> C4=GL
( 1 1 1 )) % D13=<1> C4=GR
(( 1 1 1 ) % D13=<2> C4=GL
( 1 1 1 ))); % D13=<2> C4=GR
}

potential (C4 | C6 D13)
{
data
= ((( 0.5 0.5 ) % C6=TL D13=<0>
( 0.5 0.5 ) % C6=TL D13=<1>
( 0.85 0.15 )) % C6=TL D13=<2>
(( 0.5 0.5 ) % C6=TR D13=<0>
( 0.5 0.5 ) % C6=TR D13=<1>
( 0.15 0.85 ))); % C6=TR D13=<2>
}
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

The bugfix is ready. Which platform are you using? I'd like to avoid rebuilding all binaries we support.
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

Red Hat Enterprise Linux Workstation (6.5)
I develop on both 32 and 64 bits machines.

I highly appreciate your help, and what you do.

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

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

fad777 wrote:Red Hat Enterprise Linux Workstation (6.5)
I develop on both 32 and 64 bits machines.
Are you using C++ SMILE or the Java wrapper?
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

C++ SMILE.
Thanks!
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

fad777 wrote:C++ SMILE.
The update for Linux/gcc 4.4.5 is online.
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

Hi,

Thanks for the quick response.

I tested the new API with the following snippet:
Note: the file read was the previous file posted.

Code: Select all

if(strstr(filename,".xdsl")){
        	if(theDBN.ReadFile(filename,DSL_XDSL_FORMAT)!= DSL_OKAY) {
			 cout <<"Failed to read file "<<endl;
			 return;
 		}
	}
	else if(strstr(filename,".net")){
		 if(theDBN.ReadFile(filename,DSL_HUGIN_FORMAT)!= DSL_OKAY) {
			 cout <<"Failed to read file "<<endl;
			 return;
		}
		else{
			theDBN.WriteFile("temp.xdsl",DSL_XDSL_FORMAT);
			
		}
		
	}
The output file (temp.xdsl) contains only the header information; all the details are lost.
Please, is there anything I am missing ?

I work with these two formats, and sometimes it becomes necessary to do this conversion from .net to .xdsl. Also because
as mentioned in the docs, not all features are supported by the lib. with the other formats.

Thanks for your help.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

Please, is there anything I am missing ?
Probably not. You can skip explicit format specification when passing the filename to ReadFile/WriteFile, assuming the proper extension.

Try this and check the output:

Code: Select all

int foobar(const char *filename) 
{
	ErrorH.RedirectToFile(stdout);

	DSL_network net;
	
	int res = net.ReadFile(filename);
	if (DSL_OKAY != res) 
	{
		return res;
	}

	for (int h = net.GetFirstNode(); h >= 0; h = net.GetNextNode(h))
	{
		DSL_node *n = net.GetNode(h);
		DSL_nodeDefinition *def = n->Definition();
		printf("%d %s %s\n", h, def->GetTypeName(), n->GetId());
		const DSL_Dmatrix *mtx = def->GetMatrix();
		if (NULL != mtx)
		{
			printf("  ");
			for (int i = 0; i < mtx->GetSize(); i ++)
			{
				printf("%g ", (*mtx)[i]);
			}
			printf("\n");
		}
	}

	return 0;
}
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

Please, see below for the error message when I run foobar("T4.net").
-126: ERROR: Line 1 : UNKNOWN CHARACTER
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by shooltz[BayesFusion] »

fad777 wrote:Please, see below for the error message when I run foobar("T4.net").
-126: ERROR: Line 1 : UNKNOWN CHARACTER
This is caused by CR/LF endline characters from Windows. You'll need to convert them to Unix-style LF only.
fad777
Posts: 7
Joined: Wed Feb 05, 2014 5:26 pm

Re: Reading Hugin Influence Diagram (.net) files

Post by fad777 »

The recommended conversion worked.

NB to potential victims: My colleague generated the Hugin files on Windows platform.

I have verified the values reading of the utility nodes, that also works.



Thanks for your timely support.
Post Reply