jsChenxinpeng / randomforest-matlab

Automatically exported from code.google.com/p/randomforest-matlab
0 stars 0 forks source link

Undefined function or method 'mexClassRF_train' for input arguments of type 'int32' #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When I run the tutorial 'tutorial_ClassRF.m', I get the error:

??? Undefined function or method 'mexClassRF_train' for input arguments of
type 'int32'.

Error in ==> classRF_train at 347
[nrnodes,ntree,xbestsplit,classwt,cutoff,treemap,nodestatus,nodeclass,bestvar,nd
bigtree,mtry
...

I am running the student version of Matlab 7.4.0.287 (R2007a) on a MacBook
Pro with and Intel Core 2 Duo (64 bits).  I downloaded
RF_MexStandalone-v0.02.zip and also MacOS_precompiled-WITHOUT_SOURCE-v0.02.
 As directed I copied the files from the '2009b 64-bit' folder from
MacOS_precompiled-WITHOUT_SOURCE-v0.02 into the 'RF_Class_C' and the
'RF_Reg_C' folders produced from RF_MexStandalone-v0.02.zip.  I added all
the folders to my path.  Then when I run the tutorial file I get the error
above.

Based on the other email I saw concerning this same issue I guess this is
some sort of compiler issue.  Do I need to recompile everything?  i.e.
don't use the the precompiled files?  

Thank you for your help!
Corinne

Original issue reported on code.google.com by ctee...@gmail.com on 17 May 2010 at 12:12

GoogleCodeExporter commented 8 years ago
Hi i think recompiling (with those scripts) should solve the problem. 

I think the upload was for an older version. I'll try to get a new upload in 
sometimes 
(a week or so)

Original comment by abhirana on 17 May 2010 at 4:10

GoogleCodeExporter commented 8 years ago
Hello,  

I just went on a very long compiling adventure which I thought I would report 
on as
it may be helpful to others.  Basically, I compiled everything myself and ended 
up
with another error when running the tutorial file:
    Setting to defaults 500 trees and mtry=4
Too less/many parameters: You supplied 15??? One or more output arguments not
assigned during call to "mexClassRF_train".

Error in ==> classRF_train at 347

[nrnodes,ntree,xbestsplit,classwt,cutoff,treemap,nodestatus,nodeclass,bestvar,nd
bigtree,mtry
..

I notice this error is current open issue #2 on the wikki.  After a bit I 
realized I
did not block the path of the MacOS_precompiled-WITHOUT_SOURCE-v0.02 folder 
which has
many versions of the .mexmaci files in it.  After I took that foulder out of the
path, the tutorial ran.  So to others that have that problem.  Make sure you 
only
have ONE copy of mexClassRF_predict.mexmaci and mexClassRF_train.mexmaci (or
presumably the 64 bit version) in the randomforest-matlab/RF_Class_C/src/ 
directory
and ONE version of in the mexRF_predict.mexmaci and mexRF_train.mexmaci files 
in the
randomforest-matlab/RF_Reg_C/src directory.  And make sure no other directories 
that
have other versions are in the path.  

Other notes: when compiling with Fortran I downloaded as recommended in the
'compiler_settings.text' I did not alter the 'mexopts.sh' file as advised in
'compiler_settings.txt' (because I did not understand how to alter it).   I am
running R2007a instead of R2009b as in the 'compiler_settings.txt'.    I am not 
sure
if the changes are not obvious because I am using a different version which 
makes the
changes unclear.  I ended up with .mexmaci files as opposed to .mexmaci64 
files.  
However they appear to be working.

All the steps, trials and tribulations I went though are documented below just 
in
case it is helpful to anyone. 

Cheers

ALL THE DETAILS:
Compiling the files myself:
Typing in mex -setup I have 3 options:

    Options files control which compiler to use, the compiler and link command
    options, and the runtime libraries to link against.

    Using the 'mex -setup' command selects an options file that is
    placed in ~/.matlab/R2007a and used by default for 'mex'. An options 
    file in the current working directory or specified on the command line 
    overrides the default options file in ~/.matlab/R2007a.

    To override the default options file, use the 'mex -f' command
    (see 'mex -help' for more information).

The options files available for mex are:

  1: /Applications/MATLAB_SV74/bin/f90opts.sh : 
      Template Options file for building Fortran 90 MEX-files via the system ANSI
compiler
  2: /Applications/MATLAB_SV74/bin/gccopts.sh : 
      Template Options file for building gcc MEX-files
  3: /Applications/MATLAB_SV74/bin/mexopts.sh : 
      Template Options file for building MEX-files via the system ANSI compiler
  0: Exit with no changes
Enter the number of the compiler (0-3):

At the top of the 'compiler_settings.txt' it said that fortran was used but then
lower in the 'compiler_settings.txt' file, gcc is chosen so I was a bit 
confused.

Anyway as a first try I chose #2 gccopts.sh

then I ran the compileClass_maci.m file provided in the
'MacOS_precompiled-WITHOUT_SOURCE-v0.02' folder.  I got the following error:

Compiling Cokus (random number generator)...
i686-apple-darwin9-g++-4.0.1: cokus.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
Compiling rfsub.f (fortran subroutines)...
/bin/bash: /usr/local/bin/gfortran: No such file or directory
Compiling rfutils.cpp...
i686-apple-darwin9-g++-4.0.1: rfutils.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
Compiling classTree.cpp...
i686-apple-darwin9-g++-4.0.1: classTree.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
Compiling classRF.cpp...
i686-apple-darwin9-g++-4.0.1: classRF.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
Building RF training function...

    mex:  mex_ClassificationRF_train.cpp not a normal file or does not exist.

??? Error using ==> mex at 206
Unable to complete successfully.

Error in ==> compileClass_maci at 29
mex mex_ClassificationRF_train.cpp classRF.cpp classTree.o rfutils.o rfsub.o...

So I checked to make sure that this file exists:
EDU>> exist('mex_ClassificationRF_train.cpp')
ans =
     2
So indeed it does exist.  However maybe it was a problem with not running the
compileClass_maci.m in the src directories as I saw I had to do later with the
fortran version.

Next decided to try fortran. I choose #1 in the mac -setup above.  I installed
fortran from http://r.research.att.com/gfortran-4.2.3.dmg as suggested in the
compiler_settings.txt.  Note I did NOT alter 'mexopts.sh' as suggested in the
compiler_settings.txt as follows:

-----Matlab Mex options:-----
Here's the modificatins to the maci64 section from my 'mexopts.sh' file. There  
was a
problem with it using the wrong libgfortranbegin when building a 64-bit mex 
until I
hard-coded the correct path. BTW, you may want to clear out the 
'/usr/local/lib/'
directories before re-installing gfortran.

# To use the gfortran compiler, which must be installed separately,
# include the following modifications to the 'maci64' section of the
# '~/.matlab/R2009b/mexopts.sh' file

# -----Modifications by D.Jones, Sep-2009:--------------------
            FC='/usr/local/bin/gfortran'            
            FC_LIBDIR='/usr/local/lib/'
            FC_LIBDIR2='/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64/'
            FOPTIMFLAGS='-O5 -funroll-loops -ftree-vectorize'
# ------------------------------------------------------------ 

# Note that gfortran installs its libraries in ‰??/usr/local/lib/‰??

However things did compile. (NOTE: The script mfiles (compileClass_maci.m and
compileRegression_maci.m) had to be in the appropriate src directories
(randomforest-matlab/RF_Class_C/src and randomforest-matlab/RF_Reg_C/src
respectively).  Even though the path pointed to all folders with the necessary 
files,
and the exist function said missing files existed, I would get errors saying 
that
certain files did not exist if I ran the script files while not in the 
appropriate
src directories).  

When running compileClass_maci.m I got the following comments:

Compiling Cokus (random number generator)...
Compiling rfsub.f (fortran subroutines)...
Compiling rfutils.cpp...
Compiling classTree.cpp...
Compiling classRF.cpp...
classRF.cpp:114: warning: this decimal constant is unsigned only in ISO C90
Building RF training function...
classRF.cpp:114: warning: this decimal constant is unsigned only in ISO C90
Building RF prediction function...
classRF.cpp:114: warning: this decimal constant is unsigned only in ISO C90

And it created 
mexClassRF_predict.mexmaci
mexClassRF_train.mexmaci
Notice they are NOT .mexmaci64 files.  Perhaps this is because I did not modify 
the
'mexopts.sh' file as advised in the compiler_settings.txt.  

When running compile Regression_maci.m I got the following comments:

reg_RF.cpp:88: warning: this decimal constant is unsigned only in ISO C90
reg_RF.cpp:88: warning: this decimal constant is unsigned only in ISO C90

And it created 
mexRF_predict.mexmaci
mexRF_train.mexmaci
Again they are NOT .mexmaci64 files.  

Then I tried to do the tutorial 'tutorial_ClassRF.m'

Note: You might want to alter: 

%compile everything
if strcmpi(computer,'PCWIN') |strcmpi(computer,'PCWIN64')
   compile_windows
else
   compile_linux
end

for the possible mac people.

When I ran the tutorial file lines 14 through 41: 

%%
total_train_time=0;
total_test_time=0;

%load the twonorm dataset 
load data/twonorm

%modify so that training data is NxD and labels are Nx1, where N=#of
%examples, D=# of features

X = inputs';
Y = outputs;

[N D] =size(X);
%randomly split into 250 examples for training and 50 for testing
randvector = randperm(N);

X_trn = X(randvector(1:250),:);
Y_trn = Y(randvector(1:250));
X_tst = X(randvector(251:end),:);
Y_tst = Y(randvector(251:end));

%%

% example 1:  simply use with the defaults
    model = classRF_train(X_trn,Y_trn);
    Y_hat = classRF_predict(X_tst,model);
    fprintf('\nexample 1: error rate %f\n',   length(find(Y_hat~=Y_tst))/length(Y_tst));

I got the following error:

    Setting to defaults 500 trees and mtry=4
Too less/many parameters: You supplied 15??? One or more output arguments not
assigned during call to "mexClassRF_train".

Error in ==> classRF_train at 347

[nrnodes,ntree,xbestsplit,classwt,cutoff,treemap,nodestatus,nodeclass,bestvar,nd
bigtree,mtry
...

I see that this error is currently open issue 2 on the wikki.  

When I deleted the path to the precompiled folder
'MacOS_precompiled-WITHOUT_SOURCE-v0.02' the tutorial worked.  Yippee.  

Just as a side note, below is the 'mexopts.sh' from the Matlab 2007a version.  
This
is the file I could not figure out how to alter to get the .mexmaci64 files.

#
# gccopts.sh    Shell script for configuring MEX-file creation script,
#               mex.  These options were tested with gcc 3.2.3.
#
# usage:        Do not call this file directly; it is sourced by the
#               mex shell script.  Modify only if you don't like the
#               defaults after running mex.  No spaces are allowed
#               around the '=' in the variable assignment.
#
#               Note: only the gcc side of this script was tested.
#               The FORTRAN variables are lifted directly from
#               mexopts.sh; use that file for compiling FORTRAN
#               MEX-files.
#
# Note: For the version of system compiler supported with this release,
#       refer to Technical Note 1601 at:
#       http://www.mathworks.com/support/tech-notes/1600/1601.html
#
#
# SELECTION_TAGs occur in template option files and are used by MATLAB
# tools, such as mex and mbuild, to determine the purpose of the contents
# of an option file. These tags are only interpreted when preceded by '#'
# and followed by ':'.
#
#SELECTION_TAG_MEX_OPT: Template Options file for building gcc MEX-files
#
# Copyright 1984-2006 The MathWorks, Inc.
# $Revision: 1.43.4.9 $  $Date: 2006/10/14 11:47:34 $
#----------------------------------------------------------------------------
#
    TMW_ROOT="$MATLAB"
    MFLAGS=''
    if [ "$ENTRYPOINT" = "mexLibrary" ]; then
        MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat -lmwservices -lut -lm"
    else  
        MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat -lm"
    fi
    case "$Arch" in
        Undetermined)
#----------------------------------------------------------------------------
# Change this line if you need to specify the location of the MATLAB
# root directory.  The script needs to know where to find utility
# routines so that it can determine the architecture; therefore, this
# assignment needs to be done while the architecture is still
# undetermined.
#----------------------------------------------------------------------------
            MATLAB="$MATLAB"
#
# Determine the location of the GCC libraries
#
        GCC_LIBDIR=`gcc -v 2>&1 | awk '/.*Reading specs.*/ {print
substr($4,0,length($4)-6)}'`
            ;;
        glnx86)
#----------------------------------------------------------------------------
            RPATH="-Wl,-rpath-link,$TMW_ROOT/bin/$Arch"
            CC='gcc'
            CFLAGS='-fPIC -ansi -D_GNU_SOURCE -pthread -fexceptions -m32'
            CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64" 
            CLIBS="$RPATH $MLIBS -lm -lstdc++"
            COPTIMFLAGS='-O -DNDEBUG'
            CDEBUGFLAGS='-g'
#           
            CXX='g++'
            CXXFLAGS='-fPIC -ansi -D_GNU_SOURCE -pthread '
            CXXFLAGS="$CXXFLAGS -D_FILE_OFFSET_BITS=64" 
            CXXLIBS="$RPATH $MLIBS -lm"
            CXXOPTIMFLAGS='-O -DNDEBUG'
            CXXDEBUGFLAGS='-g'
#
#
            FC='g95'
            FFLAGS='-fPIC -fexceptions'
            FLIBS="$RPATH $MLIBS -lm"
            FOPTIMFLAGS='-O'
            FDEBUGFLAGS='-g'
#
            LD="$COMPILER"
            LDEXTENSION='.mexglx'
            LDFLAGS="-pthread -shared -m32
-Wl,--version-script,$TMW_ROOT/extern/lib/$Arch/$MAPFILE -Wl,--no-undefined"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
        glnxa64)
