void SetNodeProbs_bn ( node_bn*  node,   const state_bn*  parent_states,   const prob_bn*  probs )

The purpose of this function is to build the conditional probability table (CPT) of node, which provides a probability distribution over the states of node for each possible configuration of parent states (i.e., parent condition). Each call sets the conditional probabilities of node for the situation where its parents have the states indicated by the vector parent_states. The length of parent_states must be the number of parents of node, and each of its entries provides a state for the corresponding parent. The length of the probs array must be the number of states of node, each entry is a prob_bn (i.e. 'float'), and consist of the conditional probabilities:

P (node = state0 | parents take on parent_states)

P (node = state1 | parents take on parent_states)

...

P (node = stateN | parents take on parent_states)

The order of the states in parent_states should match the order of the nodes in the list returned by GetNodeParents_bn (this will be the same order that parents were added using AddLink_bn). MapStateList_bn may be useful for that. parent_states can be NULL if node has no parents.

If any entry of parent_states is EVERY_STATE then it applies to all possible values of the corresponding parent. More than one entry of parent_states may be EVERY_STATE, in which case all the probabilities of their cartesian product will be set to probs, as you would expect (e.g., see the MakeProbsUniform example below).

Netica will make a copy of the probs array; it won't modify or free the passed array.

If node has many parents (i.e., the product of their number of states is large) then the probability table will be large, and your system may run out of memory. You can use GetError_ns after one or more calls to SetNodeProbs_bn to see if there was a problem.

After changing a node's probabilities, its net must be (re)compiled before calling GetNodeBeliefs_bn on any node in the net (although a full recompile isn't necessary, so it will proceed very quickly).

To set all the conditional probabilities of node at once, pass NULL for parent_states.

To cycle through all the possibilities of parent_states, see the NeticaEx function NextStates.

Version:

This function is available in all versions.
In versions 1.33 and earlier, "EVERY_STATE" was called "WILDCARD_STATE".

 GetNodeProbs_bn Retrieve values SetNodeFuncState_bn Build the table for a deterministic node SetNodeExperience_bn Associate a degree of experience with the probabilities ReviseCPTsByFindings_bn Revise the probabilities using the case currently entered ReviseCPTsByCaseFile_bn Revise the probabilities using a file of cases FadeCPTable_bn Adjust the probabilities for a changing world MapStateList_bn To create the state list passed in

Example:

```The following function is available in NeticaEx.c:
// Gives the passed node a uniform conditional probability distribution
// (i.e., all the probabilities the same).
//
void MakeProbsUniform (node_bn* node){
int st, numstates = GetNodeNumberStates_bn (node);
int pn, numparents = LengthNodeList_bn (GetNodeParents_bn (node));
prob_bn* uniform = malloc (numstates * sizeof (prob_bn));
state_bn* pstates = malloc (numparents * sizeof (state_bn));
for (st = 0;  st < numstates;  ++st)  uniform[st] = 1.0 / numstates;
for (pn = 0;  pn < numparents;  ++pn)  pstates[pn] = EVERY_STATE;
SetNodeProbs_bn (node, pstates, uniform);
free (uniform);  free (pstates);
}```
Example 2:
```The following function is available in NeticaEx.c:
/*________________________________________________________________ SetNodeProbs
This function is meant to be a more convenient (but slower) version of
SetNodeProbs_bn.  Its first argument is the node whose probabilities we are
setting.  This is followed by the names of the conditioning states of its
parents as C strings.  Finally comes a list of doubles, being the probabilities
for each of the states of the node.
For example:   SetNodeProbs (Temperature, "Windy", "Low", 0.6, 0.3, 0.1);
means that the probability that Temperature is in its first state given that
its first parent is in state "Windy" and its second parent is in state "Low"
is 0.6, the probability its in its second state is 0.3, and that its in its
third state is 0.1.
Passing "*" for a state names means it applies to all values of the state.
Since the function prototype uses "...", you must be very careful to pass doubles
for the probabilities (e.g., passing 0 instead of 0.0 will get you in trouble).
If time efficiency is critical, and you must set large probability tables,
use SetNodeProbs_bn directly instead of this function.
___________*/

#include <stdarg.h>
#define ARR_SIZE 20

void SetNodeProbs (node_bn* node, ...){
state_bn parent_states[ARR_SIZE];
prob_bn probs[ARR_SIZE];
char* statename;
state_bn state, numstates = GetNodeNumberStates_bn (node);
const nodelist_bn* parents = GetNodeParents_bn (node);
int pn, numparents = LengthNodeList_bn (parents);
va_list ap;
if (numstates > ARR_SIZE || numparents > ARR_SIZE){
NewError_ns (env, 0, XXX_ERR, "SetNodeProbs: Array size too small");
return;
}
va_start (ap, node);
for (pn = 0;  pn < numparents;  ++pn){
statename = va_arg (ap, char*);
if (statename == '*')  parent_states[pn] = EVERY_STATE;
else parent_states[pn] = GetStateNamed_bn (statename, NthNode_bn (parents, pn));
}
for (state = 0;  state < numstates;  ++state)
probs[state] = (prob_bn) va_arg (ap, double);
va_end (ap);
SetNodeProbs_bn (node, parent_states, probs);
}

#undef ARR_SIZE```
Example 3:
```The following function is available in NeticaEx.c:
// Sets all the conditional probabilities of node based on the array probs.
// You could use this function in combination with GetNodeAllProbs (see GetNodeProbs_bn
// to temporarily save probability tables.
//

void SetNodeAllProbs (node_bn* node, const prob_bn* probs){
int num_states  = GetNodeNumberStates_bn (node);
int num_parents = LengthNodeList_bn (GetNodeParents_bn (node));
state_bn* parent_states = calloc (num_parents, sizeof (state_bn));
while (1){
SetNodeProbs_bn (node, parent_states, probs);
if (NextStates (parent_states, GetNodeParents_bn (node)))  break;
probs += num_states;
if (GetError_ns (env, ERROR_ERR, NULL))  break;
}
free (parent_states);
}```