ITE / code / ITE_install.m

Full commit
function [] = ITE_install(ITE_code_dir)
%Installs the ITE toolbox.
%   ITE_code_dir: directory containing the ITE package, e.g., 'C:\ITE\code'
%   A typical usage is to first 'cd' to the the 'code' directory in Matlab/Octave, and call ITE_install(pwd);
%Copyright (C) 2012 Zoltan Szabo ("", "szzoli (at) cs (dot) elte (dot) hu")
%This file is part of the ITE (Information Theoretical Estimators) Matlab toolbox.
%ITE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
%This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
%You should have received a copy of the GNU General Public License along with ITE. If not, see <>.

    compile_NCut = 1;%1=compile, 0=do not compile
    compile_ANN = 1;%1=compile, 0=do not compile
    compile_knn = 1;%1=compile, 0=do not compile
	compile_chol_gauss = 1;%1=compile, 0=do not compile; (not necessary, but can further speed-up the computations; the package also contains the purely Matlab/Octave 'chol_gauss.m')
	delete_Ncut_in_Octave = 0; %1=yes, 0=no

disp('Installation: started.');

%query for the current working environment (Matlab/Octave):
  addpath(strcat(ITE_code_dir,'/shared'));%to be able to call 'working_environment_Matlab'
  environment_Matlab = working_environment_Matlab;
%delete the not necessary (depending on the working environment) ann wrappers:
    if environment_Matlab
        rmdir(strcat(ITE_code_dir,'/shared/embedded/ann_wrapperO/'),'s');%delete 'ann_wrapperO' with subfolders.    
        disp('We are working in Matlab environment => ann_wrapper for Octave: deleted.');%the 'ann' file may otherwise cause conflicts
        rmdir(strcat(ITE_code_dir,'/shared/embedded/ann_wrapperM/'),'s');%delete 'ann_wrapperM' with subfolders.    
        disp('We are working in Octave environment => ann_wrapper for Matlab: deleted.');%the 'ann' file may otherwise cause conflicts
%download and extract the ARfit package to '/shared/embedded/ARfit':
    disp('ARfit package: downloading, extraction: started.');
    [FN,status] = urlwrite('','');
    if status %downloading: successful
        %create 'shared/downloaded/ARfit', if needed:
            if ~exist('shared/downloaded/ARfit')
                if ~mkdir('shared/downloaded') || ~mkdir('shared/downloaded/ARfit');%Octave
                    disp('Error: making directory for ARfit failed.');
        unzip(FN,strcat(ITE_code_dir, '/shared/downloaded/ARfit'));
        delete(FN);%delete the .zip file
        disp('ARfit package: downloading, extraction: ready.');
        disp('Error: ARfit package could not been downloaded.');
%add 'ITE_code_dir' with its subfolders to the Matlab PATH:
    if environment_Matlab
        env = 'Matlab';
        env = 'Octave';
    disp(strcat(['ITE directory: added with subfolders to the ',env,' PATH.']));
%store the current working directory:
     pd = pwd;   
if environment_Matlab
    %compile 'ANN':
        if compile_ANN%if needed
			cd(strcat(ITE_code_dir,'/shared/embedded/ann_wrapperM')); %cd 'ann_wrapperM'
            disp('ANN compilation: started.');
            ann_class_compile; %compile the ANN package
            disp('ANN compilation: ready.'); %Note: it is sufficient if 'mex_w_times_x_symmetric.cpp', 'sparsifyc.cpp' and 'spmtimesd.cpp' compile successfully.
    %compile 'NCut':
        if compile_NCut%if needed
			cd(strcat(ITE_code_dir,'/shared/embedded/NCut')); %cd 'NCut'
            disp('NCut compilation: started.');
            compileDir_simple;%compile the NCut package
            disp('NCut compilation: ready.');
	if delete_Ncut_in_Octave
		rmdir(strcat(ITE_code_dir,'/shared/embedded/NCut/'),'s');%delete NCut with subfolders.
		disp('We are working in Octave environment => NCut: deleted.');

%compile 'chol_gauss', if needed:	
	if compile_chol_gauss    
        cd(strcat(ITE_code_dir,'/shared/embedded/TCA'));%cd 'TCA'
        disp('chol_gauss compilation: started.');
        mex chol_gauss.c;
        disp('chol_gauss compilation: ready.');

%compile 'knn', if needed:
    if compile_knn%if needed
        disp('knn compilation: started.');
        build; %compile the knn package (top.cpp)
        disp('knn compilation: ready.');

%change back to the stored working directory:
%quick tests:
    disp('Installation tests:');
    if environment_Matlab
            Y = rand(3,100); Q = rand(3,200); k = 3; epsi = 0.1;
            ann_object = ann(Y);
            [indices, squared_distances] = ksearch(ann_object, Q, k, epsi,0);%'0': nearest neighbors do not include the points
            disp('ANN quick test: successful.');

            A = rand(10); A = A + A.'; num_of_comps = 2;
            ClusterIndicators = ncutW(A,num_of_comps);
            disp('NCut quick test: successful.');
        d = 2; A = 0.9 * random_orthogonal(d); T = 1000;   Ls = 1;
        v = arsim(zeros(d,1),A,eye(d),T);
        [w_temp, Fx_hat, C, SBCs] = arfit(v, Ls, Ls);
        disp('ARfit quick test: successful.');
        Y = rand(3,100); Q = rand(3,200);
        disp('knn quick test: successful.');