Normally to add a new node you would do something like:
Code: Select all
theNet.AddNode(DSL_CPT,"Success");
Code: Select all
theNet.AddNode(DSL_CPT,"Success");
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);
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;
Code: Select all
| Parent | Leak |
+-------------+--------+
| 0.4 | 0 | 0.5 |
| 0.6 | 1 | 0.5 |
+-------------+--------+
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 &).What would I need to do to define the CPT as below?
Code: Select all
| A | B | Leak |
+-------------+--------+
| 0.5 | 0.5 | 0 |
| 0.5 | 0.5 | 1 |
+-------------+--------+
Code: Select all
int fPV = UserProfile.AddNode(DSL_NOISY_MAX,"fPV");
Code: Select all
DSL_noisyMAX noisyMax(*UserProfile.GetNode(fPV)->Definition());
noisyMax.SetDefinition(DSL_doubleArray);
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.shooltz wrote:Then using DSL_doubleArray I assigned {0.5,0.5,0.5,0.5,0,1} values
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;
}
}
What's the return code from SetDefinition?fPV_pointer->Definition()->SetDefinition( theProbs );
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
SetDefinition returns an int. What's the value?Mastif wrote:I'm not quite sure about what are you asking
SetDefinition returns an int. What's the value?
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
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 );