Few updates on todays lecture

This commit is contained in:
Jan Benda 2015-10-19 18:53:52 +02:00
parent b5084b78f4
commit 1e3b02b9a1
6 changed files with 44 additions and 30 deletions

View File

@ -1,6 +1,6 @@
x = randn( 100, 1 );
bins1 = -4:2:4;
bins2 = -4:0.5:4;
x = randn( 100, 1 ); % generate some data
bins1 = -4:2:4; % large bins
bins2 = -4:0.5:4; % small bins
subplot( 1, 2, 1 );
hold on;
hist( x, bins1 );
@ -10,6 +10,7 @@ ylabel('Frequeny')
hold off;
subplot( 1, 2, 2 );
hold on;
% normalize to the rigtht bin size:
hist( x, bins1, 1.0/(bins1(2)-bins1(1)) );
hist( x, bins2, 1.0/(bins2(2)-bins2(1)) );
xlabel('x')

View File

@ -1,22 +1,30 @@
% plot Gaussian pdf:
dx=0.1
dx=0.1;
x = [-4.0:dx:4.0];
p = exp(-0.5*x.^2)/sqrt(2.0*pi);
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:
x1=1.0
x2=2.0
P = sum(p((x>=x1)&(x<x2)))*dx
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) ] );
% draw random numbers:
r = randn( 10000, 1 );
hist(r,x,1.0/dx)
%r = randn( 10000, 1 );
%hist(r,x,1.0/dx)
% 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) ] );

View File

@ -1,13 +1,13 @@
function m = mymedian( x )
% returns the median of the vector x
xs = sort( x );
if ( length( xs ) == 0 )
if ( length( xs ) == 0 ) % empty input vector
m = NaN;
elseif ( rem( length( xs ), 2 ) == 0 )
elseif ( rem( length( xs ), 2 ) == 0 ) % even number of data values
index = length( xs )/2;
m = (xs( index ) + xs( index+1 ))/2;
else
index = (length( xs ) + 1)/2;
m = (xs( index ) + xs( index+1 ))/2; % average the two central elements
else % odd number of data values
index = (length( xs ) + 1)/2; % take the middle element
m = xs( index );
end
end

View File

@ -1,13 +1,14 @@
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 );
if ( length( xs ) == 0 )
if ( length( xs ) == 0 ) % no data
q = [];
elseif ( rem( length( xs ), 2 ) == 0 )
elseif ( rem( length( xs ), 2 ) == 0 ) % even number of data
index = length( xs )/2;
m = (xs( index ) + xs( index+1 ))/2;
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];
else
else % odd number of data
index = (length( xs ) + 1)/2;
m = xs( index );
q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ];

View File

@ -1,11 +1,16 @@
TEXFILES=$(wildcard *.tex)
PDFFILES=$(TEXFILES:.tex=.pdf)
PYFILES=$(wildcard *.py)
PYPDFFILES=$(PYFILES:.py=.pdf)
pdf : $(PDFFILES)
pdf : $(PDFFILES) $(PYPDFFILES)
$(PDFFILES) : %.pdf : %.tex
pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true
$(PYPDFFILES) : %.pdf : %.py
python $<
clean :
rm -f *~ $(TEXFILES:.tex=.aux) $(TEXFILES:.tex=.log) $(TEXFILES:.tex=.out) $(TEXFILES:.tex=.nav) $(TEXFILES:.tex=.snm) $(TEXFILES:.tex=.toc) $(TEXFILES:.tex=.vrb)

View File

@ -154,7 +154,7 @@
below. In particular the script should test data vectors of
different length.} {Schreibe ein Skript, das testet ob die
\code{mymedian} Funktion wirklich die Zahl zur\"uckgibt, \"uber
der genausoviele Datenwerte liegen wie darunter. Das Skript sollte
der genauso viele Datenwerte liegen wie darunter. Das Skript sollte
insbesondere verschieden lange Datenvektoren testen.}
\end{exercise}
@ -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 \]
und das normierte Histogramm hat die H\"ohe
\[ 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.
$p(x_i)$ kann keine Wahrscheinlichkeit sein, da $p(x_i)$ nun eine
@ -258,14 +258,14 @@ spricht von einer Wahrscheinlichkeitsdichte.
\caption{\label{pdfprobabilitiesfig} Wahrscheinlichkeiten bei
einer Wahrscheinlichkeitsdichtefunktion.}
\end{figure}
\begin{exercise}
\begin{exercise}[gaussianpdf.m]
\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?}
\[ 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}
\[ \int_{-\infty}^{+\infty} p(x) \, dx \; ?\]
\[ \int\limits_{-\infty}^{+\infty} p(x) \, dx \; ?\]
\tr{Why?}{Warum?}
\end{exercise}
@ -392,7 +392,6 @@ spricht von einer Wahrscheinlichkeitsdichte.
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Statistics}
What is "a statistic"? % dt. Sch\"atzfunktion