Context
The Export function can take a predictive Bayesian network model and translate it into program code that can be used in other environments, such as SAS, PHP, JavaScript, Visual Basic, R, and Python.
The Export function is available by separate subscription. See BayesiaLab Code Export Modules in Pricing.
The Export function is very practical if you already have an existing research workflow in another software platform and want to augment its capability with a predictive model developed and tested in BayesiaLab.
- To export the code that corresponds to your network, select
Main Menu > Network > Export. - Upon setting language-specific options see example below, you obtain the source code, which you can then paste into the host program.
With the generated code, your application can compute the posterior probability distribution of a Target Node given evidence set on the nodes in its Markov Blanket.
When using the exported code in your application, please note that you can only set Hard Evidence on nodes. However, leaf nodes can remain unobserved.
- Translating a Bayesian network’s general probabilistic inference capability into code would be far too complex, hence the limitation on predictive inference in the Code Export Module.
- To utilize general probabilistic inference in your own program, consider using the Bayesia Engine API.
Example
As an example, we will use the following network, generated by the Augmented Markov Blanket learning algorithm to predict house prices in King County, Washington, USA:
For the nodes shown as blue discs, Hard Evidence will be mandatory when using the exported code for predictive inference.
The nodes shown as cyan-colored badges are leaf nodes. For them, Hard Evidence is not necessary, i.e., they can remain unobserved.
Available Languages
The Code Export Module can be licensed for one particular language or all of the following languages:
SAS
The full SAS export example is available as a downloadable .sas file above.
A short excerpt is shown below:
%MACRO INFERENCE(TABLIN,TABLOUT);
%LET TEST=VALID;
%IF &TABLIN= %THEN %DO;
%PUT ERROR=============> MISSING TABLE NAME (TABLIN);
%LET TEST=INVALID;
%END;
%IF &TABLOUT= %THEN %DO;
%PUT ERROR=============> MISSING TABLE NAME (TABLOUT);
%LET TEST=INVALID;
%END;
%IF &TEST=INVALID %THEN %GOTO EXIT;
DATA &TABLOUT;
SET &TABLIN;
PROB___356=1.0;
PROB___537_25=1.0;
PROB___763_776=1.0;
PROB___1140=1.0;
PROB__1140=1.0;
/* ... many generated branches ... */
SUMPROB=PROB___356+PROB___537_25+PROB___763_776+PROB___1140+PROB__1140;
IF SUMPROB GT 0 THEN DO;
PROB___356=PROB___356/SUMPROB;
PROB___537_25=PROB___537_25/SUMPROB;
PROB___763_776=PROB___763_776/SUMPROB;
PROB___1140=PROB___1140/SUMPROB;
PROB__1140=PROB__1140/SUMPROB;
END;
DROP SUMPROB;
RUN;
%EXIT:* END OF MACRO;
%MEND INFERENCE;PHP
JavaScript
R
Visual Basic
Python
