plot1dExampleRegression.m 2.3 KB

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