#----------------------------------------------------------------------------
            RPATH="-Wl,-rpath-link,$TMW_ROOT/bin/$Arch"
            CC='gcc'
            CFLAGS='-fPIC -fno-omit-frame-pointer -ansi -D_GNU_SOURCE -pthread
-fexceptions'
            CLIBS="$RPATH $MLIBS -lm -lstdc++"
            COPTIMFLAGS='-O -DNDEBUG'
            CDEBUGFLAGS='-g'
#           
            CXX='g++'
            CXXFLAGS='-fPIC -fno-omit-frame-pointer -ansi -D_GNU_SOURCE -pthread '
            CXXLIBS="$RPATH $MLIBS -lm"
            CXXOPTIMFLAGS='-O -DNDEBUG'
            CXXDEBUGFLAGS='-g'
#
#
            FC='g95'
            FFLAGS='-fPIC -fno-omit-frame-pointer -fexceptions'
            FLIBS="$RPATH $MLIBS -lm"
            FOPTIMFLAGS='-O'
            FDEBUGFLAGS='-g'
#
            LD="$COMPILER"
            LDEXTENSION='.mexa64'
            LDFLAGS="-pthread -shared
-Wl,--version-script,$TMW_ROOT/extern/lib/$Arch/$MAPFILE -Wl,--no-undefined"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
        sol2)
