initWorkspaceLibSVM.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. elseif strcmp( getenv('USER'), 'kaeding')
  23. LIBSMVDIR = '/home/kaeding/lib/libsvm-3.20/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. %% 3rd party, untouched
  40. if ( isempty(LIBSMVDIR) )
  41. fprintf('InitPatchDiscovery-WARNING - no LIBSMVDIR dir found on your machine. Code is available at https://github.com/cjlin1/libsvm/ \n');
  42. else
  43. b_recursive = true;
  44. b_overwrite = true;
  45. addPathSafely ( LIBSMVDIR, b_recursive, b_overwrite );
  46. end
  47. %% clean up
  48. clear( 'LIBSMVDIR' );
  49. end
  50. function addPathSafely ( s_path, b_recursive, b_overwrite )
  51. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  52. if ( b_overwrite )
  53. if ( b_recursive )
  54. rmpath( genpath( s_path ) );
  55. else
  56. rmpath( s_path );
  57. end
  58. else
  59. fprintf('initWSLibSVM - %s already in your path but overwriting de-activated.\n', s_path);
  60. return;
  61. end
  62. end
  63. if ( b_recursive )
  64. addpath( genpath( s_path ) );
  65. else
  66. addpath( s_path );
  67. end
  68. end