[simulations] added uniform distribution
This commit is contained in:
parent
a50cc4ff7b
commit
d50b0be404
@ -1,8 +1,8 @@
|
|||||||
n = 10000;
|
n = 200; % number of time intervals
|
||||||
lambda = 50.0; % event rate
|
rate = 50.0; % event rate
|
||||||
t = exprnd(1.0/lambda, n, 1); % exponentially distributed random numbers
|
t = exprnd(1.0/rate, n, 1); % exponentially distributed intervals
|
||||||
m = mean(t); % mean time interval
|
m = mean(t); % mean time interval
|
||||||
s = std(t); % corresponding standard deviation
|
s = std(t); % corresponding standard deviation
|
||||||
fprintf('Generated n=%d exponentially distributed random time intervals\n', n);
|
fprintf('Generated n=%d random time intervals with rate=%.0fHz:\n', n, rate);
|
||||||
fprintf(' with rate=%.0fHz (-> mean=%.3fs, std=%.3fs)\n', lambda, 1.0/lambda, 1.0/lambda);
|
fprintf(' Expected mean interval=%.3fs, std=%.3fs\n', 1.0/rate, 1.0/rate);
|
||||||
fprintf('Measured mean=%.3fs, std=%.3fs\n', m, s);
|
fprintf(' Measured mean interval=%.3fs, std=%.3fs\n', m, s);
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
Generated n=10000 exponentially distributed random time intervals
|
Generated n=200 random time intervals with rate=50Hz:
|
||||||
with rate=50Hz (-> mean=0.020s, std=0.020s)
|
Expected mean interval=0.020s, std=0.020s
|
||||||
Measured mean=0.020s, std=0.020s
|
Measured mean interval=0.020s, std=0.019s
|
||||||
|
16
simulations/code/unirandom.m
Normal file
16
simulations/code/unirandom.m
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
n = 10000; % number of action potentials
|
||||||
|
T = 100.0; % total time interval
|
||||||
|
spikes = sort(T*rand(n, 1)); % sorted times of action potentials
|
||||||
|
isis = diff(spikes); % interspike intervals
|
||||||
|
rate = n/T; % firing rate
|
||||||
|
misi = mean(isis); % mean interspike interval
|
||||||
|
sisi = std(isis); % and standard deviation
|
||||||
|
fprintf('firing rate = %.1fHz\n', rate);
|
||||||
|
fprintf(' mean ISI = %.1fms\n', 1000.0*misi); % inverse of rate
|
||||||
|
fprintf(' std ISI = %.1fms\n', 1000.0*sisi); % same as mean
|
||||||
|
hist(1000.0*isis, 50); % exponential distribution
|
||||||
|
xlabel('ISI [ms]');
|
||||||
|
ylabel('count');
|
||||||
|
|
||||||
|
|
||||||
|
|
3
simulations/code/unirandom.out
Normal file
3
simulations/code/unirandom.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
firing rate = 100.0Hz
|
||||||
|
mean ISI = 10.0ms
|
||||||
|
std ISI = 10.0ms
|
@ -79,24 +79,28 @@ script is run.
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\section{Univariate data}
|
\section{Univariate data}
|
||||||
The most basic type of simulation is to draw random numbers from a
|
A basic type of stochastic simulations is to draw random numbers from
|
||||||
given distribution like, for example, the normal distribution. This
|
a given distribution like, for example, the normal distribution. This
|
||||||
simulates repeated measurements of some quantity (e.g., weight of
|
simulates repeated measurements of some quantity (weight of tigers,
|
||||||
tigers or firing rate of neurons). Doing so we must specify from which
|
firing rate of neurons). Doing so we must specify from which
|
||||||
probability distribution the data should originate from and what are
|
probability distribution the data should originate from and what are
|
||||||
the parameters of that distribution (mean, standard deviation, shape
|
the parameters of that distribution (mean, standard deviation, shape
|
||||||
parameters, ...). How to illustrate and quantify univariate data, no
|
parameters). How to illustrate and quantify univariate data, no matter
|
||||||
matter whether they have been actually measured or whether they have
|
whether they have been actually measured or whether they have been
|
||||||
been simulated as described in the following, is described in
|
simulated as described in the following, is described in
|
||||||
chapter~\ref{descriptivestatisticschapter}.
|
chapter~\ref{descriptivestatisticschapter}.
|
||||||
|
|
||||||
\subsection{Normally distributed data}
|
\subsection{Normally distributed data}
|
||||||
For drawing numbers $x_i$ from a normal distribution we use the
|
For drawing numbers from a normal distribution
|
||||||
\code{randn()} function. This function returns normally distributed
|
\begin{equation}
|
||||||
numbers $\xi_i$ with zero mean and unit standard deviation. For
|
p_{norm}(x) = \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}
|
||||||
changing the standard deviation we need to multiply the returned data
|
\end{equation}
|
||||||
values with the required standard deviation $\sigma$. For changing the
|
with zero mean and unit standard deviation we use the \code{randn()}
|
||||||
mean we just add the desired mean $\mu$ to the random numbers:
|
function. This function returns normally distributed numbers $\xi_i$
|
||||||
|
with zero mean and unit standard deviation. For changing the standard
|
||||||
|
deviation we need to multiply the returned data values with the
|
||||||
|
required standard deviation $\sigma$. For changing the mean we just
|
||||||
|
add the desired mean $\mu$ to the random numbers:
|
||||||
\begin{equation}
|
\begin{equation}
|
||||||
x_i = \sigma \xi_i + \mu
|
x_i = \sigma \xi_i + \mu
|
||||||
\end{equation}
|
\end{equation}
|
||||||
@ -144,24 +148,44 @@ only defined for positive time intervals:
|
|||||||
\label{expdistribution}
|
\label{expdistribution}
|
||||||
p_{exp}(t) = \lambda e^{-\lambda t} \; , \quad t \ge 0, \; \lambda > 0
|
p_{exp}(t) = \lambda e^{-\lambda t} \; , \quad t \ge 0, \; \lambda > 0
|
||||||
\end{equation}
|
\end{equation}
|
||||||
The exponential distribution is parameterized by a single rate
|
A single rate parameter $\lambda$ measured in Hertz parameterizes the
|
||||||
parameter $\lambda$ measured in Hertz. It defines how often per time
|
exponential distribution. It defines how often per time unit the event
|
||||||
unit the event happens. Both the mean interval between the events and
|
happens. Both the mean interval between the events and the
|
||||||
the corresponding standard deviation equal the inverse rate.
|
corresponding standard deviation equal the inverse rate.
|
||||||
|
|
||||||
\begin{exercise}{exprandom.m}{exprandom.out}
|
\begin{exercise}{exprandom.m}{exprandom.out}
|
||||||
Draw $n=10\,000$ random time intervals from an exponential
|
Draw $n=200$ random time intervals from an exponential distribution
|
||||||
distribution with rate $\lambda=50$\,Hz. Calculate the mean and the
|
with rate $\lambda=50$\,Hz. Calculate the mean and the standard
|
||||||
standard deviation of the random numbers and compare them with the
|
deviation of the random numbers and compare them with the expected
|
||||||
expected values.
|
values.
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
The gamma distribution (\code{gamrnd()}) phenomenologically describes
|
The \code{rand()} function returns uniformly distributed random
|
||||||
various types of interspike interval dsitributions
|
numbers between zero and one
|
||||||
(chapter~\ref{pointprocesseschapter}). scale and shape. exercise.
|
\begin{equation}
|
||||||
|
p_{uni}(x) = \left\{\begin{array}{rcl} 1 & ; & 0 \le x < 1 \\
|
||||||
|
0 & ; & \text{else} \end{array}\right.
|
||||||
|
\end{equation}
|
||||||
|
For random numbers $x_i$ uniformly distributed between $x_{\rm min}$
|
||||||
|
and $x_{\rm max}$ we multiply by the desired range $x_{\rm max} -
|
||||||
|
x_{\rm min}$ and add $x_{\rm min}$ to the numbers $u_i$ returned by
|
||||||
|
\code{rand()}:
|
||||||
|
\begin{equation}
|
||||||
|
x_i = (x_{\rm max} - x_{\rm min}) u_i + x_{\rm min}
|
||||||
|
\end{equation}
|
||||||
|
|
||||||
|
\begin{exercise}{unirandom.m}{unirandom.out}
|
||||||
|
Simulate the times of $n=10\,000$ action potentials occuring
|
||||||
|
randomly within a time interval of 100\,s using the \code{rand()}
|
||||||
|
function. Sort the times using \code{sort()}, compute the time
|
||||||
|
intervals between the action potentials (interspike intervals, ISIs)
|
||||||
|
using the \code{diff()} function, plot a histogram of the interspike
|
||||||
|
intervals in milliseconds, and compute the mean and standard
|
||||||
|
deviation of the interspike intervals, also in milliseconds. Compare
|
||||||
|
the mean ISI with the firing rate (number of action potentials per
|
||||||
|
time).
|
||||||
|
\end{exercise}
|
||||||
|
|
||||||
\code{rand()} between xmin
|
|
||||||
and xmax.
|
|
||||||
|
|
||||||
\subsection{Simulating probabilities}
|
\subsection{Simulating probabilities}
|
||||||
Simulating events that happen with some probability $P$ is also
|
Simulating events that happen with some probability $P$ is also
|
||||||
@ -177,6 +201,18 @@ the event does not occur.
|
|||||||
probability of $P=0.6$. Count the number of heads.
|
probability of $P=0.6$. Count the number of heads.
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
|
Random walk! Have a figure with a few 1D random walks and the
|
||||||
|
increasing standard deviation as a sheded area behind.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
The gamma distribution (\code{gamrnd()}) phenomenologically describes
|
||||||
|
various types of interspike interval dsitributions
|
||||||
|
(chapter~\ref{pointprocesseschapter}). scale and shape. exercise.
|
||||||
|
|
||||||
\subsection{Random integers}
|
\subsection{Random integers}
|
||||||
\code{randi()}
|
\code{randi()}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user