#----------------------------------------------------------------------------
            CC='gcc'
            GCC_LIBDIR=`$CC -v 2>&1 | sed -n '1s/[^\/]*\(.*\/lib\).*/\1/p'`
            CFLAGS='-fPIC -fexceptions'
            CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
            CLIBS="$MLIBS -lm"
            COPTIMFLAGS='-O -DNDEBUG'
            CDEBUGFLAGS='-g'  
            CXXFLAGS="$CXXFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
            CXXDEBUGFLAGS='-g'
#
            CXX='g++'
            CXXFLAGS='-fPIC'
            CXXLIBS="$MLIBS -lm"
            CXXOPTIMFLAGS='-O -DNDEBUG'
#
            LD="$COMPILER"
            LDEXTENSION='.mexsol'
            LDFLAGS="-shared -Wl,-M,$TMW_ROOT/extern/lib/$Arch/$MAPFILE,-R,$GCC_LIBDIR"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'  
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
        sol64)
#----------------------------------------------------------------------------
            CC='gcc'
            GCC_LIBDIR=`$CC -v 2>&1 | sed -n '1s/[^\/]*\(.*\/lib\).*/\1\/sparcv9/p'`
            CFLAGS='-fPIC -fexceptions -m64'
            CLIBS="$MLIBS -lm"
            COPTIMFLAGS='-O -DNDEBUG'
            CDEBUGFLAGS='-g'  
            CXXDEBUGFLAGS='-g'
