equation node

The engine.
Post Reply
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

equation node

Post by aminsabet »

hi
i am a beginning in SMILE and GENIE , my network is big and has about 2000 nodes. The input nodes are continuous with normal
distribution and the other nodes should be defined as an equation (for example, if node1 and node2 be the parents of node3, then
node3 will be defined as min(node2,node1)+normal(mu,sigma)).i could do this with small network in GENIE and my results were
resealable. Just i have a couple of questions and i will appreciate your quick answer.

1)can i use GeNIE to implement such a big network? or i should use smile?

2)if i can use GeNie how can i load my network in Genie utilizing adjacent matrix or something like that? how should i assign an equation to each node?

3)if i use SMILE ,what is the exact syntax for defining a node like min(node2,node1)+normal(mu,sigma) and input nodes with normal distribution.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: equation node

Post by shooltz[BayesFusion] »

aminsabet wrote:1)can i use GeNIE to implement such a big network? or i should use smile?
The limiting factor is the size of memory structures SMILE needs to perform inference on the network. GeNIe won't add much memory overhead.
2)if i can use GeNie how can i load my network in Genie utilizing adjacent matrix or something like that? how should i assign an equation to each node?
If you already have the adjacency matrix and know the general type of the equations in the network, it's best to write a program using SMILE (or jSMILE) to convert this information into .xdsl file which you can later use with GeNIe.
3)if i use SMILE ,what is the exact syntax for defining a node like min(node2,node1)+normal(mu,sigma) and input nodes with normal distribution.
You'll have to get the access to equation node's definition by casting the result of DSL_node::Definition call to DSL_equation. Then you'll be able to call DSL_equation::SetEquation; it's 1st parameter is the equation string. In your case it should be like this:

Code: Select all

node3=min(node2,node1)+normal(mu,sigma)
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

Re: equation node

Post by aminsabet »

Thank you very much for your immediate answer.

I still have problems with my nodes and network in Smile. Due to some deadlines related to my project, I need to do an exact inference for my network as a part of my project as soon as possible. I have already attached the xdls file of the network to my previous post in Genie. I will be truly grateful if you could kindly provide me with the Smile code of this network.

Thank you very much again.
Attachments
Network.xdsl
(2.22 KiB) Downloaded 534 times
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: equation node

Post by shooltz[BayesFusion] »

aminsabet wrote:I need to do an exact inference for my network
The network you've attached contains probability distributions. The inference will produce samples for each node, not an exact numeric value.
I will be truly grateful if you could kindly provide me with the Smile code of this network.
Not sure what you mean by "SMILE code of this network". To build equation network you can use the DSL_equation::SetEquation method, as in the snippet below:

Code: Select all

int h1 = net.AddNode(DSL_EQUATION, "x1");
int h2 = net.AddNode(DSL_EQUATION, "x2");
int h3 = net.AddNode(DSL_EQUATION, "x3");
static_cast<DSL_equation *>(net.GetNode(h1)->Definition())->SetEquation("x1=normal(0,0.1)");
static_cast<DSL_equation *>(net.GetNode(h2)->Definition())->SetEquation("x2=normal(1,0.2)");
static_cast<DSL_equation *>(net.GetNode(h3)->Definition())->SetEquation("x3=min(x1,x2)+normal(0,0.5)");
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

Re: equation node

Post by aminsabet »

By ''smile code'' I mean creating a Bayesian Network which contains node definition, network creation, performing an exact or approximate inference and saving the sample values.
As you mentioned the inference procedure produces samples instead of the exact values. How can i define the number of samples which is produced?
Thank you for your kind help.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: equation node

Post by shooltz[BayesFusion] »

aminsabet wrote:How can i define the number of samples which is produced?
Call DSL_network::SetNumberOfSamples. To retrieve samples, cast the output from DSL_node::Value to DSL_valEqEvaluation and call DSL_valEqEvaluation::GetSamples.
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

Re: equation node

Post by aminsabet »

thank you so much for your kind help

1:I have a conceptual question and i will be very thankful if you answer them ,I know in the Bayesian network all of the nodes have a CPT or CPD except from the root nodes ,In my previous question i defined a node as "node3=min(node2,node1)+normal(mu,sigma)" ,I was wondering what the CPT or CPD of this node can be.

2:Also i was wondering why there is not any difference in the obtained elapsed time when i perform the exact and approximate inference in GENIE in my previous defined network even for big network.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: equation node

Post by shooltz[BayesFusion] »

aminsabet wrote:1:I have a conceptual question and i will be very thankful if you answer them ,I know in the Bayesian network all of the nodes have a CPT or CPD except from the root nodes ,In my previous question i defined a node as "node3=min(node2,node1)+normal(mu,sigma)" ,I was wondering what the CPT or CPD of this node can be.
The equation is the conditional probability distribution in this case.
2:Also i was wondering why there is not any difference in the obtained elapsed time when i perform the exact and approximate inference in GENIE in my previous defined network even for big network.
If your network has equation nodes and at least one node has probabability distribution in its equation (like Normal), GeNIe will perform inference with sampling algorithm, regardless of your choice of algorithm in the 'Network' menu.
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

Re: equation node

Post by aminsabet »

As you mentioned earlier,Inference will produce samples in my network case,When I run the network in GENIE, i can get the mean and variance of each node which is my required parameters. but since my network is too big i can not get the the mean and variance of all of the nodes manually. Hence i need to access these values in Smile.I should save the samples of each node in an array in order to calculate the mean and variance values. I am writing the code for saving samples of "h22_22" node below ,but i don't know how to save "the GetSamples" function return values in an array, Is there any direct way to access the mean or variance of a node, if not, how can I save the " GetSamples" return values in an array (please kindly give me the exact Syntax)

void InfereceWithBayesNet(void){
DSL_network theNet;
theNet.ReadFile("tutorial.xdsl");
theNet.SetDefaultBNAlgorithm(DSL_ALG_BN_LSAMPLING);
theNet.UpdateBeliefs();
int result= theNet.FindNode("h22_22");
DSL_valEqEvaluation theValue(forecast,&theNet);
theValue.GetSamples();

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

Re: equation node

Post by shooltz[BayesFusion] »

aminsabet wrote:Is there any direct way to access the mean or variance of a node
The GetSamples function returns the const reference to vector of weighted samples. Each sample consists of (value, weight) pair. In your case all the weights will be equal to 1.0, so you can ignore them.

If you only need mean and standard deviation, you can use GetSampleMean() and GetSampleStdDev() methods. GetStats will return these two values along with min/max value. You can also iterate over samples with GetSample(int index) method.
aminsabet
Posts: 6
Joined: Mon Jan 19, 2015 7:37 am

Re: equation node

Post by aminsabet »

Thank you for your kind help
As I mentioned in my previous post, in the final step of my project I have to determine the mean and stdDev of my output nodes. In according to your comments I
used the "GetSampleMean()" and "GetSampleStdDev()" functions in order to determine these values but it seems that these functions return incorrect values, the results are totally different with GeNie ,I have attached my code ,I will be truly thankful if you look at it and guide me to solve the final problem.
thank you so much.
Attachments
code.txt
(3.21 KiB) Downloaded 390 times
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: equation node

Post by shooltz[BayesFusion] »

You're creating new DSL_valEquationEvaluation object instead of retrieving the one managed by SMILE.

Instead of this:

Code: Select all

DSL_valEqEvaluation theValue_01(result_22_10,&theNet);
use this:

Code: Select all

DSL_valEqEvaluation *val = net.GetNode(result_22_10)->Value();
Post Reply