Attachment 'sheet05_01.m'

Download

   1 function sheet05_01
   2 % Comparing Bayesian estimation versus maximum-likelihood estimation.
   3 
   4 % generate some Bernoulli distributed data
   5 N = 300;
   6 p = 0.3;
   7 X = rand(1, N) < p;
   8 
   9 % estimate p using the ml estimator
  10 ml = zeros(1, N);
  11 for I = 1:N
  12   ml(I) = ml_estimate(X(1:I));
  13 end
  14 
  15 % estimate p using a "non-informative"
  16 [B11A, B11B] = beta_estimate(1, 1, X);
  17 [B7030A, B7030B] = beta_estimate(70, 30, X);
  18 [B300700A, B300700B] = beta_estimate(300, 700, X);
  19 
  20 B11A
  21 
  22 plot(1:N, ml, 'g');
  23 hold on;
  24 plot_beta_estimates(B11A, B11B, 'r');
  25 plot_beta_estimates(B7030A, B7030B, 'k');
  26 plot_beta_estimates(B300700A, B300700B, 'b');
  27 hold off;
  28 
  29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  30 % only make changes blow
  31 
  32 % 1. Compute the maximum-likelihood estimate for Bernoulli random
  33 % variables from the samples contained in X
  34 function p = ml_estimate(X)
  35 % ...
  36 
  37 % Compute the continuous updates of the beta distribution prior
  38 % parameters for X.
  39 function [A, B] = beta_estimate(a, b, X)
  40 N = length(X);
  41 A = zeros(1, N);
  42 B = zeros(1, N);
  43 for I = 1:N
  44   [a, b] = beta_update(a, b, X(I));
  45   A(I) = a;
  46   B(I) = b;
  47 end
  48 
  49 % 2. Update the a and b parameters of the beta distribution prior
  50 % for a single X.
  51 function [a, b] = beta_update(a, b, X)
  52 % ...
  53 
  54 % 3. Compute the mean and variance of the beta distribution for
  55 % the given vector of parameters
  56 function [M, V] = beta_stats(A, B)
  57 % ...
  58 
  59 % Plot mean and two times standard deviation.
  60 function plot_beta_estimates(A, B, mark)
  61 N = length(A);
  62 [M, V] = beta_stats(A, B);
  63 plot(1:N, M, [mark, '-'], ...
  64      1:N, M + 2*sqrt(V), [mark, ':'], ...
  65      1:N, M - 2*sqrt(V), [mark, ':']);

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-03-12 14:03:18, 318.2 KB) [[attachment:BayesianDecisionTheory.pdf]]
  • [get | view] (2009-03-12 14:03:18, 247.3 KB) [[attachment:crossvalidation.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1740.8 KB) [[attachment:mlintro.pdf]]
  • [get | view] (2009-03-12 14:03:18, 665.3 KB) [[attachment:probtheo.pdf]]
  • [get | view] (2009-03-12 14:03:18, 52.7 KB) [[attachment:sheet01.pdf]]
  • [get | view] (2009-03-12 14:03:18, 61.7 KB) [[attachment:sheet02.pdf]]
  • [get | view] (2009-03-12 14:03:18, 65.8 KB) [[attachment:sheet03.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.1 KB) [[attachment:sheet04.m]]
  • [get | view] (2009-03-12 14:03:18, 80.3 KB) [[attachment:sheet04.pdf]]
  • [get | view] (2009-03-12 14:03:18, 106.7 KB) [[attachment:sheet05.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet05_01.m]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet05_02.m]]
  • [get | view] (2009-03-12 14:03:18, 0.8 KB) [[attachment:sheet06.m]]
  • [get | view] (2009-03-12 14:03:18, 93.2 KB) [[attachment:sheet06.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.4 KB) [[attachment:sheet07.m]]
  • [get | view] (2009-03-12 14:03:18, 100.6 KB) [[attachment:sheet07.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.7 KB) [[attachment:sheet08.m]]
  • [get | view] (2009-03-12 14:03:18, 85.4 KB) [[attachment:sheet08.pdf]]
  • [get | view] (2009-03-12 14:03:18, 45.2 KB) [[attachment:sheet09.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.5 KB) [[attachment:sheet10.m]]
  • [get | view] (2009-03-12 14:03:18, 59.4 KB) [[attachment:sheet10.pdf]]
  • [get | view] (2009-03-12 14:03:18, 3.0 KB) [[attachment:sheet11.m]]
  • [get | view] (2009-03-12 14:03:18, 68.6 KB) [[attachment:sheet11.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.7 KB) [[attachment:sheet12.m]]
  • [get | view] (2009-03-12 14:03:18, 62.6 KB) [[attachment:sheet12.pdf]]
  • [get | view] (2009-03-12 14:03:18, 2.4 KB) [[attachment:sheet12_data.m]]
  • [get | view] (2009-03-12 14:03:18, 63.1 KB) [[attachment:sheet13.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1.6 KB) [[attachment:sheet14.m]]
  • [get | view] (2009-03-12 14:03:18, 73.7 KB) [[attachment:sheet14.pdf]]
  • [get | view] (2009-03-12 14:03:18, 4.8 KB) [[attachment:sheet14_data.m]]
  • [get | view] (2009-03-12 14:03:18, 120.2 KB) [[attachment:summary.pdf]]
  • [get | view] (2009-03-12 14:03:18, 1505.5 KB) [[attachment:vl_ica_tub-08.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.