How do I define a NoisyMAX gate/node?

The engine.
Quirijn
Posts: 7
Joined: Sun May 02, 2010 6:43 pm

How do I define a NoisyMAX gate/node?

Post by Quirijn »

I've been using the SMILE library for a while in a program and I must say that everything works great. The API provided works really well. The next thing I want to do is add functionality for Noisy gates in my program (to use noisyMAX to model common cause failures in aircraft systems). I was wondering how I can define a node as NoisyMax.

Normally to add a new node you would do something like:

Code: Select all

theNet.AddNode(DSL_CPT,"Success");
I couldn't really figure out from the documentation how to define the node as NoisyMAX. Do you also have an example on how to define the CPT for one of those gates? I saw in the documentation that it had to be done using a DSL_Dmatrix object. Thanks for the help in advance!
shooltz[BayesFusion]
Site Admin
Posts: 1461
Joined: Mon Nov 26, 2007 5:51 pm

Re: How do I define a NoisyMAX gate/node?

Post by shooltz[BayesFusion] »

Replace DSL_CPT with DSL_NOISY_MAX to create a noisy node. To set its noisy parameters (not the fully expanded CPT) use DSL_noisyMAX::SetDefinition.
Quirijn
Posts: 7
Joined: Sun May 02, 2010 6:43 pm

Post by Quirijn »

Thanks for the help. I still don't get a few things. I define the nodes as you said:

Code: Select all

theNet.AddNode(NOISY_MAX,"Success");
 
// setting number (and name) of outcomes
    DSL_idArray someNames;
    someNames.Add("Success");
    someNames.Add("Failure");
    theNet.GetNode(success)->Definition()->SetNumberOfOutcomes(someNames);  

Let's say "Success has a parent with two states. Normally you would set the probabilities in this way (like in the tutorial):

Code: Select all

 DSL_sysCoordinates theCoordinates (*theNet.GetNode(forecast)->Definition());
    theCoordinates.UncheckedValue() = 0.4;
    theCoordinates.Next();
    theCoordinates.UncheckedValue() = 0.6;
    theCoordinates.Next();
    theCoordinates.UncheckedValue() = 0.1;
    theCoordinates.Next();
    theCoordinates.UncheckedValue() = 0.9; 
This would not be the correct way to define it for a NoisyMAX I assume. What would I need to do to define the CPT as below? I

Code: Select all


|    Parent   | Leak   |
+-------------+--------+
| 0.4  |  0   |   0.5  |
| 0.6  |  1   |   0.5  |
+-------------+--------+
do not really understand how to set the leak with DSL_noisyMAX::SetDefinition. Do I need to create an instance of DSL_noisyMAX? Thanks for the help! I am not using your API directly using C but I used SWIG to create a wrapper for Common Lisp. Accessing all the functions from the SMILE library is therefore a little different.

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

Post by shooltz[BayesFusion] »

What would I need to do to define the CPT as below?
Based on the ASCII art above, I assume you want to set the noisy weights, not the expanded CPT. If this is the case, drop the DSL_sysCoordinates and fill the plain DSL_doubleArray with the numbers using the order they appear in the columns (0.4, 0.6, 0, 1, 0.5, 0.5). The pass the DSL_doubleArray to DSL_noisyMAX::SetDefinition(DSL_doubleArray &).
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

Hi,

I have similar question.
I follow shooltz's instruction to set the noisy weights but I'm not getting what I want.
My goal is to get table like this:

Code: Select all

|  A    |   B    | Leak  |
+-------------+--------+
| 0.5  |  0.5   |    0 |
| 0.5  |  0.5   |   1  |
+-------------+--------+
to do that I create node fPV as a noisyMAX:

Code: Select all

int fPV = UserProfile.AddNode(DSL_NOISY_MAX,"fPV");
Then using DSL_doubleArray I assigned {0.5,0.5,0.5,0.5,0,1} values
next,

Code: Select all

DSL_noisyMAX noisyMax(*UserProfile.GetNode(fPV)->Definition());
noisyMax.SetDefinition(DSL_doubleArray);
Could you help me what I'm doing wrong :(
Many thanks
f_allen
Posts: 4
Joined: Fri May 04, 2012 10:32 pm

Re: How do I define a NoisyMAX gate/node?

Post by f_allen »

shooltz wrote:Then using DSL_doubleArray I assigned {0.5,0.5,0.5,0.5,0,1} values
I'm no expert, but I had the same problem today and it seemed like the solution was to set {0.5,0.5,0,1,0.5,0.5,0,1,0,1} i.e. include the constrained columns.
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

graph2.tar
my dsl file
(10 KiB) Downloaded 1007 times
thanks f_allen, but still I have the same problem.
I can print my CPT and is OK, but changing the values in constrained columns doesn't work. :?

My code:

Code: Select all

 #include <iostream>
 #include <cstdio>
#include <conio.h>   
 #include "smilearn.h"
 #include "smile.h"


