Soft Evidence Implementation

The engine

Soft Evidence Implementation

Postby khijuni » Tue Feb 22, 2011 6:02 pm

Hi, all!

First of all, I really appreciate all the efforts that SMILE & Genie related personnel made. It is really wonderful BNs framework.

I currently use SMILE for building my web application. But I got stuck with a problem. On genie, I found a soft evidence functionality and want to apply it to my web application. I am using C++ SMILE API. If you can share some tutorial code with me, it will be great. I tried to find related article. But I couldn't.

For my hard evidence, I used the following code (just a partial part)

theNet.UpdateBeliefs();

string name;
int evidence_number = 0 ;
name = evidence_input[i+1] + "_Facility_" + evidence_input[i] +"_Report" ; // evidence input arrays are inputs from external txt file and ignore i variable
set_evidence= theNet.FindNode((char *)(name.c_str()));
theNet.GetNode(set_evidence)->Value()->SetEvidence(evidence_number);

What I want to do in place of my old code is that I want to find a node then set it as soft evidence. If the node has updated probability from other nodes, I want to use the updated probability as soft evidence as I can do it in Genie.

Thanks in advance!!
khijuni
 
Posts: 4
Joined: Wed Dec 22, 2010 7:10 pm

Re: Soft Evidence Implementation

Postby shooltz » Wed Feb 23, 2011 12:32 pm

SMILE's functionality for soft evidence is exposed through methods declared in DSL_nodeValue class:
Code: Select all
int GetSoftEvidence(std::vector<double> &evidence) const;
int SetSoftEvidence(const std::vector<double> &evidence);
int IsSoftEvidence() const;

Two first methods are virtual and actual implementation is in DSL_beliefVector.

The parameter passed to/from Get/SetSoftEvidence is the vector of probabilitites with the size equal to the node's outcome count. If you have a ternary node, your code could look like this:

Code: Select all
DSL_node *pNode = net.GetNode(handle);
pNode->GetValue()->SetSoftEvidence();
net.UpdateBeliefs();

Finally, use DSL_nodeValue::ClearEvidence to remove the soft evidence from the node.
shooltz
Site Admin
 
Posts: 828
Joined: Mon Nov 26, 2007 5:51 pm

Re: Soft Evidence Implementation

Postby khijuni » Thu Feb 24, 2011 6:17 am

Thanks for your reply.

I have finished the coding and share with others, as I got great help from you ^^.

string facility_soft_evidence;
int credibility_update;
DSL_node *pNode;
DSL_nodeValue *pNodeValue;

facility_soft_evidence = "node_name" ;
credibility_update= theNet.FindNode((char *)(facility_soft_evidence.c_str()));
pNode = theNet.GetNode(credibility_update);
pNodeValue = pNode -> Value() ;

DSL_sysCoordinates theCoordinates_soft(*theNet.GetNode(credibility_update)->Value());
theCoordinates_soft[0] = 0;
theCoordinates_soft.GoToCurrentPosition();
vector<double> marks (2);
for (int y = 0 ; y <2 ; y++ ) {
marks[y] = theCoordinates_soft.UncheckedValue();;
theCoordinates_soft.Next();
}
pNodeValue -> SetSoftEvidence(marks);

theNet.UpdateBeliefs();

P.S. I am not sure this is efficient code. But SetSoftEvidence function seems to be tricky, as it requires vector as parameters. If anybody knows better way, please share with us. Thanks!
khijuni
 
Posts: 4
Joined: Wed Dec 22, 2010 7:10 pm


Return to SMILE

Who is online

Users browsing this forum: No registered users and 0 guests

cron