Netica API for Matlab

Matlab is able to call JAVA JNI libraries. This is simply to announce that Matlab users report success in calling Netica functions from Matlab. Here are the steps required:

  1. Refer to the NeticaJ users manual regarding installation of NeticaJ with IDEs and other JVMs. Be sure you understand the principles here, namely, that there are basically three steps involved:
    1. NeticaJ.jar must appear on the Matlab JVM's CLASSPATH.
    2. NeticaJ.dll must appear on the Matlab JVM's java.library.path.
    3. Netica.dll  must appear on the Windows "execution path".

  2. Add these lines to the top of Matlab's classpath.txt file (assuming C:\NeticaJ_325\ is where you installed Netica-J):
    .
    C:\NeticaJ_325\bin
    C:\NeticaJ_325\bin\NeticaJ.jar
    
  3. Update the 'librarypath.txt' file so that Matlab can find NeticaJ.lib. Do 'which librarypath.txt' to locate this file. Note: if you place NeticaJ.lib in your working directory, then all you need to do is add a '.' to the file.
    Note. The above seems to work only for recent versions of Matlab. For older versions of Matlab (e.g., 6.5.1.199709), the following instructions were submitted:
    "Copy the Netica.dll and NeticaJ.dll files (from the bin\ folder) to the working directory of a particular matlab session because Matlab fails to properly use the java.library.path. (see www.mathworks.com/support/solutions/data/32867.shtml for an explanation)."
     
  4. Import netica methods into your Matlab session. To do this, you must add this line to top of your m-file script:
    import norsys.netica.*;
    
  5. Proceed to use NeticaJ methods at will. For example:
    % check for existing netica environment
    env = Environ.getDefaultEnviron;
    % now set password
    env = Environ('yourpasswordhere');
    % kill env by calling:   env.finalize
    % get a net
    streamer = Streamer('yournethere.dne');
    net = Net(streamer);
    net.compile;
    % kill by calling:       net.finalize

Note. The above has been reported to work for the following platforms:

1. MATLAB Version: 6.5.1.199709 (R13) Service Pack 1
Operating System: Microsoft Windows 2000 Version 5.0 (Build 2195: Service Pack 4)
Java VM Version: Java 1.3.1_01 with Sun Microsystems Inc. Java HotSpot(TM) Client VM

2. MATLAB Version: 7.4.0.287 (R2007a) with its default Java: Java 1.5.0_07.

If you have any experience with using Netica under Matlab that may be of use to others, or have any sample code or scripts you wish to publish, please contact Norsys. Thank you.




Alternative configuration instructions

These instructions were submitted by one helpful user, for which we are very grateful. They work for MATLAB Version: 7.4.0.287 (R2007a) and possibly earlier versions that support 'librarypath.txt':
  1. Append the path to the bin directory (e.g. "C:\NeticaJ_Win\NeticaJ_325\bin\ " to the Windows execution path. In Windows XP go to start->My Computer->View system information->Advanced->Environment , for MATLAB Version: 7.4.0.287 (R2007a)Variables ; in the "System Variables" box look for "Path"; select it and click "Edit"; put the path (preceeded by a semicolon) to the bin directory at the end of the list. Save and close.
  2. Start up Matlab.
  3. In Matlab, enter >>edit(which('librarypath.txt')); This will start up the editor; insert the same path name at the end of whatever list is there.
  4. Exit Matlab.
  5. Reboot the computer (you need to do this for the change to the Windows Path to be incorporated)

After rebooting, Matlab should be able to run the Netica programs without having to move DLL or library files from the bin directory. Talking to Netica via Matlab is very similar to the way it's done in Java, except one doesn't need the declarations; for example for the Chest Clinic example, a simple sample run looks like this:
>> import norsys.netica.*
>>env = Environ.getDefaultEnviron;
>> env = Environ('');
>> streamer = Streamer('01 - ChestClinic.dne');
>> net = Net(streamer);
>> net.compile;0756831247
>> visitAsia = net.getNode('VisitAsia');
>> tb = net.getNode('Tuberculosis');
>> xray = net.getNode('XRay');
>> b=tb.getBelief('present')
b =
    0.0104
>> xray.finding().enterState('abnormal');
>> b=tb.getBelief('present')
b =
    0.0924
>> net.finalize();
>> 



Alternative configuration instructions #2 (submitted June 25, 2014)

These instructions were submitted by another thoughtful user who found they were required for working with MATLAB Version: R2012b :
(Please note that this is the first solution ever submitted for R2012b, and if your experiences differ, or you think these instructions can be improved, please send us your findings or comments, and we will post them here. Thanks.)

For Matlab version : R2012(8.0.0.783), 64-bit(win64)
  1. Append the following paths (or similar paths; I was using 64-bit so it is important to add the x64_bin) to the bin directory C:\ProgramFiles\Java\jdk1.7.0_07\bin; D:\Software\NeticaJ_504\bin\x64_bin;
    To do this in Windows (windows 7 enterprise) go:
    Start->Control Panel-> All Control Panel Items->System. Then click the tab ‘Advanced system Settings’ and then the ‘Environment Variables’ button. Under the System variables find the variable ‘Path’, choose it and click ‘edit’.
    Add these paths (or similar)
    C:\ProgramFiles\Java\jdk1.7.0_07\bin;
    D:\Software\NeticaJ_504\bin\x64_bin;

    Note that I did not add a ‘\’ in the end. Perhaps it works with ‘\’ as well.
    And click ok. Then restart computer.
  2. Start up Matlab.
  3. In Matlab, enter
    >>edit(which('librarypath.txt'));
    This will start up the editor; insert the same NeticaJ path name at the end of whatever list is there, i.e.,
    D:\Software\NeticaJ_504\bin\x64_bin\
    Note that I add a ‘\’ in the end.
  4. In Matlab, enter >>edit classpath.txt; Add these lines to the top of Matlab's classpath.txt file :
    D:\Software\NeticaJ_504\bin\x64_bin\NeticaJ.jar
    D:\Software\NeticaJ_504\bin\x64_bin
  5. Exit Matlab.
  6. Reboot the computer (you need to do this for the change to the Windows Path to be incorporated)