/*
* DoInference.c
*
* Example use of Netica-C-API for doing probabilistic inference.
*/
#include "Netica.h"
#include "NeticaEx.c"
#define CHKERR {if (GetError_ns (env, ERROR_ERR, NULL)) goto error;}
environ_ns* env;
int main (void){
net_bn* net;
double belief;
char mesg[MESG_LEN_ns];
int res;
env = NewNeticaEnviron_ns (NULL, NULL, NULL);
res = InitNetica2_bn (env, mesg);
printf ("%s\n", mesg);
if (res < 0) exit (-1);
net = ReadNet_bn ( NewStreamFile_ns ("AsiaEx.dne", env, NULL),
NO_VISUAL_INFO);
CHKERR
CompileNet_bn (net);
belief = GetNodeBelief ("Tuberculosis", "Present", net);
CHKERR
printf ("The probability of tuberculosis is %g\n\n", belief);
EnterFinding ("XRay", "Abnormal", net);
belief = GetNodeBelief ("Tuberculosis", "Present", net);
CHKERR
printf ("Given an abnormal X-ray, \n\
the probability of tuberculosis is %g\n\n", belief);
EnterFinding ("VisitAsia", "Visit", net);
belief = GetNodeBelief ("Tuberculosis", "Present", net);
CHKERR
printf ("Given an abnormal X-ray and a visit to Asia, \n\
the probability of tuberculosis is %g\n\n", belief);
end:
FreeNet_bn (net);
res = CloseNetica_bn (env, mesg);
printf ("%s\n", mesg);
return (res < 0 ? -1 : 0);
error:
fprintf (stderr, "DoInference: Error in %s\n",
ErrorMessage_ns (GetError_ns (env, ERROR_ERR, NULL)));
goto end;
}
|
Netica (AB) 2.15 Win, (C) 1990-2002 Norsys Software Corp.
The probability of tuberculosis is 0.0104
Given an abnormal X-ray,
the probability of tuberculosis is 0.0924109
Given an abnormal X-ray and a visit to Asia,
the probability of tuberculosis is 0.3377156
|