-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogicsample.c
More file actions
56 lines (48 loc) · 1.29 KB
/
logicsample.c
File metadata and controls
56 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/********************************************************************
$RCSfile: logicsample.c,v $
$Author: alexvk $
$Revision: 1.1 $
$Date: 1997/10/15 02:52:53 $
********************************************************************/
static char rcsid[] = "$Id: logicsample.c,v 1.1 1997/10/15 02:52:53 alexvk Exp alexvk $";
#include <stdio.h>
#include "network.h"
void NetworkLogicSample(net, probs)
NETWORK *net;
VECTOR *probs;
{
int i, j, jointidx, index, maxNumVals;
NODE *node, *parent;
VECTOR randomNum, lastprob;
for (i = 0; i < net->numNodes; i++) {
node = net->nodes + net->parentOrdering[i];
jointidx = 0;
for (j = 0; j < node->numParents; j++) {
parent = net->nodes + node->parentIndices[j];
jointidx += node->odometer[j] * parent->setVal;
}
for (lastprob = 0.0, j = 0; j < node->numValues; j++) {
index = jointidx + j;
probs[j] = node->probMatrix[index] + lastprob;
lastprob = probs[j];
}
RandomZeroOne(&randomNum);
for (j = 0; j < node->numValues; j++) {
if (randomNum <= probs[j])
break;
}
node->setVal = j;
}
}
void NetworkCaseOutput(fp, net)
FILE *fp;
NETWORK *net;
{
int i;
NODE *node;
for (i = 0; i < net->numNodes; i++) {
node = net->nodes + i;
fprintf(fp, "%d ", node->setVal+1);
}
fprintf(fp, "\n");
}