Source

ITE / code / ITE_install.m

function [] = ITE_install(ITE_code_dir)
%Installs the ITE toolbox.
%
%INPUT:
%   ITE_code_dir: directory containing the ITE package, e.g., 'C:\ITE\code'
%EXAMPLE:
%   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 ("http://nipg.inf.elte.hu/szzoli", "szzoli (at) cs (dot) elte (dot) hu")
%
%This file is part of the ITE (Information Theoretical Estimators) Matlab/Octave 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 <http://www.gnu.org/licenses/>.

%parameters:
	%compile:
		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_TCA = 1;%1=compile, 0=do not compile (chol_gauss); not necessary, but can further speed-up the computations; the package also contains the purely Matlab/Octave 'chol_gauss.m'
		compile_SWICA = 1; %1=compile, 0=do not compile; not necessary, but can accelerate computations; the package also contains the purely Matlab/Octave 'SW_kappa.m' and 'SW_sigma.m'
		compile_Hoeffding_term1 = 1; %1=compile, 0=do not compile; not necessary, but can be more ecomical in terms of memory used + accelerate computations; the package also contains the purely Matlab/Octave 'Hoeffding_term1.m'
		compile_Edgeworth_t1_t2_t3 = 1; %1=compile, 0=do not compile; not necessary, but can accelerate computations; the ITE package also contains the purely Matlab/Octave 'Edgeworth_t1_t2_t3.m'
		compile_CDSS = 1; %1=compile, 0=do not compile; not necessary, but can speed up the computations; the ITE package also contains the purely Matlab/Octave 'compute_CDSS.m'
    %download:
		download_ARfit = 1;%1=download+extract,0=do not download
	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
    else
        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
    end
	
if download_ARfit  %download and extract the ARfit package to '/shared/embedded/ARfit':
    disp('ARfit package: downloading, extraction: started.');
    [FN,status] = urlwrite('http://www.gps.caltech.edu/~tapio/arfit/arfit.zip','arfit.zip');
    if status %downloading: successful
        %create 'shared/downloaded/ARfit', if needed:
            if ~exist('shared/downloaded/ARfit')
                %mkdir('shared/downloaded/ARfit');%Matlab
                if ~mkdir('shared/downloaded') || ~mkdir('shared/downloaded/ARfit');%Octave
                    error('Making directory for ARfit: failed.');
                end
            end
        unzip(FN,strcat(ITE_code_dir, '/shared/downloaded/ARfit'));
        delete(FN);%delete the .zip file
        disp('ARfit package: downloading, extraction: ready.');
    else
        error('The ARfit package could not been downloaded.');
    end    
end

%add 'ITE_code_dir' with its subfolders to the Matlab PATH:
    addpath(genpath(ITE_code_dir));
    if environment_Matlab
        env = 'Matlab';
    else
        env = 'Octave';
    end
    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.
        end	
    %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.');
        end    
else
	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.');
    end
end

%compile TCA (chol_gauss.c), if needed:	
	if compile_TCA
        cd(strcat(ITE_code_dir,'/shared/embedded/TCA'));%cd 'TCA'
        disp('TCA (chol_gauss.c) compilation: started.');
        mex chol_gauss.c;
        disp('TCA (chol_gauss.c) compilation: ready.');
    end
    
%compile SWICA (SW_kappa.cpp, SW_sigma.cpp), if needed:    
    if compile_SWICA
        cd(strcat(ITE_code_dir,'/shared/embedded/SWICA'));%cd 'SWICA'
        disp('SWICA (SW_kappa.cpp, SW_sigma.cpp) compilation: started.');
        build_SWICA;
        disp('SWICA (SW_kappa.cpp, SW_sigma.cpp) compilation: ready.');
    end

%compile 'Hoeffding_term1.cpp', if needed:
    if compile_Hoeffding_term1    
        cd(strcat(ITE_code_dir,'/H_I_D/utilities'));
        disp('Hoeffding_term1.cpp compilation: started.');
        mex Hoeffding_term1.cpp;
        disp('Hoeffding_term1.cpp compilation: ready.');
    end

%compile 'Edgeworth_t1_t2_t3.cpp', if needed:
    if compile_Edgeworth_t1_t2_t3
        cd(strcat(ITE_code_dir,'/H_I_D/utilities'));
        disp('Edgeworth_t1_t2_t3.cpp compilation: started.');
        mex Edgeworth_t1_t2_t3.cpp;
        disp('Edgeworth_t1_t2_t3.cpp compilation: ready.');
    end

%compile 'compute_CDSS.cpp', if needed:
    if compile_CDSS
        cd(strcat(ITE_code_dir,'/H_I_D/utilities'));
        disp('compute_CDSS.cpp compilation: started.');
        mex compute_CDSS.cpp;
        disp('compute_CDSS.cpp compilation: ready.');
    end

%compile 'knn', if needed:
    if compile_knn%if needed
        cd(strcat(ITE_code_dir,'/shared/embedded/knn'));
        disp('knn (top.cpp) compilation: started.');
        build; %compile the knn package (top.cpp)
        disp('knn (top.cpp) compilation: ready.');
    end
	
%change back to the stored working directory:
    cd(pd);
    
%quick tests:
    disp('-------------------');
    disp('Installation tests:');
    if environment_Matlab
	    %ANN:
			if compile_ANN%verify only in case of compilation
				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.');
			end
		%NCut:			
			if compile_NCut%verify only in case of compilation
				A = rand(10); A = A + A.'; num_of_comps = 2;
				ClusterIndicators = ncutW(A,num_of_comps);
				disp('NCut quick test: successful.');
			end
    end        
    %ARfit:
		if download_ARfit %verify only in case of downloading
			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.');
		end
	%knn:
		if compile_knn%verify only in case of compilation
			Y = rand(3,100); Q = rand(3,200);
			knn(Q,Y,1);
			disp('knn quick test: successful.');
		end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.