Updated maximum likelihood chapter.

Common latex header file.
This commit is contained in:
2015-10-31 20:45:32 +01:00
parent 91f1f3663e
commit 40a5343fa8
20 changed files with 429 additions and 1452 deletions

View File

@@ -3,7 +3,7 @@
for i = 1:140 % loop over different length
for k = 1:10 % try several times
a = randn( i, 1 ); % generate some data
m = mymedian( a ) % compute median
m = mymedian( a ); % compute median
if length( a(a>m) ) ~= length( a(a<m) ) % check
disp( 'error!' )
end

View File

@@ -1,24 +1,27 @@
% dependence of histogram on number of rolls:
nrolls = [ 20, 100, 1000 ];
nrolls = [20, 100, 1000];
for i = [1:length(nrolls)]
d = rollthedie( nrolls(i) );
d = rollthedie(nrolls(i));
% plain hist:
%hist( d )
%hist(d)
% check bin counts of plain hist:
% h = hist( d )
% h = hist(d)
% force 6 bins:
%hist( d, 6 )
%hist(d, 6)
% set the right bin centers:
%bins = 1:6;
%hist( d, bins )
bins = 1:6;
%hist(d, bins)
% normalize histogram and compare to expectation:
plot([0 7], [1/6 1/6], '-r', 'linewidth', 10)
[h, b] = hist(d, bins);
h = h/sum(h) % normalization
hold on
plot( [0 7], [1/6 1/6], '-r', 'linewidth', 10 )
hist( d, bins, 1.0, 'facecolor', 'b' )
bar(b, h, 'facecolor', 'b')
hold off
pause
title(sprintf('N=%d', length(d)))
pause( 2.0 )
end

View File

@@ -7,9 +7,9 @@ bins2 = -4:db2:4; % small bins
[h2,b2] = hist(x,bins2);
subplot( 1, 2, 1 );
bar(b1,hn1)
bar(b1,h1)
hold on
bar(b2,hn2, 'facecolor', 'r' )
bar(b2,h2, 'facecolor', 'r' )
xlabel('x')
ylabel('Frequency')
hold off

View File

@@ -1,30 +1,27 @@
% plot Gaussian pdf:
dx=0.1;
dx=0.01;
x = [-4.0:dx:4.0];
p = exp(-0.5*x.^2)/sqrt(2.0*pi);
plot(x, p, 'linewidth', 4)
hold on
plot(x, p, 'linewidth', 10)
% show area of integral:
x1=1.0;
x2=2.0;
area(x((x>=x1)&(x<=x2)), p((x>=x1)&(x<=x2)), 'FaceColor', 'r' )
hold off
% compute integral between x1 and x2:
x1=1.0;
x2=2.0;
P = sum(p((x>=x1)&(x<x2)))*dx;
disp( [ 'The integral between ', num2str(x1, 1), ' and ', num2str(x2, 1), ' is ', num2str(P, 3) ] );
fprintf( 'The integral between %.2g and %.2g is %.3g\n', x1, x2, P );
% draw random numbers:
%r = randn( 10000, 1 );
%hist(r,x,1.0/dx)
r = randn( 10000, 1 );
% check P:
Pr = sum((r>=x1)&(r<x2))/length(r);
disp( [ 'The probability of getting a number between ', num2str(x1, 1), ' and ', num2str(x2, 1), ' is ', num2str(Pr, 3) ] );
fprintf( 'The probability of getting a number between %.2g and %.2g is %.3g\n', x1, x2, Pr );
% infinite integral:
P = sum(p)*dx;
disp( [ 'The integral between -infinity and +infinity is ', num2str(P, 3) ] );
disp( [ 'I.e. the probability to get any number is ', num2str(P, 3) ] );
fprintf( 'The integral between -infinity and +infinity is %.3g\n', P );
fprintf( 'I.e. the probability to get any number is %.3g\n', P );