Parent State Names

The engine.
Post Reply
jdtoellner
Posts: 71
Joined: Mon Aug 01, 2016 9:45 pm

Parent State Names

Post by jdtoellner »

In the other forum you provided the following code snippet that set probabilities (weights) for a Noisy Max node.

Code: Select all

// NoisyMaxDemo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "smile.h"

int main()
{
	DSL_network net;
	int ret = net.ReadFile("noisymax.xdsl");
	if (DSL_OKAY != ret)
	{
		printf("Can't load input file %sn", "noisyadder.xdsl");
		return ret;
	}

	int h = net.FindNode("A");
	if (h < 0)
	{
		printf("Node %s not founnd", "A");
		return h;
	}

	DSL_nodeDefinition *def = net.GetNode(h)->Definition();
	if (def->GetType() != DSL_NOISY_MAX)
	{
		printf("Node %s is not a noisy addern", "A");
		return DSL_WRONG_NODE_TYPE;
	}
	DSL_noisyMAX *adder = static_cast <DSL_noisyMAX *> (def);

	printf("Displaying noisyAdder weights for %s\n", "A");
	DSL_Dmatrix &weights = adder->GetCiWeights();
	for (int i = 0; i < weights.GetSize(); i++)
	{
		printf("%d: %f\n", i, weights[i]);
	}

	int parentCount = adder->GetNumberOfParents();
	int outcomeCount = adder->GetNumberOfOutcomes();
	for (int i = 0; i < parentCount; i++)
	{
		int base = i * outcomeCount * 2;
		double p = (i + 1) * 0.1;
		weights[base] = p;
		for (int j = 1; j < outcomeCount; j++)
		{
			weights[base + j] = (1 - p) / (outcomeCount - 1);
		}
	}

	return net.WriteFile("noisymax-modified.xdsl");
}
This code snippet provides me with the Noisy Max state names:

Code: Select all

			DSL_nodeDefinition *def = theNet.GetNode(nodeHandle)->Definition();
				const DSL_Dmatrix &cpt = *def->GetMatrix();
			const DSL_idArray &outcomes = *def->GetOutcomesNames();
			const int numberOfOutcomes = def->GetNumberOfOutcomes();
I'd like to set weights based on Parent State names and the Noisy Max node state names.
Capture.JPG
Capture.JPG (32.51 KiB) Viewed 3905 times
What's the best way to determine Parent states?

Also, what's the best way to determine Parent names?

Are those in the Noisy Max node or do I need to traverse the parents?
jdtoellner
Posts: 71
Joined: Mon Aug 01, 2016 9:45 pm

Re: Parent State Names

Post by jdtoellner »

I think I've figured this out.

Get the parents with this code.

Code: Select all

			DSL_intArray parentHandles = theNet.GetParents(nodeHandle);
			int numberOfParents = theNet.NumParents(nodeHandle);
Then get the states with this code.

Code: Select all

			for (int parentIdx = 0; parentIdx < numberOfParents; parentIdx++) {

				DSL_node *parentNode = theNet.GetNode(parentHandles[parentIdx]);
				DSL_nodeDefinition *parentDef = parentNode->Definition();
				DSL_Dmatrix &parentCPT = *parentDef->GetMatrix();
				const DSL_idArray &parentOutcomes = *parentDef->GetOutcomesNames();
				const int parentNumberOfOutcomes = parentDef->GetNumberOfOutcomes();

				string parentNodeID = parentNode->GetId();
			}
Post Reply