This page gives some basic information about the OpenEarthTools Python wrapper for the Netica C API.
Information about the Netica C API can be found at http://norsys.com/netica_c_api.htm; downloads at available at http://www.norsys.com/downloads/
The Python wrapper is available in the openearthtools trunk, more specifically at https://svn.oss.deltares.nl/repos/openearthtools/trunk/python/applications/Netica/
Installation
Currently, the wrapper is only tested on Windows
Step 1
Windows
The .zip
file with the Netica C API contains the file Netica.dll
This .dll
file should be copied to the lib directory of the Python Netica package (python/applications/Netica/lib/)
Mac OS X
The Netica C API for Mac OS X includes a static library only, where a dynamic library is needed for use with the python wrapper. You have to compile it yourself. First run in the src folder of the zip file:
./compile.sh
This results in a NeticaEx.o
file in the lib folder. Then go to the lib folder and run:
g++ -shared libnetica.a NeticaEx.o -o libnetica.so
Copy the resulting libnetica.so to the lib directory of the Python Netica package (python/applications/Netica/lib/)
Don't commit the libnetica.so
file
Step 2
On all platforms, run setup to install the python package:
python setup.py develop
This setup.py
file is located in python/applications/Netica/setup.py
Example of basic usage
Building a bayesian network
The code below shows how to build a Netica Bayesian network from scratch using Python.
The .cas
file to train the network can be downloaded here.
from netica import Netica import numpy as np # initialize class ntc = Netica() # create new environment env = ntc.newenv() # initialize environment ntc.initenv(env) # create new net net_p = ntc.newnet('BNexample', env) # define nodes node1 = ntc.newnode('Node1', 3, net_p) ntc.setnodestatenames(node1, "one, two, three") node2 = ntc.newnode('Node2', 0, net_p) ntc.setnodelevels(node2, 4, np.asarray([1, 2, 3, 4, 5], dtype='float64')) # define links ntc.addlink(parent=node1, child=node2) # obtain node list nl_p = ntc.getnetnodes(net_p) # train with cas file ntc.revisecptsbycasefile(filename='BNcases.cas', nl_p=nl_p, updating=0, degree=1) # compile the net ntc.compilenet(net_p) # enable auto updating ntc.setautoupdate(net_p) # save net ntc.savenet(env, net_p, 'BNexample.dne')