Few updates on todays lecture
This commit is contained in:
parent
b5084b78f4
commit
1e3b02b9a1
@ -1,6 +1,6 @@
|
|||||||
x = randn( 100, 1 );
|
x = randn( 100, 1 ); % generate some data
|
||||||
bins1 = -4:2:4;
|
bins1 = -4:2:4; % large bins
|
||||||
bins2 = -4:0.5:4;
|
bins2 = -4:0.5:4; % small bins
|
||||||
subplot( 1, 2, 1 );
|
subplot( 1, 2, 1 );
|
||||||
hold on;
|
hold on;
|
||||||
hist( x, bins1 );
|
hist( x, bins1 );
|
||||||
@ -10,6 +10,7 @@ ylabel('Frequeny')
|
|||||||
hold off;
|
hold off;
|
||||||
subplot( 1, 2, 2 );
|
subplot( 1, 2, 2 );
|
||||||
hold on;
|
hold on;
|
||||||
|
% normalize to the rigtht bin size:
|
||||||
hist( x, bins1, 1.0/(bins1(2)-bins1(1)) );
|
hist( x, bins1, 1.0/(bins1(2)-bins1(1)) );
|
||||||
hist( x, bins2, 1.0/(bins2(2)-bins2(1)) );
|
hist( x, bins2, 1.0/(bins2(2)-bins2(1)) );
|
||||||
xlabel('x')
|
xlabel('x')
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
% plot Gaussian pdf:
|
% plot Gaussian pdf:
|
||||||
dx=0.1
|
dx=0.1;
|
||||||
x = [-4.0:dx:4.0];
|
x = [-4.0:dx:4.0];
|
||||||
p = exp(-0.5*x.^2)/sqrt(2.0*pi);
|
p = exp(-0.5*x.^2)/sqrt(2.0*pi);
|
||||||
hold on
|
hold on
|
||||||
plot(x, p, 'linewidth', 10)
|
plot(x, p, 'linewidth', 10)
|
||||||
|
% show area of integral:
|
||||||
|
area(x((x>=x1)&(x<=x2)), p((x>=x1)&(x<=x2)), 'FaceColor', 'r' )
|
||||||
|
hold off
|
||||||
|
|
||||||
% compute integral between x1 and x2:
|
% compute integral between x1 and x2:
|
||||||
x1=1.0
|
x1=1.0;
|
||||||
x2=2.0
|
x2=2.0;
|
||||||
P = sum(p((x>=x1)&(x<x2)))*dx
|
P = sum(p((x>=x1)&(x<x2)))*dx;
|
||||||
|
disp( [ 'The integral between ', num2str(x1, 1), ' and ', num2str(x2, 1), ' is ', num2str(P, 3) ] );
|
||||||
|
|
||||||
% draw random numbers:
|
% draw random numbers:
|
||||||
r = randn( 10000, 1 );
|
%r = randn( 10000, 1 );
|
||||||
hist(r,x,1.0/dx)
|
%hist(r,x,1.0/dx)
|
||||||
|
|
||||||
% check P:
|
% check P:
|
||||||
Pr = sum((r>=x1)&(r<x2))/length(r)
|
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) ] );
|
||||||
|
|
||||||
hold off
|
% 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) ] );
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
function m = mymedian( x )
|
function m = mymedian( x )
|
||||||
% returns the median of the vector x
|
% returns the median of the vector x
|
||||||
xs = sort( x );
|
xs = sort( x );
|
||||||
if ( length( xs ) == 0 )
|
if ( length( xs ) == 0 ) % empty input vector
|
||||||
m = NaN;
|
m = NaN;
|
||||||
elseif ( rem( length( xs ), 2 ) == 0 )
|
elseif ( rem( length( xs ), 2 ) == 0 ) % even number of data values
|
||||||
index = length( xs )/2;
|
index = length( xs )/2;
|
||||||
m = (xs( index ) + xs( index+1 ))/2;
|
m = (xs( index ) + xs( index+1 ))/2; % average the two central elements
|
||||||
else
|
else % odd number of data values
|
||||||
index = (length( xs ) + 1)/2;
|
index = (length( xs ) + 1)/2; % take the middle element
|
||||||
m = xs( index );
|
m = xs( index );
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
function q = quartiles( x )
|
function q = quartiles( x )
|
||||||
% returns a vector with the first, second, and third quartile of the vector x
|
% returns a vector with the first, second, and third quartile
|
||||||
|
% of the vector x
|
||||||
xs = sort( x );
|
xs = sort( x );
|
||||||
if ( length( xs ) == 0 )
|
if ( length( xs ) == 0 ) % no data
|
||||||
q = [];
|
q = [];
|
||||||
elseif ( rem( length( xs ), 2 ) == 0 )
|
elseif ( rem( length( xs ), 2 ) == 0 ) % even number of data
|
||||||
index = length( xs )/2;
|
index = length( xs )/2;
|
||||||
m = (xs( index ) + xs( index+1 ))/2;
|
m = (xs( index ) + xs( index+1 ))/2;
|
||||||
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];
|
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];
|
||||||
else
|
else % odd number of data
|
||||||
index = (length( xs ) + 1)/2;
|
index = (length( xs ) + 1)/2;
|
||||||
m = xs( index );
|
m = xs( index );
|
||||||
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];
|
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
TEXFILES=$(wildcard *.tex)
|
TEXFILES=$(wildcard *.tex)
|
||||||
PDFFILES=$(TEXFILES:.tex=.pdf)
|
PDFFILES=$(TEXFILES:.tex=.pdf)
|
||||||
|
PYFILES=$(wildcard *.py)
|
||||||
|
PYPDFFILES=$(PYFILES:.py=.pdf)
|
||||||
|
|
||||||
pdf : $(PDFFILES)
|
pdf : $(PDFFILES) $(PYPDFFILES)
|
||||||
|
|
||||||
$(PDFFILES) : %.pdf : %.tex
|
$(PDFFILES) : %.pdf : %.tex
|
||||||
pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true
|
pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true
|
||||||
|
|
||||||
|
$(PYPDFFILES) : %.pdf : %.py
|
||||||
|
python $<
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -f *~ $(TEXFILES:.tex=.aux) $(TEXFILES:.tex=.log) $(TEXFILES:.tex=.out) $(TEXFILES:.tex=.nav) $(TEXFILES:.tex=.snm) $(TEXFILES:.tex=.toc) $(TEXFILES:.tex=.vrb)
|
rm -f *~ $(TEXFILES:.tex=.aux) $(TEXFILES:.tex=.log) $(TEXFILES:.tex=.out) $(TEXFILES:.tex=.nav) $(TEXFILES:.tex=.snm) $(TEXFILES:.tex=.toc) $(TEXFILES:.tex=.vrb)
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ $A$ des Histogramms ist also
|
|||||||
\[ A = \sum_{i=1}^N ( n_i \cdot \Delta x ) = \Delta x \sum_{i=1}^N n_i \]
|
\[ A = \sum_{i=1}^N ( n_i \cdot \Delta x ) = \Delta x \sum_{i=1}^N n_i \]
|
||||||
und das normierte Histogramm hat die H\"ohe
|
und das normierte Histogramm hat die H\"ohe
|
||||||
\[ p(x_i) = \frac{n_i}{\Delta x \sum_{i=1}^N n_i} \]
|
\[ p(x_i) = \frac{n_i}{\Delta x \sum_{i=1}^N n_i} \]
|
||||||
Es muss also nicht nur durch die Summe, sondern auch durch die Breite der Klassen $\Delta x$
|
Es muss also nicht nur durch die Summe, sondern auch durch die Breite $\Delta x$ der Klassen
|
||||||
geteilt werden.
|
geteilt werden.
|
||||||
|
|
||||||
$p(x_i)$ kann keine Wahrscheinlichkeit sein, da $p(x_i)$ nun eine
|
$p(x_i)$ kann keine Wahrscheinlichkeit sein, da $p(x_i)$ nun eine
|
||||||
@ -259,13 +259,13 @@ spricht von einer Wahrscheinlichkeitsdichte.
|
|||||||
einer Wahrscheinlichkeitsdichtefunktion.}
|
einer Wahrscheinlichkeitsdichtefunktion.}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
\begin{exercise}
|
\begin{exercise}[gaussianpdf.m]
|
||||||
\tr{Plot the Gaussian probability density}{Plotte die Gauss'sche Wahrscheinlichkeitsdichte }
|
\tr{Plot the Gaussian probability density}{Plotte die Gauss'sche Wahrscheinlichkeitsdichte }
|
||||||
\[ p_g(x) = 1/\sqrt{2\pi\sigma^2}e^{-\frac{(x-\mu)^2}{2\sigma^2}}\]
|
\[ p_g(x) = \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}\]
|
||||||
\tr{What does it mean?}{Was bedeutet die folgende Wahrscheinlichkeit?}
|
\tr{What does it mean?}{Was bedeutet die folgende Wahrscheinlichkeit?}
|
||||||
\[ P(x_1 < x < x2) = \int_{x_1}^{x_2} p(x) \, dx \]
|
\[ P(x_1 < x < x2) = \int\limits_{x_1}^{x_2} p(x) \, dx \]
|
||||||
\tr{How large is}{Wie gro{\ss} ist}
|
\tr{How large is}{Wie gro{\ss} ist}
|
||||||
\[ \int_{-\infty}^{+\infty} p(x) \, dx \; ?\]
|
\[ \int\limits_{-\infty}^{+\infty} p(x) \, dx \; ?\]
|
||||||
\tr{Why?}{Warum?}
|
\tr{Why?}{Warum?}
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
@ -392,7 +392,6 @@ spricht von einer Wahrscheinlichkeitsdichte.
|
|||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\subsection{Statistics}
|
\subsection{Statistics}
|
||||||
What is "a statistic"? % dt. Sch\"atzfunktion
|
What is "a statistic"? % dt. Sch\"atzfunktion
|
||||||
|
Reference in New Issue
Block a user