initWorkspaceLibSVM.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function initWorkspaceLibSVM
  2. % function initWorkspaceLibSVM
  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. % initWorkspaceLibSVM;
  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. LIBSMVDIR = '/home/freytag/code/3rdParty/libsvm/matlab/';
  22. else
  23. fprintf('Unknown user %s and unknown default settings', getenv('USER') );
  24. end
  25. % add main path
  26. b_recursive = false;
  27. b_overwrite = true;
  28. s_pathMain = fullfile(pwd);
  29. addPathSafely ( s_pathMain, b_recursive, b_overwrite )
  30. clear ( 's_pathMain' );
  31. % for addFieldWithDefault.m
  32. b_recursive = true;
  33. b_overwrite = true;
  34. s_pathMisc = fullfile(pwd, 'misc');
  35. addPathSafely ( s_pathMisc, b_recursive, b_overwrite )
  36. clear ( 's_pathMisc' );
  37. %% 3rd party, untouched
  38. if ( isempty(LIBSMVDIR) )
  39. fprintf('InitPatchDiscovery-WARNING - no LIBSMVDIR dir found on your machine. Code is available at https://github.com/cjlin1/libsvm/ \n');
  40. else
  41. b_recursive = true;
  42. b_overwrite = true;
  43. addPathSafely ( LIBSMVDIR, b_recursive, b_overwrite );
  44. end
  45. %% clean up
  46. clear( 'LIBSMVDIR' );
  47. end
  48. function addPathSafely ( s_path, b_recursive, b_overwrite )
  49. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  50. if ( b_overwrite )
  51. if ( b_recursive )
  52. rmpath( genpath( s_path ) );
  53. else
  54. rmpath( s_path );
  55. end
  56. else
  57. fprintf('initWSLibSVM - %s already in your path but overwriting de-activated.\n', s_path);
  58. return;
  59. end
  60. end
  61. if ( b_recursive )
  62. addpath( genpath( s_path ) );
  63. else
  64. addpath( s_path );
  65. end
  66. end