plot1dExampleClassification.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. % BRIEF: Small visualization script using GPHIKClassifier
  2. % author: Alexander Freytag
  3. % date: 20-01-2014 (dd-mm-yyyy)
  4. myData = [ 0.2; 0.6; 0.9];
  5. % create l1-normalized 'histograms'
  6. myData = cat(2,myData , 1-myData);
  7. myLabels = [1; 2; 2];
  8. % init new GPHIKClassifier object
  9. myGPHIKClassifier = GPHIKClassifier ( 'verbose', 'false', ...
  10. 'optimization_method', 'none', 'varianceApproximation', 'approximate_fine',...
  11. 'nrOfEigenvaluesToConsiderForVarApprox',2,...
  12. 'uncertaintyPredictionForClassification', true, ...
  13. 'noise', 0.000001 ...
  14. );
  15. % run train method
  16. myGPHIKClassifier.train( myData, myLabels );
  17. myDataTest = 0:0.01:1;
  18. % create l1-normalized 'histograms'
  19. myDataTest = cat(1, myDataTest, 1-myDataTest)';
  20. scores = zeros(size(myDataTest,1),1);
  21. uncertainties = zeros(size(myDataTest,1),1);
  22. for i=1:size(myDataTest,1)
  23. example = myDataTest(i,:);
  24. [ classNoEst, score, uncertainties(i)] = myGPHIKClassifier.classify( example );
  25. scores(i) = score(1);
  26. end
  27. % create figure and set title
  28. classificationFig = figure;
  29. set ( classificationFig, 'name', 'Classification with GPHIK');
  30. hold on;
  31. %#initialize x array
  32. x=0:0.01:1;
  33. %#create first curve
  34. uncLower=scores-uncertainties;
  35. %#create second curve
  36. uncUpper=scores+uncertainties;
  37. %#create polygon-like x values for plotting
  38. X=[x,fliplr(x)];
  39. %# concatenate y-values accordingly
  40. Y=[uncLower',fliplr(uncUpper')];
  41. %#plot filled area
  42. fill(X,Y,'y');
  43. % plot mean values
  44. plot ( x,scores, ...
  45. 'LineStyle', '--', ...
  46. 'LineWidth', 2, ...
  47. 'Color', 'r', ...
  48. 'Marker','none', ...
  49. 'MarkerSize',1, ...
  50. 'MarkerEdgeColor','r', ...
  51. 'MarkerFaceColor',[0.5,0.5,0.5] ...
  52. );
  53. % plot training data
  54. plot ( myData(:,1), 2*(myLabels==1)-1, ...
  55. 'LineStyle', 'none', ...
  56. 'LineWidth', 3, ...
  57. 'Marker','o', ...
  58. 'MarkerSize',6, ...
  59. 'MarkerEdgeColor','b', ...
  60. 'MarkerFaceColor',[0.5,0.5,0.5] ...
  61. );
  62. xlabel('1st Input dimension');
  63. ylabel('Classification score');
  64. i_fontSizeAxis = 16;
  65. set(get(gca,'XLabel'), 'FontSize', i_fontSizeAxis);
  66. set(get(gca,'YLabel'), 'FontSize', i_fontSizeAxis);
  67. % clean up and delete object
  68. myGPHIKClassifier.delete();
  69. clear ( 'myGPHIKClassifier' );