initWorkspaceLibLinear.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. else
  25. fprintf('Unknown user %s and unknown default settings', getenv('USER') );
  26. end
  27. % add main path
  28. b_recursive = false;
  29. b_overwrite = true;
  30. s_pathMain = fullfile(pwd);
  31. addPathSafely ( s_pathMain, b_recursive, b_overwrite )
  32. clear ( 's_pathMain' );
  33. % for addFieldWithDefault.m
  34. b_recursive = true;
  35. b_overwrite = true;
  36. s_pathMisc = fullfile(pwd, 'misc');
  37. addPathSafely ( s_pathMisc, b_recursive, b_overwrite )
  38. clear ( 's_pathMisc' );
  39. % for binary evaluation metrics such as auc during cross val
  40. b_recursive = true;
  41. b_overwrite = true;
  42. s_pathMisc = fullfile(pwd, 'binary');
  43. addPathSafely ( s_pathMisc, b_recursive, b_overwrite )
  44. clear ( 's_pathMisc' );
  45. %% 3rd party, untouched
  46. if ( isempty(LIBLINEARDIR) )
  47. fprintf('InitPatchDiscovery-WARNING - no LIBLINEARDIR dir found on your machine. Code is available at http://www.csie.ntu.edu.tw/~cjlin/liblinear/ \n');
  48. else
  49. b_recursive = true;
  50. b_overwrite = true;
  51. addPathSafely ( LIBLINEARDIR, b_recursive, b_overwrite );
  52. end
  53. %% clean up
  54. clear( 'LIBLINEARDIR' );
  55. end
  56. function addPathSafely ( s_path, b_recursive, b_overwrite )
  57. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  58. if ( b_overwrite )
  59. if ( b_recursive )
  60. rmpath( genpath( s_path ) );
  61. else
  62. rmpath( s_path );
  63. end
  64. else
  65. fprintf('initWSLibLinear - %s already in your path but overwriting de-activated.\n', s_path);
  66. return;
  67. end
  68. end
  69. if ( b_recursive )
  70. addpath( genpath( s_path ) );
  71. else
  72. addpath( s_path );
  73. end
  74. end