testGPHIKClassifier.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. % brief: Demo-program showing how to use the GPHIKClassifier Interface (including the class wrapper)
  2. % author: Alexander Freytag
  3. % date: 07-01-2014 (dd-mm-yyyy)
  4. myData = [ 0.2 0.3 0.5;
  5. 0.3 0.2 0.5;
  6. 0.9 0.0 0.1;
  7. 0.8 0.1 0.1;
  8. 0.1 0.1 0.8;
  9. 0.1 0.0 0.9
  10. ];
  11. myLabels = [1,1,2,2,3,3];
  12. % boolean
  13. b_verboseTime = false;
  14. b_verbose = false;
  15. b_uncertaintyPredictionForClassification ...
  16. = false;
  17. b_optimize_noise = false;
  18. b_use_quantization = false;
  19. b_ils_verbose = false;
  20. %
  21. % integer
  22. i_nrOfEigenvaluesToConsiderForVarApprox ...
  23. = 4;
  24. i_num_bins = 100; % default
  25. i_ils_max_iterations = 1000; % default
  26. %
  27. % double
  28. d_ils_min_delta = 1e-7; % default
  29. d_ils_min_residual = 1e-7; % default
  30. d_noise = 0.1; % default
  31. %
  32. % string
  33. s_ils_method = 'CG'; % default
  34. s_optimization_method = 'greedy';
  35. settings.settingsGPHIK.s_transform = 'identity';
  36. settings.settingsGPHIK.s_varianceApproximation...
  37. = 'approximate_fine';
  38. % init new GPHIKClassifier object
  39. myGPHIKClassifier = ...
  40. GPHIKClassifier ( ...
  41. 'verboseTime', b_verboseTime, ...
  42. 'verbose', b_verbose, ...
  43. 'uncertaintyPredictionForClassification', b_uncertaintyPredictionForClassification, ...
  44. 'optimize_noise', b_optimize_noise, ...
  45. 'use_quantization', b_use_quantization, ...
  46. 'ils_verbose', b_ils_verbose, ...
  47. ...
  48. 'num_bins', i_num_bins, ...
  49. 'ils_max_iterations', i_ils_max_iterations, ...
  50. ...
  51. 'ils_min_delta', d_ils_min_delta, ...
  52. 'ils_min_residual', d_ils_min_residual, ...
  53. 'noise', d_noise, ...
  54. ...
  55. 'ils_method', s_ils_method, ...
  56. 'optimization_method', s_optimization_method ...
  57. );
  58. % GPHIKClassifier (...
  59. % 'verbose', 'false', ...
  60. % 'optimization_method', 'none', ...
  61. % 'varianceApproximation', 'approximate_fine',...
  62. % 'nrOfEigenvaluesToConsiderForVarApprox', 4,...
  63. % 'uncertaintyPredictionForClassification', false ...
  64. %
  65. % );
  66. % run train method
  67. myGPHIKClassifier.train( myData, myLabels );
  68. % check the reclassification is working!
  69. [ arrReCl, confMatReCl, scoresReCl] = myGPHIKClassifier.test( myData, myLabels )
  70. uncertainty = myGPHIKClassifier.uncertainty( myData(1,:) )
  71. myDataTest = [ 0.3 0.4 0.3
  72. ];
  73. myLabelsTest = [1];
  74. % run single classification call
  75. [ classNoEst, score, uncertainty] = myGPHIKClassifier.classify( myDataTest )
  76. % compute predictive variance
  77. uncertainty = myGPHIKClassifier.uncertainty( myDataTest )
  78. % run test method evaluating arr potentially using multiple examples
  79. [ arr, confMat, scores] = myGPHIKClassifier.test( myDataTest, myLabelsTest )
  80. % add a single new example
  81. newExample = [ 0.5 0.5 0.0
  82. ];
  83. newLabel = [4];
  84. myGPHIKClassifier.addExample( newExample, newLabel);
  85. % add mutiple new examples
  86. newExamples = [ 0.3 0.3 0.4;
  87. 0.1, 0.2, 0.7
  88. ];
  89. newLabels = [1,3];
  90. myGPHIKClassifier.addMultipleExamples( newExamples, newLabels );
  91. % perform evaluation again
  92. % run single classification call
  93. [ classNoEst, score, uncertainty] = myGPHIKClassifier.classify( myDataTest )
  94. % compute predictive variance
  95. uncertainty = myGPHIKClassifier.uncertainty( myDataTest )
  96. % run test method evaluating arr potentially using multiple examples
  97. [ arr, confMat, scores] = myGPHIKClassifier.test( myDataTest, myLabelsTest )
  98. % clean up and delete object
  99. myGPHIKClassifier.delete();
  100. clear ( 'myGPHIKClassifier' );