diff --git a/likelihood/exercises/mlestd.m b/likelihood/exercises/mlestd.m index f28d39e..8c61e4b 100644 --- a/likelihood/exercises/mlestd.m +++ b/likelihood/exercises/mlestd.m @@ -3,10 +3,11 @@ sigma =2.0; ns = [50, 1000]; for k = 1:length(ns) n = ns(k); + fprintf('\nn=%d\n', n); % draw random numbers: x = randn(n,1)*sigma+mu; - fprintf(' mean of the data is %.2f\n', mean(x)) - fprintf('standard deviation of the data is %.2f\n', std(x)) + fprintf(' mean of the data is %.2f\n', mean(x)) + fprintf(' standard deviation of the data is %.2f\n', std(x)) % standard deviation as parameter: psigs = 1.0:0.01:3.0; @@ -17,8 +18,14 @@ for k = 1:length(ns) p = exp(-0.5*((x-mu)/psig).^2.0)/sqrt(2.0*pi)/psig; lms(:,i) = p; end - lm = prod(lms, 1); % likelihood + lm = prod(lms, 1); % likelihood loglm = sum(log(lms), 1); % log likelihood + maxlm = psigs(lm==max(lm)); + if length(maxlm) > 1 + maxlm = maxlm(1); + end + fprintf(' likelihood: standard deviation of the data is %.2f\n', maxlm) + fprintf(' log-likelihood: standard deviation of the data is %.2f\n', psigs(loglm==max(loglm))) % plot likelihood of standard deviation: subplot(2, 2, 2*k-1); diff --git a/likelihood/exercises/mlestd.pdf b/likelihood/exercises/mlestd.pdf index 5246eda..4732ba4 100644 Binary files a/likelihood/exercises/mlestd.pdf and b/likelihood/exercises/mlestd.pdf differ