#
            CXX='g++'
            CXXFLAGS='-fPIC -m64'
            CXXLIBS="$MLIBS -lm"
            CXXOPTIMFLAGS='-O -DNDEBUG'
#
            LD="$COMPILER"
            LDEXTENSION='.mexs64'
            LDFLAGS="-shared
-Wl,-M,$TMW_ROOT/extern/lib/$Arch/$MAPFILE,-R,$GCC_LIBDIR -m64"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'  
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
        mac)
#----------------------------------------------------------------------------
            CC='gcc-4.0'
            CFLAGS='-fno-common -no-cpp-precomp -fexceptions'
            CLIBS="$MLIBS -lstdc++"
            COPTIMFLAGS='-O3 -fno-loop-optimize -DNDEBUG'
            CDEBUGFLAGS='-g'
#
            CXX=g++-4.0
            CXXFLAGS='-fno-common -no-cpp-precomp -fexceptions -arch ppc'
            CXXLIBS="$MLIBS -lstdc++"
            CXXOPTIMFLAGS='-O3 -fno-loop-optimize -DNDEBUG'
            CXXDEBUGFLAGS='-g'
#
            FC='g95'
            FFLAGS="-fexceptions"
            FC_LIBDIR=`$FC -print-file-name=libf95.a 2>&1 | sed -n '1s/\/*libf95\.a//p'`
            FLIBS="$MLIBS -L$FC_LIBDIR -lf95"
            FOPTIMFLAGS='-O'
            FDEBUGFLAGS='-g'
#
            LD="$CC"
            LDEXTENSION='.mexmac'
            LDFLAGS="-bundle -Wl,-flat_namespace -undefined suppress
-Wl,-exported_symbols_list,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
        maci)
#----------------------------------------------------------------------------
            CC='gcc-4.0'
            CFLAGS='-fno-common -no-cpp-precomp -fexceptions'
            CLIBS="$MLIBS -lstdc++"
            COPTIMFLAGS='-O3 -DNDEBUG'
            CDEBUGFLAGS='-g'
#
            CXX=g++-4.0
            CXXFLAGS='-fno-common -no-cpp-precomp -fexceptions -arch i386'
            CXXLIBS="$MLIBS -lstdc++"
            CXXOPTIMFLAGS='-O3 -DNDEBUG'
            CXXDEBUGFLAGS='-g'
#
            FC='g95'
            FFLAGS="-fexceptions"
            FC_LIBDIR=`$FC -print-file-name=libf95.a 2>&1 | sed -n '1s/\/*libf95\.a//p'`
            FLIBS="$MLIBS -L$FC_LIBDIR -lf95"
            FOPTIMFLAGS='-O'
            FDEBUGFLAGS='-g'
#
            LD="$CC"
            LDEXTENSION='.mexmaci'
            LDFLAGS="-bundle -Wl,-flat_namespace -undefined suppress
-Wl,-exported_symbols_list,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'
#
            POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
            ;;
    esac
#############################################################################
#
# Architecture independent lines:
#
#     Set and uncomment any lines which will apply to all architectures.
#
#----------------------------------------------------------------------------
#           CC="$CC"
#           CFLAGS="$CFLAGS"
#           COPTIMFLAGS="$COPTIMFLAGS"
#           CDEBUGFLAGS="$CDEBUGFLAGS"
#           CLIBS="$CLIBS"
#
#           LD="$LD"
#           LDFLAGS="$LDFLAGS"
#           LDOPTIMFLAGS="$LDOPTIMFLAGS"
#           LDDEBUGFLAGS="$LDDEBUGFLAGS"
#----------------------------------------------------------------------------
#############################################################################