using namespace std;


int main() {

 DSL_network UserProfile;
 UserProfile.ReadFile("graph2.dsl");

 int fPV = UserProfile.FindNode("fPV");  //fPV is a noisyMAX node in the original network
 
 
 DSL_Dmatrix* probMatrix = UserProfile.GetNode(fPV)->Definition()->GetMatrix(); 
 
 int count = probMatrix->GetSize(); 
 for (int i = 0; i < count; i ++) 
	 cout << i << " "<< (*probMatrix)[i]  << endl;

 /*changing the values in constrained columns to get 

 |parentA| parentB|leak |
 |-------|--------|-----|
 |0.5    |  0.5   | 0   |
 |-------|--------|-----|
 | 0.5   |   0.5  | 1   | 
 
 
 */
    DSL_doubleArray theProbs; 

 	theProbs.Flush();
	theProbs.SetSize(10);
	theProbs.Add( 0.5 );
	theProbs.Add( 0.5 );
	theProbs.Add( 0 );
	theProbs.Add( 1 );
	theProbs.Add( 0.5 );
	theProbs.Add( 0.5 );
	theProbs.Add( 0 );
	theProbs.Add( 1 );
	theProbs.Add( 0 ); 
	theProbs.Add( 1 );

	DSL_node *fPV_pointer = UserProfile.GetNode(fPV);
	fPV_pointer->Definition()->SetDefinition( theProbs );
	

	probMatrix = fPV_pointer->Definition()->GetMatrix(); 
 
	cout << "after modifying:\n" << endl;

	count = probMatrix->GetSize(); 
	for (int i = 0; i < count; i ++) {
	 cout << i << " "<< (*probMatrix)[i]  << endl;
	}
}

Do you have any thoughts what can be wrong ??

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

Re: How do I define a NoisyMAX gate/node?

Post by shooltz[BayesFusion] »

fPV_pointer->Definition()->SetDefinition( theProbs );
What's the return code from SetDefinition?
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

Hi shooltz,
Thanks for your response.
I'm not quite sure about what are you asking. :?
Do you mean output ?

This is my output:

Code: Select all

0 0.75
1 0.25
2 0.5
3 0.5
4 0.5
5 0.5
6 0
7 1
after modifying:

0 0.75
1 0.25
2 0.5
3 0.5
4 0.5
5 0.5
6 0
7 1
Thanks for help
shooltz[BayesFusion]
Site Admin
Posts: 1461
Joined: Mon Nov 26, 2007 5:51 pm

Re: How do I define a NoisyMAX gate/node?

Post by shooltz[BayesFusion] »

Mastif wrote:I'm not quite sure about what are you asking
SetDefinition returns an int. What's the value?
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

SetDefinition returns an int. What's the value?
:) the value is 0
shooltz[BayesFusion]
Site Admin
Posts: 1461
Joined: Mon Nov 26, 2007 5:51 pm

Re: How do I define a NoisyMAX gate/node?

Post by shooltz[BayesFusion] »

What happens when you replace 0.5/0.5 with 0.2/0.8 in the intial two calls to theProbs.Add?
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

hi,

It looks like it is changing

Code: Select all

0 0.875
1 0.125
2 0.75
3 0.25
4 0.75
5 0.25
6 0.5
7 0.5
SetDefinition after change 0
after modifying:

0 0.6
1 0.4
2 0.2
3 0.8
4 0.5
5 0.5
6 0
7 1
my theProbs

Code: Select all

theProbs.Flush();
	theProbs.SetSize(10);
	theProbs.Add( 0.2 );
	theProbs.Add( 0.8);
	theProbs.Add( 0 );
	theProbs.Add( 1 );
	theProbs.Add( 0.5 );
	theProbs.Add( 0.5 );
	theProbs.Add( 0 );
	theProbs.Add( 1 );
	theProbs.Add( 0 ); 
	theProbs.Add( 1 );
however I do not understand this changes. I would like to have the equal weights (for all my parents 0.5 and only Leak 0/1)
Thanks
shooltz[BayesFusion]
Site Admin
Posts: 1461
Joined: Mon Nov 26, 2007 5:51 pm

Re: How do I define a NoisyMAX gate/node?

Post by shooltz[BayesFusion] »

SetDefinition sets the noisy weights. GetMatrix returns the CPT. You can check if the numbers you're seeing in your program are in line with values displayed in GeNIe (go to node properties/definition page, then switch between noisy and CPT using the toolbar buttons).
Mastif
Posts: 16
Joined: Thu Apr 26, 2012 10:31 pm

Re: How do I define a NoisyMAX gate/node?

Post by Mastif »

Thanks a lot for explanation!

I was checking my answer with GeNIe before, for theProbs[index] and I couldn't see any changes (but maybe I had somewhere else problems). I never check for theProbs.Add() :lol: and it looks OK.

Many thanks!!!!! :D
Post Reply