-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample.c
More file actions
55 lines (49 loc) · 1.42 KB
/
sample.c
File metadata and controls
55 lines (49 loc) · 1.42 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
/********************************************************************
$RCSfile: sample.c,v $
$Author: alexvk $
$Revision: 1.1 $
$Date: 1997/10/15 02:52:53 $
********************************************************************/
static char rcsid[] = "$Id: sample.c,v 1.1 1997/10/15 02:52:53 alexvk Exp alexvk $";
#include <stdio.h>
#include <string.h>
#include "network.h"
void main(argc, argv)
int argc;
char **argv;
{
if (argc < 3)
printf("usage: %s networkFile numSamples\n",argv[0]);
else {
NETWORK *net;
VECTOR *probs = NULL;
int i, numCases, maxNumVals;
Randomize();
NetworkNew(&net);
net->netName = strdup(argv[1]);
NetworkFileReadErgo(net, argv[1]);
NetworkAnalyze(net);
/* Output K3 database format */
fprintf(stdout,"%d\n", net->numNodes);
for (i = 0; i < net->numNodes; i++)
fprintf(stdout,"%d ", net->parentOrdering[i]+1);
fprintf(stdout, "\n");
for (i = 0; i < net->numNodes; i++)
fprintf(stdout,"%d ", (net->nodes + i)->numValues);
fprintf(stdout,"\n");
numCases = atoi(argv[2]);
fprintf(stdout,"%d\n", numCases);
maxNumVals = 0;
for (i = 0; i < net->numNodes; i++) {
NODE *node = net->nodes + net->parentOrdering[i];
if (node->numValues > maxNumVals)
maxNumVals = node->numValues;
}
probs = (VECTOR *) calloc(maxNumVals, sizeof(VECTOR));
for (i = 0; i < numCases; i++) {
NetworkLogicSample(net, probs);
NetworkCaseOutput(stdout,net);
}
free((char *) probs);
}
}