initWorkspaceLibLinear.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function initWorkspaceLibLinear
  2. % function initWorkspaceLibLinear
  3. %
  4. % BRIEF
  5. % Add local subfolders and 3rd party libraries to Matlabs work space.
  6. %
  7. % Exemplary call from external position:
  8. % LIBLINEARWRAPDIR = '/place/to/this/repository/';
  9. % currentDir = pwd;
  10. % cd ( LIBLINEARWRAPDIR );
  11. % initWorkspaceLibLinear;
  12. % cd ( currentDir );
  13. %
  14. %
  15. % Author: Alexander Freytag
  16. %% setup paths in user-specific manner
  17. % currently we do not have any dependencies, but if we would have some,
  18. % we would add them here
  19. %% add paths which come with this repository
  20. if strcmp( getenv('USER'), 'freytag')
  21. LIBLINEARDIR = '/home/freytag/code/3rdParty/liblinear-1.93/matlab/';
  22. elseif strcmp( getenv('USER'), 'rodner')
  23. LIBLINEARDIR = '/home/freytag/code/3rdParty/liblinear-1.93/matlab/';
  24. elseif strcmp( getenv('USER'), 'kaeding')
  25. LIBLINEARDIR = '/home/kaeding/lib/liblinear-multicore-2.1-2/matlab/';
  26. else
  27. fprintf('Unknown user %s and unknown default settings', getenv('USER') );
  28. end
  29. % add main path
  30. b_recursive = false;
  31. b_overwrite = true;
  32. s_pathMain = fullfile(pwd);
  33. addPathSafely ( s_pathMain, b_recursive, b_overwrite )
  34. clear ( 's_pathMain' );
  35. % for addFieldWithDefault.m
  36. b_recursive = true;
  37. b_overwrite = true;
  38. s_pathMisc = fullfile(pwd, 'misc');
  39. addPathSafely ( s_pathMisc, b_recursive, b_overwrite )
  40. clear ( 's_pathMisc' );
  41. % for binary evaluation metrics such as auc during cross val
  42. b_recursive = true;
  43. b_overwrite = true;
  44. s_pathMisc = fullfile(pwd, 'binary');
  45. addPathSafely ( s_pathMisc, b_recursive, b_overwrite )
  46. clear ( 's_pathMisc' );
  47. %% 3rd party, untouched
  48. if ( isempty(LIBLINEARDIR) )
  49. fprintf('InitPatchDiscovery-WARNING - no LIBLINEARDIR dir found on your machine. Code is available at http://www.csie.ntu.edu.tw/~cjlin/liblinear/ \n');
  50. else
  51. b_recursive = true;
  52. b_overwrite = true;
  53. addPathSafely ( LIBLINEARDIR, b_recursive, b_overwrite );
  54. end
  55. %% clean up
  56. clear( 'LIBLINEARDIR' );
  57. end
  58. function addPathSafely ( s_path, b_recursive, b_overwrite )
  59. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  60. if ( b_overwrite )
  61. if ( b_recursive )
  62. rmpath( genpath( s_path ) );
  63. else
  64. rmpath( s_path );
  65. end
  66. else
  67. fprintf('initWSLibLinear - %s already in your path but overwriting de-activated.\n', s_path);
  68. return;
  69. end
  70. end
  71. if ( b_recursive )
  72. addpath( genpath( s_path ) );
  73. else
  74. addpath( s_path );
  75. end
  76. end