Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using matlab code in Octave - Bayes Net Toolbox

Tags:

matlab

octave

I am trying to run Kevin Murphy's Bayes Net Toolbox in Octave and encountering some problems. It doesn't help that I'm a novice at Bayesian networks, Matlab and Octave.

This toolbox was originally written for Matlab. There is a large test file called test_BNT.m which runs through all the functionality in the toolbox. Most of the error messages relate to the difference between & and && in Matlab and Octave. This is easy to fix. However, I've now come across a new problem and I don't know what to do about it.

For instance, the qmr1.m script creates an instance of the pearl_inf_engine class, sets some of the member member variables and passes the instance of the class to another function. Later on, the member variables are accessed again in a different script (parallel_protocol.m). But when this happens, the following message appears:

error: invalid index for class
error: evaluating argument list element number 1

It seems that from one script to another, it has forgotten that the class has any member variables and gives the invalid index message when you try to access them.

Is this a common error with an easy solution? Is something wrong with the path or working directory? Maybe someone else has already converted the BNT to octave and knows what to do?

Edit

I was able to get past this error message. The trick was to read the installation instructions (haha) and run addpath(genpathKPM(<BNT base directory)). genpathKPM.m is a script includes in BNT which adds all the required directories to the path.

After doing this, run test_BNT.m and change & to && and | to || at each line where it gives a warning. This will clear up most of the errors.

However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and some others. The new error message I'm stuck on is:

error: invalid empty index list
error: called from:
error:   C:\FullBNT-1.0.7\bnt\BNT\inference\static\@var_elim_inf_engine\find_mpe
.m at line 63, column 5

on this line of code:

eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);

If I can get all the scripts to work, I'll post an answer here with the steps I took to do it.

Edit 2

I was able to get past the problem in the previous edit. Replace

eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);

with

eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);

The next problem is identical. Just replace num2str in the same way.

This file was apparently contributed by a user of BNT, and not written by the original author. Using eval kind of a hack, I think. A better fix would be to just rewrite the code so it doesn't use eval at all.

There is one more error in draw_graph.m, which was apparently also an outside contribution to the project. I just commented out the call to that function since I'm not interested in drawing graphs right now. After doing this, and continuing to fix shortcircuit operators, all of the tests in test_BNT.m will run.

Still, I won't create an answer for this until I can get draw_graph.m to run, too.

like image 605
peace_within_reach Avatar asked Nov 02 '22 11:11

peace_within_reach


1 Answers

As a significant amount of time has passed, and the answer to the core problem was provided in the question, I will post it here so it will not stay listed as unanswered:

tl;dr: Change a few operators, solve the remaining bugs specified below, and everything works except the drawing of graphs.

Edit

I was able to get past this error message. The trick was to read the installation instructions (haha) and run addpath(genpathKPM(<BNT base directory)). genpathKPM.m is a script includes in BNT which adds all the required directories to the path.

After doing this, run test_BNT.m and change & to && and | to || at each line where it gives a warning. This will clear up most of the errors.

However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and some others. The new error message I'm stuck on is:

error: invalid empty index list
error: called from:
error:   C:\FullBNT-1.0.7\bnt\BNT\inference\static\@var_elim_inf_engine\find_mpe
.m at line 63, column 5

on this line of code:

eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);

If I can get all the scripts to work, I'll post an answer here with the steps I took to do it.

Edit 2

I was able to get past the problem in the previous edit. Replace

eval(['sCPT.T(', sargs, num2str(jj), ')=0;']); with

eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);

The next problem is identical. Just replace num2str in the same way.

This file was apparently contributed by a user of BNT, and not written by the original author. Using eval kind of a hack, I think. A better fix would be to just rewrite the code so it doesn't use eval at all.

There is one more error in draw_graph.m, which was apparently also an outside contribution to the project. I just commented out the call to that function since I'm not interested in drawing graphs right now. After doing this, and continuing to fix shortcircuit operators, all of the tests in test_BNT.m will run.

like image 171
Dennis Jaheruddin Avatar answered Nov 15 '22 09:11

Dennis Jaheruddin