Due to the need to complete the design, we have been studying Hugin expert recently, a software about Bayesian Networks. Today we have some eyebrows. To sum up, we can make it easier for ourselves and for others.
Hugin expert is a commercial software that provides C, C ++, Java, and ,. net API support and free Hugin lite use. Its Bayesian Network supports discrete and continuous nodes and expressions and Gaussian distribution. This is why Hugin was the final choice after I found a lot of software.
Because I plan to use Java to complete the setup, I started to read only the Java API. I didn't expect this damn Java API document to have no examples. I was so depressed that I couldn't do it, no useful information was found on the Internet. A few days later, I opened the. net api by chance and found some examples in the API. I was very surprised to see it and finally understood it. Then we can just convert. Net to Java. This is difficult for me. I am familiar with Java and. net, and it should be fine. Let's talk about some of the things I got.
In API, the domain class is used most. It refers to a Bayesian Network, and all nodes can be obtained through the getnodes () method. Node represents a node in the Bayes network. It is a base class and its sub-classes include continuouschancenode, discretenode, instancenode, and utilitynode. Among them, continuouschancenode is a continuous node, discretenode is a discrete node, utilitynode is a tool node, instancenode, and I haven't used it yet. Discretenode also has the sub-classes discretechancenode and discretedecisionnode. The longest class is discretechancenode.
To build a Bayesian network, you can load a file or create a new network.CodeDemo: load a network: domain = new domain ("C: \ Program Files \ Hugin expert \ Hugin lite 7.0 \ samples \ fire.net ", new defaultclassparselistener ();, it is easier to create a new network, as long as you call the domian construction without parameters.
Now, because I am not very familiar with the research, I will not do more about it. I will post the Code:
Package com. ssdut. Wangyou;
Import com. Hugin. Hapi .*;
Public class loadandrun {
Public static void main (string [] ARGs) throws exceptionhugin {
Domain domain = new domain ("C :\\ program files \\ Hugin expert \\ Hugin lite 7.0 \ samples \ fire.net", new defaultclassparselistener ());
Domain. openlogfile ("mylog. log ");
Domain. Compile ();
Domain. closelogfile ();
Domain. propagate (domain. h_equilibrium_sum, domain. h_evidence_mode_normal );
Discretechancenode node = (discretechancenode) domain. getnodebyname ("fire ");
Node. selectstate (1 );
Printnodemarginals (domain );
}
Public static void printnodemarginals (domain) throws exceptionhugin
{
Nodelist NLIST = domain. getnodes ();
For (INT I = 0; I <NLIST. Size (); I ++)
{
Discretechancenode node = (discretechancenode) NLIST. Get (I );
Int nstates = node. getnumberofstates ();
System. Out. println (node. getlabel ());
For (Int J = 0; j <nstates; j ++)
{
System. Out. println ("-" + node. getstatelabel (j) + "" + node. getbelief (j )));
}
}
}
}
The above code loads a network, sets the node named fire as evidence, and then shows the probability of all nodes. If you have studied Hugin expert, we can discuss it together. Leave a message.