Original comment by ctee...@gmail.com on 17 May 2010 at 9:23

GoogleCodeExporter commented 8 years ago
Thank you so much for the detailed howto on getting everything to work on a 
mac. It 
will be helpful to others.

I think the reason why you are not getting a mexmaci64 rather than a mexmaci 
file is 
because the student version on macs run in 32-bit and probably will generate 
32-bit 
mex files (i.e. mexmaci) rather than 64-bit mex (i.e.mexmaci64)  
http://www.mathworks.com/support/solutions/en/data/1-5UW63C/index.html?
product=ML&solution=1-5UW63C

Original comment by abhirana on 17 May 2010 at 10:54

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
% To compile the Random Forests Classification code on the MAC OX System 
10.6.7.  I installed the GNU fortran 4.3.2 compiler and opened matlab and typed
% 
% mex -setup
% 
% then I navigated to the source code of the random forests classification 
folder and ran the compileClass_maci.m with THE FOLLOWING REPLACEMENT LINE
% 
% system('/usr/local/bin/gfortran -arch x86_64 -fno-common -c rfsub.f -o 
rfsub.o;');
% 
% The complete file is given below.  Once the two mexClassRF_train.mexmaci64 
and mexClassRF_predict.mexmaci64 are created move them both to the folder with 
the tutorial_ClassRF.m file and execute that tutorial.
% 

% Script file: compileClass_maci.m
% - create Matlab Mex versions of 'Random Forest'

% Notes: you must change to the SRC directory before calling this

% cokus:
fprintf('Compiling Cokus (random number generator)...\n');
system('g++ -fno-common -no-cpp-precomp -c cokus.cpp -o cokus.o;');

% rfsub:
fprintf('Compiling rfsub.f (fortran subroutines)...\n');
system('/usr/local/bin/gfortran -arch x86_64 -fno-common -c rfsub.f -o 
rfsub.o;');

% rfutils:
fprintf('Compiling rfutils.cpp...\n');
system('g++ -fno-common -no-cpp-precomp -c rfutils.cpp -o rfutils.o;');

% classTree:
fprintf('Compiling classTree.cpp...\n');
system('g++ -fno-common -no-cpp-precomp -c classTree.cpp -o classTree.o;');

% classRF:
fprintf('Compiling classRF.cpp...\n');
system('g++ -fno-common -no-cpp-precomp -c classRF.cpp -o classRF.o;');

% Mex Training function:
fprintf('Building RF training function...\n');
mex mex_ClassificationRF_train.cpp classRF.cpp classTree.o rfutils.o rfsub.o...
   cokus.o -o mexClassRF_train -lgfortran -lm -DMATLAB -g

% Mex Prediction function:
fprintf('Building RF prediction function...\n');
mex mex_ClassificationRF_predict.cpp classRF.cpp classTree.o rfutils.o 
rfsub.o...
   cokus.o -o mexClassRF_predict -lgfortran -lm -DMATLAB -g

Original comment by ambro...@gmail.com on 15 Apr 2011 at 7:00

GoogleCodeExporter commented 8 years ago
I currently working with Matlab 2008b. I downloaded the files from the svn 
repository, and run the tutorial_ClassRF.m. Mex Files compiled correctly, but 
on the first test the program fails. Below is the error message

Could Not Find C:\Program 
Files\MATLAB\R2008b\toolbox\RandomForest\RF_Class_C\*.mexw32 
I am going to use the precompiled fortran file
If it doesnt work then use cygwin+g77 (or gfortran) to recompile rfsub.f
Mex`s compiled correctly
    Setting to defaults 500 trees and mtry=4
??? Undefined function or method 'mexClassRF_train' for input arguments of type 
'int32'.

Original comment by cristoba...@gmail.com on 13 Apr 2012 at 6:49

GoogleCodeExporter commented 8 years ago
hi Cristobal

i just checked on my side and i am not getting the same error. maybe the paths 
are a bit borked and matlab is considering some other _train file instead of 
the current file

attached is the compiled svn version on my side. you might have to remove the 
compile_windows line (in tutorial_) else it will remove it before compiling

Original comment by abhirana on 13 Apr 2012 at 7:01

Attachments:

GoogleCodeExporter commented 8 years ago
Without compling anything your files work just fine with the tutorial file. 
I'll give a try with a harder task. I'll write to you crashing feedback. Thx

Original comment by cristoba...@gmail.com on 13 Apr 2012 at 7:12

GoogleCodeExporter commented 8 years ago
Hi I have been having issues getting compile.  On my MAC OSX local host, 
everything seems to be working fine.  However, I have been trying to do the 
same on the cluster and for some reason things are not compiling.  Im using 
MATLAB 2009a, and the cluster runs on linux x86_64... The error I have been 
getting is while trying to run tutorial_ is :

rm: cannot remove `*.mexglx': No such file or directory
rm: cannot remove `*.mexa64': No such file or directory
rm -rf *.mexa64 *.mexglx *.mexw32 *.o src/*.o tempbuild/*.o *.exe *~ gmon* 
diabetes_test cokus_test a.out
echo 'deleted mex files, object files, gmon files and diabetes_test'
deleted mex files, object files, gmon files and diabetes_test
echo -e 'Making mex'
Making mex
mex src/cokus.cpp src/mex_regressionRF_train.cpp src/reg_RF.cpp -o mexRF_train 
-DMATLAB 
make: mex: Command not found
make: *** [mex] Error 127
Mex compiled
    Setting to defaults 500 trees and mtry=3
??? Undefined function or method 'mexRF_train' for input arguments of type 
'int32'.

Error in ==> regRF_train at 283

I would appreciate any thought? cluster has g++ installed but nor sure if there 
is anything else missing...

thanks :)

Original comment by charles...@gmail.com on 24 Jul 2012 at 1:38

GoogleCodeExporter commented 8 years ago
@charles, the mex program comes with matlab. you either have to install matlab 
on the cluster (i am guessing matlab is installed but mex is not installed, its 
usually in matlab install directory/bin) or if you cannot use matlab on your 
cluster convert your .m file into an executable 

or maybe just compile mex files on your local linux machine which has mex and 
matlab and then copy the generated mex file onto the cluster (you might have to 
make sure that the matlab/g++ versions are equal)

Original comment by abhirana on 24 Jul 2012 at 1:53

GoogleCodeExporter commented 8 years ago
Thanks for your quick response.
Matlab is installed on the cluster, and I have ran the mex -setup command 
several times (which I presume is the installation of mex)...  I also did the 
latter option (compile on my machine and then copy the generated mex file into 
the cluster), but I got the same error.  
Thanks,
C

Original comment by charles...@gmail.com on 24 Jul 2012 at 3:47

GoogleCodeExporter commented 8 years ago
@charles,

actually the compile_linux.m uses the command prompt to spawn the compiling. 
mex -setup is run within matlab whereas the makefile for compilation is run 
within the shell. i am guessing mex is not in the path within the shell (try 
mex in a shell and see if the shell recognizes it)

try this, uncomment the lines 18-19, you might have to comment line 21 in 
compile_linux.m
http://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Reg_C/compil
e_linux.m#18

do you need the classification code working? do tell.

Original comment by abhirana on 24 Jul 2012 at 4:50

GoogleCodeExporter commented 8 years ago
Thanks for the great support.  If I run the compile_linux script here is the 
output I get:

./compile_linux.m: line 1: fg: no job control
./compile_linux.m: line 2: syntax error near unexpected token `('
./compile_linux.m: line 2: `% * mex File compiling code for Random Forest (for 
linux)'

As for your second question, I only need Regression for now and the near 
future...

Thanks,

Charlie

Original comment by charles...@gmail.com on 24 Jul 2012 at 11:47

GoogleCodeExporter commented 8 years ago
the compile_linux.m file has to be run within matlab like a matlab file

or run the following commands within matlab's command prompt while being in the 
RF_Class_C folder

mex mex_regressionRF_train.cpp reg_RF.cpp cokus.cpp -o mexRF_train -DMATLAB 
mex mex_regressionRF_predict.cpp reg_RF.cpp cokus.cpp -o mexRF_predict -DMATLAB

Original comment by abhirana on 25 Jul 2012 at 12:37

GoogleCodeExporter commented 8 years ago
Running the command: mex mex_regressionRF_train.cpp reg_RF.cpp cokus.cpp -o 
mexRF_train -DMATLAB 
gives me the following: mex_regressionRF_predict.cpp: In function ‘void 
mexFunction(int, mxArray**, int, const mxArray**)’:
mex_regressionRF_predict.cpp:75: warning: converting to ‘int’ from 
‘double’
mex_regressionRF_predict.cpp:80: warning: converting to ‘int’ from 
‘double’
reg_RF.cpp: In function ‘void permuteOOB(int, double*, int*, int, int)’:
reg_RF.cpp:178: warning: converting to ‘int’ from ‘double’
reg_RF.cpp: In function ‘void regRF(double*, double*, int*, int*, int*, int*, 
int*, int*, int*, int*, int, int*, int, int, int, double*, double*, double*, 
double*, double*, int*, char*, int*, int*, double*, int*, double*, double*, 
const int*, int*, int, double*, int*, double*, int, double*, double*, double*, 
double*, int*, int*)’:
reg_RF.cpp:381: warning: converting to ‘int’ from ‘double’

running tutorial_.m gives me same error as before:

rm: cannot remove `*.mexglx': No such file or directory
rm: cannot remove `*.mexa64': No such file or directory
rm -rf *.mexa64 *.mexglx *.mexw32 *.o src/*.o tempbuild/*.o *.exe *~ gmon* 
diabetes_test cokus_test a.out
echo 'deleted mex files, object files, gmon files and diabetes_test'
deleted mex files, object files, gmon files and diabetes_test
echo -e 'Making mex'
Making mex
mex src/cokus.cpp src/mex_regressionRF_train.cpp src/reg_RF.cpp -o mexRF_train 
-DMATLAB 
make: mex: Command not found
make: *** [mex] Error 127
Mex compiled
    Setting to defaults 500 trees and mtry=3
??? Undefined function or method 'mexRF_train' for input arguments of type 
'int32'.

Error in ==> regRF_train at 283
    [ldau,rdau,nodestatus,nrnodes,upper,avnode,...

Error in ==> tutorial_RegRF at 39
    model = regRF_train(X_trn,Y_trn);

Original comment by charles...@gmail.com on 25 Jul 2012 at 1:30

GoogleCodeExporter commented 8 years ago
the tutorial_files runs compile_windows/linux.m file at the start. it deletes 
the mex files and tries to compile them (and that wont work)

do the mex command steps i told posted in comment 15 and then before running 
tutorial_RegRF.m file
comment out line 8-13 
http://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Reg_C/tutori
al_RegRF.m#8

Original comment by abhirana on 25 Jul 2012 at 1:34

GoogleCodeExporter commented 8 years ago
yes, perfect.  This works fine now!

Thanks :)!

Original comment by charles...@gmail.com on 25 Jul 2012 at 4:06

GoogleCodeExporter commented 8 years ago
hi,I have some issues getting compile.Im using MATLAB 2013a, and the cluster 
runs on linux x86_64
compile_linux

rm: cannot remove `*.mexglx': No such file or directory
rm: cannot remove `*.mexa64': No such file or directory
rm twonorm_test -rf
rm  tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
rm twonorm_test -rf
rm  tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o 
tempbuild/classTree.o 
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran   -O2 -fpic  -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp  src/classRF.cpp tempbuild/classTree.o 
tempbuild/rfutils.o rfsub.o tempbuild/cokus.o  -o mexClassRF_train -lgfortran 
-lm -DMATLAB -g

Warning: You are using gcc version "4.6.3".  The version
         currently supported with MEX is "4.4.x".
         For a list of currently supported compilers see: 
         http://www.mathworks.com/support/compilers/current_release/

/usr/bin/ld: cannot find -lgfortran
collect2: ld returned 1 exit status

    mex: link of ' "mexClassRF_train.mexa64"' failed.

make: *** [mex_classRF] Error 1

I check the lgfortran:
candice@ubuntu:~$ ldconfig -p  |  grep   fortran
    libgfortran.so.3 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgfortran.so.3

Original comment by Candice0...@gmail.com on 17 Mar 2014 at 6:42

GoogleCodeExporter commented 8 years ago
@Candice08089
can you run the last command from the command prompt
mex src/mex_ClassificationRF_train.cpp  src/classRF.cpp tempbuild/classTree.o 
tempbuild/rfutils.o rfsub.o tempbuild/cokus.o  -o mexClassRF_train -lgfortran 
-lm -DMATLAB -g

Original comment by abhirana on 17 Mar 2014 at 4:44

GoogleCodeExporter commented 8 years ago
thanks for your replay.
I run the last command from the command prompt,it show :
 mex src/mex_ClassificationRF_train.cpp  src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o  -o mexClassRF_train -lgfortran -lm -DMATLAB -g
The program 'mex' can be found in the following packages:
 * texlive-lang-polish
 * texlive-lang-polish
Try: sudo apt-get install <selected package>

Original comment by Candice0...@gmail.com on 19 Mar 2014 at 6:12

GoogleCodeExporter commented 8 years ago
@candice08089

looks like the mex that is run is a command in the tex package rather than 
matlab's mex function. It's because Matlab mex might not be in the path.

go to matlab's bin directory (try 
ls -lt `which matlab`
where matlab is the command that you run to open matlab, and it should tell you 
the path to matlab
). You should have mex command in that folder. Then instead of writing mex in 
the command you tried earlier, substitute the entire path. For me it looks 
something like 

/opt/matlab/bin/mex src/mex_ClassificationRF_train.cpp  src/classRF.cpp 
tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o  -o 
mexClassRF_train -lgfortran -lm -DMATLAB -g

Original comment by abhirana on 19 Mar 2014 at 6:48

GoogleCodeExporter commented 8 years ago
thanks!
In matlab's bin directory have the mex file.
but it does not  work.I'm not sure I'm right or not.
I change the Makefile in RF_Class_C to 
/home/candice/MATLAB/R2013a/bin/mex -c $(SRC)classRF.cpp -outdir 
$(BUILD)classRF.o -DMATLAB $(MEXFLAGS)
    /home/candice/MATLAB/R2013a/bin/mex $(SRC)mex_ClassificationRF_train.cpp  $(SRC)classRF.cpp $(BUILD)classTree.o $(BUILD)rfutils.o rfsub.o $(BUILD)cokus.o  -o mexClassRF_train -lgfortran -lm -DMATLAB $(MEXFLAGS)
    /home/candice/MATLAB/R2013a/bin/mex $(SRC)mex_ClassificationRF_predict.cpp $(SRC)classRF.cpp $(BUILD)classTree.o $(BUILD)rfutils.o rfsub.o $(BUILD)cokus.o  -o mexClassRF_predict -lgfortran -lm -DMATLAB $(MEXFLAGS)

run compile_linux.m in matlab under the path 
/home/candice/RF_MexStandalone-v0.02-precompiled/randomforest-matlab/RF_Class_C 
it show:

compile_linux
rm: cannot remove `*.mexglx': No such file or directory
rm: cannot remove `*.mexa64': No such file or directory
rm twonorm_test -rf
rm  tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
rm twonorm_test -rf
rm  tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o 
tempbuild/classTree.o 
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran   -O2 -fpic  -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
/home/candice/MATLAB/R2013a/bin/mex src/mex_ClassificationRF_train.cpp  
src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o 
tempbuild/cokus.o  -o mexClassRF_train -lgfortran -lm -DMATLAB -g

Warning: You are using gcc version "4.6.3".  The version
         currently supported with MEX is "4.4.x".
         For a list of currently supported compilers see: 
         http://www.mathworks.com/support/compilers/current_release/

/usr/bin/ld: cannot find -lgfortran
collect2: ld returned 1 exit status

    mex: link of ' "mexClassRF_train.mexa64"' failed.

make: *** [mex_classRF] Error 1

the same issue when I run /home/candice/MATLAB/R2013a/bin/mex 
src/mex_ClassificationRF_train.cpp  src/classRF.cpp tempbuild/classTree.o 
tempbuild/rfutils.o rfsub.o tempbuild/cokus.o  -o mexClassRF_train -lgfortran 
-lm -DMATLAB -g in the command prompt

Original comment by Candice0...@gmail.com on 20 Mar 2014 at 1:36

Attachments:

GoogleCodeExporter commented 8 years ago
could you specify the library path for where gfortran is?
should be something like 
-L/usr/lib/x86_64-linux-gnu

and add that to the mex path?

if that doesnot work, are you by any chance running 32 bit matlab on 64bit?

Original comment by abhirana on 20 Mar 2014 at 1:40

GoogleCodeExporter commented 8 years ago
yes, in usr/lib/x84_64-linux-gnu can find libgfortran.so.3 and 
libgfortran.so.3.0.0.and I copy it to de mex in matlab but it doesnot work.
I check my matlab is 8.1.0.604-64-bit glinxa64.
run the /home/candice/MATLAB/R2013a/bin/mex src/mex_ClassificationRF_train.cpp  
src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o 
tempbuild/cokus.o  -o mexClassRF_train -lgfortran -lm -DMATLAB -g
have the same issue.

Original comment by Candice0...@gmail.com on 20 Mar 2014 at 2:00

GoogleCodeExporter commented 8 years ago
so you copied the libgfortran into the directory in which you run the mex file 
(i.e. in RF_Class_C directory, it will not work if you put in matlab's bin 
folder)?
either do that or add the following at the end of both the mex commands in the 
Makefile (line 38 and 39)
-L/usr/lib/x86_64-linux-gnu

it will look something like
mex $(SRC)mex_ClassificationRF_predict.cpp $(SRC_FILES) rfsub.o  -o 
mexClassRF_predict -lgfortran -lm -DMATLAB $(MEXFLAGS) 
-L/usr/lib/x86_64-linux-gnu

Original comment by abhirana on 20 Mar 2014 at 2:17

GoogleCodeExporter commented 8 years ago
or maybe its looking for libgfortran and not .so.3

http://stackoverflow.com/questions/6302209/building-r-package-getting-error-ld-c
annot-find-lgfortran/15540919#15540919

Original comment by abhirana on 20 Mar 2014 at 2:21

GoogleCodeExporter commented 8 years ago
yes, perfect!thank you very much! 
I copy libgfortran.so.3 to the directory and as sudo ln -s 
/usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
it work!thanks!

Original comment by Candice0...@gmail.com on 20 Mar 2014 at 3:11

GoogleCodeExporter commented 8 years ago
Hi I am using matlab2013a with MAC, and now I've just encountered a very basic 
problem that is, although I installed gfortran 4.8.2, when I type mex -setup in 
matlab, it only gives me 2 options:

>> mex -setup

    Options files control which compiler to use, the compiler and link command
    options, and the runtime libraries to link against.

    Using the 'mex -setup' command selects an options file that is
    placed in /Users/cathy/.matlab/R2013a and used by default for 'mex'. An options 
    file in the current working directory or specified on the command line 
    overrides the default options file in /Users/cathy/.matlab/R2013a.

    To override the default options file, use the 'mex -f' command
    (see 'mex -help' for more information).

The options files available for mex are:

  1: /Applications/MATLAB_R2013a.app/bin/mexopts.sh : 
      Template Options file for building MEX-files

  0: Exit with no changes

Enter the number of the compiler (0-1):

I have completely no idea why I don't have  the gccopts.sh file in bin. But 
according to 
http://www.mathworks.com/support/compilers/R2013a/index.html?sec=maci64 , 2013a 
support GNU gfortran 4.3.x, but my gfrotran is 4.8.2, is it because the version 
is not correct?

By the way, the installation path of 4.8.2 is different with 4.2.x in the 
readme file so I change the path accordingly.

Original comment by xiao.luo...@gmail.com on 18 Apr 2014 at 12:18