plot1dExampleRegression.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. %% boolean
  10. %interested in time measurements?
  11. b_verboseTime = false;
  12. %interested in outputs?
  13. b_verbose = false;
  14. % important for plotting!
  15. b_uncertaintyPredictionForRegression ...
  16. = true;
  17. b_optimize_noise = false;
  18. b_use_quantization = false;
  19. b_ils_verbose = false;
  20. %
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. %% integer
  23. i_nrOfEigenvaluesToConsiderForVarApprox ...
  24. = 2;
  25. i_num_bins = 100; % default
  26. i_ils_max_iterations = 1000; % default
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. %% double
  29. d_ils_min_delta = 1e-7; % default
  30. d_ils_min_residual = 1e-7; % default
  31. % model regularization
  32. d_noise = 0.000001;
  33. % adapt parameter bounds if you are interested in optimization
  34. d_parameter_lower_bound = 1.0;
  35. d_parameter_upper_bound = 1.0;
  36. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  37. %% string
  38. s_ils_method = 'CG'; % default
  39. % options: 'none', 'greedy', 'downhillsimplex'
  40. s_optimization_method = 'none';
  41. % options: 'identity', 'abs', 'absexp'
  42. % with settings above, this equals 'identity'
  43. s_transform = 'absexp';
  44. % options: 'exact', 'approximate_fine', 'approximate_rough', and 'none'
  45. s_varianceApproximation = 'exact';
  46. % init new GPHIKRegression object
  47. myGPHIKRegression = ...
  48. GPHIKRegression ( ...
  49. 'verboseTime', b_verboseTime, ...
  50. 'verbose', b_verbose, ...
  51. 'uncertaintyPredictionForRegression', b_uncertaintyPredictionForRegression, ...
  52. 'optimize_noise', b_optimize_noise, ...
  53. 'use_quantization', b_use_quantization, ...
  54. 'ils_verbose', b_ils_verbose, ...
  55. ...
  56. 'nrOfEigenvaluesToConsiderForVarApprox', i_nrOfEigenvaluesToConsiderForVarApprox, ...
  57. 'num_bins', i_num_bins, ...
  58. 'ils_max_iterations', i_ils_max_iterations, ...
  59. ...
  60. 'ils_min_delta', d_ils_min_delta, ...
  61. 'ils_min_residual', d_ils_min_residual, ...
  62. 'noise', d_noise, ...
  63. 'parameter_lower_bound', d_parameter_lower_bound, ...
  64. 'parameter_upper_bound', d_parameter_upper_bound, ...
  65. ...
  66. 'ils_method', s_ils_method, ...
  67. 'optimization_method', s_optimization_method, ...
  68. 'transform', s_transform, ...
  69. 'varianceApproximation', s_varianceApproximation ...
  70. );
  71. %% run train method
  72. myGPHIKRegression.train( sparse(myData), myValues );
  73. %% evaluate model on test data
  74. myDataTest = 0:0.01:1;
  75. % create l1-normalized 'histograms'
  76. myDataTest = cat(1, myDataTest, 1-myDataTest)';
  77. scores = zeros(size(myDataTest,1),1);
  78. uncertainties = zeros(size(myDataTest,1),1);
  79. for i=1:size(myDataTest,1)
  80. example = sparse(myDataTest(i,:));
  81. [ scores(i), uncertainties(i)] = myGPHIKRegression.estimate( example );
  82. end
  83. %% plot results
  84. % create figure and set title
  85. classificationFig = figure;
  86. set ( classificationFig, 'name', 'Regression with GPHIK');
  87. hold on;
  88. %#initialize x array
  89. x=0:0.01:1;
  90. %#create first curve
  91. uncLower=scores-uncertainties;
  92. %#create second curve
  93. uncUpper=scores+uncertainties;
  94. %#create polygon-like x values for plotting
  95. X=[x,fliplr(x)];
  96. %# concatenate y-values accordingly
  97. Y=[uncLower',fliplr(uncUpper')];
  98. %#plot filled area for predictive variance ( aka regression uncertainty )
  99. fill(X,Y,'y');
  100. % plot mean values
  101. plot ( x,scores, ...
  102. 'LineStyle', '--', ...
  103. 'LineWidth', 2, ...
  104. 'Color', 'r', ...
  105. 'Marker','none', ...
  106. 'MarkerSize',1, ...
  107. 'MarkerEdgeColor','r', ...
  108. 'MarkerFaceColor',[0.5,0.5,0.5] ...
  109. );
  110. % plot training data
  111. plot ( myData(:,1), myValues, ...
  112. 'LineStyle', 'none', ...
  113. 'LineWidth', 3, ...
  114. 'Marker','o', ...
  115. 'MarkerSize',6, ...
  116. 'MarkerEdgeColor','b', ...
  117. 'MarkerFaceColor',[0.5,0.5,0.5] ...
  118. );
  119. xlabel('1st Input dimension');
  120. ylabel('Regression score');
  121. i_fontSizeAxis = 16;
  122. set(get(gca,'XLabel'), 'FontSize', i_fontSizeAxis);
  123. set(get(gca,'YLabel'), 'FontSize', i_fontSizeAxis);
  124. %% clean up and delete object
  125. myGPHIKRegression.delete();
  126. clear ( 'myGPHIKRegression' );