\documentclass[12pt,a4paper,pdftex]{article}
\usepackage[left=25mm, right=25mm, top=20mm, bottom=25mm]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{natbib}
\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=false,citecolor=blue]{hyperref}

\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
%\usepackage{float}
\usepackage{floatrow}
\usepackage{wrapfig}

\usepackage{listings} % für den code am Ende



\newcommand{\todo}[1]{{\color{red}(TODO: #1)}}

\newcommand{\AptLepto}{{\textit{Apteronotus leptorhynchus \:}}}

\newcommand{\lepto}{{\textit{A. leptorhynchus}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ab hier beginnt der eigentliche Text:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Titelseite
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{titlepage}
		\begin{center}
		{\Huge Modeling the Heterogeneity of Electrosensory Afferents in Electric Fish \par}
		\vspace{0.75cm}
		{\Large Masterthesis \par}
		\vspace{0.25cm}
		{der Mathematisch-Naturwissenschaftlichen Fakultät \par} {der Eberhard Karls Universität Tübingen \par}
		\vspace{0.75cm}
		{Erstkorrektor: Prof.~Dr.~Philipp Berens\\
		Zweitkorrektor: Prof.~Dr.~Jan Benda \par}
		\vspace{0.25cm}
		{Lehrbereich für Neuroethologie}
		
		\vfill
		\large vorgelegt von \par
		\large Alexander Mathias Ott \par
		Abgabedatum: 21.09.2020
	\end{center}
\end{titlepage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Erklärung
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Eigenständigkeitserklärung}

\vspace{0.5cm}

Hiermit erkläre ich, dass ich die vorgelegte Arbeit selbstständig verfasst habe und keine anderen als die angegebenen Quellen und Hilfsmittel benutzt habe. 

\vspace{2mm}
\noindent
Außerdem erkläre ich, dass die eingereichte Arbeit weder vollständig noch in wesentlichen Teilen Gegenstand eines anderen Prüfungsverfahrens gewesen ist.






\vfill

\begin{tabular}{ll}
	$\overline{\text{Unterschrift}\hspace{6cm}}$ & $\overline{\text{Ort, Datum}\hspace{4cm}}$ \\
\end{tabular}
\newpage\newpage



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Inhalsverzeichnis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

{
 \hypersetup{linkcolor=black}
 \tableofcontents
}

\newpage

\section*{Not to forget: TODO}

\begin{itemize}

\item update the colors in all plots to be consistent.

\item make plot labels consistent (Units: in mV vs [mV])
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Zusammenfassung
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Zusammenfassung}
% Abstract in deutsch




\section{Abstract}
%Einleitung + Ergebnisse der Diskussion in kurz



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Einleitung
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}






%\begin{figure}[H]
%\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=0.49\textwidth}}]{figure}[\FBwidth]
%{\caption{\label{fig:p_unit_example} Example behavior of a p-unit with a high baseline firing rate. Baseline Firing: A 100\,ms voltage trace of the recording with spikes marked by the black lines. ISI-histogram: The histogram of the ISI with the x-axis in EOD periods, showing the phase locking of the firing. Serial Correlation: The serial correlation of the ISI showing a negative correlation for lags one and two. Step Response: The response of the p-unit to a step increase in EOD amplitude. In \todo{color} the averaged frequency over 10 trials and in \todo{color} smoothed with an running average with a window of 10\,ms. The p-unit strongly reacts to the onset of the stimulus but very quickly adapts to the new stimulus and then shows a steady state response. FI-Curve: The fi-curve visualizes the onset and steady-state response of the neuron for different step sizes (contrasts). In \todo{color} the detected onset responses and the fitted Boltzmann, in %\todo{color} the detected steady-state response and the linear fit.}}
%{\includegraphics[width=0.45\textwidth]{figures/p_unit_example.png}}
%\end{figure}


\begin{figure}[H]
{\caption{\label{fig:p_unit_example} Example behavior of a p-unit with a high baseline firing rate. Baseline Firing: A 100\,ms voltage trace of the recording with spikes marked by the black lines. ISI-histogram: The histogram of the ISI with the x-axis in EOD periods, showing the phase locking of the firing. Serial Correlation: The serial correlation of the ISI showing a negative correlation for lags one and two. Step Response: The response of the p-unit to a step increase in EOD amplitude. In \todo{color} the averaged frequency over 10 trials and in \todo{color} smoothed with an running average with a window of 10\,ms. The p-unit strongly reacts to the onset of the stimulus but very quickly adapts to the new stimulus and then shows a steady state response. FI-Curve: The fi-curve visualizes the onset and steady-state response of the neuron for different step sizes (contrasts). In \todo{color} the detected onset responses and the fitted Boltzmann, in \todo{color} the detected steady-state response and the linear fit.}}
{\includegraphics[width=0.9\textwidth]{figures/p_unit_example.png}}
\end{figure}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methoden
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Materials and Methods}

\todo{some transition from the introduction}

\subsection{Cell recordings}


%sampling: 100000.0 count: 20
%sampling: 20000.0 count: 54
%sampling: 40000.0 count: 1

% each fish only once in calculation (as determined with max one fish per day)
% # of fish = 32
% EOD-freq: min 601.09, mean 753.09, max 928.45, std 82.30
% Sizes: min 11.00, mean 15.78, max 25.00, std 3.48

The cell recordings for this master thesis were collected as part of other previous studies (\cite{walz2013Phd}, \citep{walz2014static})\todo{ref other studies} and the recording procedure is described there but will also be repeated below. The recordings of altogether 457 p-units were inspected. Of those 88 fulfilled basic necessary requirements: including a measurement of at least 30 seconds of baseline behavior and containing at least 7 different contrasts with each at least 7 trials for the f-I curve (see below \todo{ref fi-curve? }). After pre-analysis of those cells an additional 15 cells were excluded because of spike detection difficulties.

The 73 used cells came from 32 \AptLepto (brown ghost knifefish). The fish were between 11--25\,cm long (15.8 $\pm$ 3.5\,cm) and their electric organ discharge (EOD) frequencies ranged between 601 and 928\,Hz (753 $\pm$ 82\,Hz). The sex of the fish was not determined.

The in vivo intracellular recordings of P-unit electroreceptors were done in the lateral line nerve. The fish were anesthetized with MS-222 (100-130 mg/l; PharmaQ; Fordingbridge, UK) and the part of the skin covering the lateral line just behind the skull was removed, while the area was anesthetized with Lidocaine (2\%; bela-pharm; Vechta, Germany). The fish were immobilized for the recordings with Tubocurarine (Sigma-Aldrich; Steinheim, Germany, 25--50\,$\mu l$ of 5\,mg/ml solution) and placed in the experimental tank (47 $\times$ 42 $\times$ 12\,cm) filled with water from the fish's home tank with a conductivity of about 300$\mu$\,S/cm and the temperature was around 28°C. 
All experimental protocols were approved and complied with national and regional laws (files: no. 55.2-1-54-2531-135-09 and Regierungspräsidium Tübingen no. ZP 1/13 and no. ZP 1/16)
For the recordings a standard glass mircoelectrode (borosilicate; 1.5 mm outer diameter; GB150F-8P, Science Products, Hofheim, Germany) was used. They were pulled to a resistance of 50--100\,M$\Omega$ using Model P-97 from Sutter Instrument Co. (Novato, CA, USA) and filled with 1\,M KCl solution. The electrodes were controlled using microdrives (Luigs-Neumann; Ratingen, Germany) and the potentials recorded with the bridge mode of the SEC-05 amplifier (npi-electronics GmbH, Tamm, Germany) and lowpass filtered at 10 kHz.

During the recording spikes were detected online using the peak detection algorithm from \cite{todd1999identification}. It uses a dynamically adjusted threshold value above the previously detected trough. To detect spikes through changes in amplitude the threshold was set to 50\% of the amplitude of a detected spike while keeping the threshold above a minimum set to be higher than the noise level based on a histogram of all peak amplitudes. Trials with bad spike detection were removed from further analysis.
The fish's EOD was recorded using two vertical carbon rods (11\,cm long, 8\,mm diameter) positioned in front of the head and behind its tail. The signal was amplified 200 to 500 times and band-pass filtered (3 − 1500 Hz passband, DPA2-FX, npi-electronics, Tamm, Germany). The electrodes were placed on iso-potential lines of the stimulus field to reduce the interference of the stimulus in the recording. All signals were digitized using a data acquisition board (PCI-6229; National Instruments, Austin TX, USA) at a sampling rate of 20--100\,kHz (54 cells at 20\,kHz, 20 at 100\,kHz and 1 at 40\,kHz)

The recording and stimulation was done using the ephys, efield, and efish plugins of the software RELACS (\href{www.relacs.net}{www.relacs.net}). It allowed the online spike and EOD detection, pre-analysis and visualization and ran on a Debian computer.



\subsection{Stimulus Protocols}
% image of Baseline stimulus as baseline doesn't mean no stimulus here
% image of Fi curve stimulus sinusoidal step
% image of SAM stimulus

The stimuli used during the recordings were presented from two vertical carbon rods (30 cm long, 8 mm diameter) as stimulus electrodes. They were positioned at either side of the fish parallel to its longitudinal axis. The stimuli were computer generated, attenuated and isolated  (Attenuator: ATN-01M, Isolator: ISO-02V, npi-electronics, Tamm, Germany) and then send to the stimulus electrodes.
For this work two types of recordings were made with all cells: baseline recordings and amplitude step recordings for the frequency-Intensity curve (f-I curve). 
The 'stimulus' for the baseline recording is purely the EOD field the fish produces itself with no external stimulus.

The amplitude step stimulus here is a step in EOD amplitude. To be able to cause an amplitude modulation (AM) in the fish's EOD , the EOD was recorded and multiplied with the modulation (see fig. \ref{fig:stim_examples}). This modified EOD can then be presented at the right phase with the stimulus electrodes, causing constructive interference and adding the used amplitude modulation to the EOD (Fig. \ref{fig:stim_examples}). This stimuli construction as seen in equation~\ref{eq:am_generation} works for any AM as long as the EOD of the fish is stable. 

\begin{equation}
V_{Stim}(t) = EOD(t)(1 + AM(t)) 
\label{eq:am_generation}
\end{equation}


\begin{figure}[H]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left, center}, capbesidewidth=0.45\textwidth}}]{figure}[\FBwidth]
{\caption{\label{fig:stim_examples} Example of the stimulus construction. At the top a recording of the fish's EOD. In the middle: EOD recording multiplied with the AM, with a step from 0 to a contrast of 30\,\% between 0 and 50\,ms (marked in \todo{color}). At the bottom the resulting stimulus trace when the AM is added to the EOD. \todo{Umformulieren}}}
{\includegraphics[width=0.45\textwidth]{figures/amGeneration.pdf}}
\end{figure}


All step stimuli consisted of a delay of 0.2\,s followed by a 0.4\,s (n=68) or 1\,s (n=7) long step and a 0.8\,s long recovery time. The contrast range measured  was for the most cells 80--120\% of EOD amplitude. Some cells were measured in a larger range up to 20--180\%. In the range at least 7 contrasts were measured with at least 7 trials, but again many cells were measured with more contrasts and trials. The additionally measured contrasts were used for the model if they had at least 3 trials.

%That means for every cell the FI-Curve was measured at at least 7 Points each with at least 7 trials. If more contrasts were measured during the recording the additional information was used as long as there were at least 3 trials available.
%All presentations had 0.2\,s delay at the start and then started the stimulus at time 0. The step stimulus was presented for 0.4\,s (7 cells) or 1\,s(68 cells) and followed by 0.8\,s time for the cell to recover back to baseline. 

% Always a 0.2 second delay and 0.8 seconds after stimulus
% Stimulus start at time=0
% step duration 0.4s (7times) and 1s (68 times)
% contrast ranges maximal -0.8-0.8, contrasts tested 8-23
% most common -0.2 - 0.2 with 7 or 9 contrasts





%\begin{figure}[H]
%    \centering
%    \begin{minipage}{0.49\textwidth}
%    	\raisebox{70mm}{\large\sffamily A}
%        \includegraphics[width=0.95\textwidth]{figures/amGeneration.pdf}
%    \end{minipage}\hfill
%    \begin{minipage}{0.49\textwidth}
%    	\raisebox{70mm}{\large\sffamily B}
%        \includegraphics[width=\textwidth]{figures/stimuliExamples.pdf}
%    \end{minipage}
%		\caption{use real EOD data? A) B) \todo{(remove SAM stimulus/ the B full figure)} %\label{fig:stim_examples}}
%\end{figure}



\subsection{Cell Characteristics}

The cells were characterized by ten parameters: 6 for the baseline and 4 for the f-I curve.
For the baseline the mean firing rate was calculated by dividing the number of spikes in the recording by the recording time. Then the set of all interspike intervals (ISI) $T$ was computed and further parameters were calculated from it. 

The coefficient of variation
\begin{equation}
CV = \frac{STD(T)}{\langle T \rangle}
\label{eq:CV}
\end{equation}
is defined as the standard deviation (STD) of $T$ divided by the mean ISI, see equation \ref{eq:CV} with angled brackets as the averaging operator. 


The vector strength (VS) is a measure of how strong the cell locks to a phase of the EOD. It was calculated as seen in Eq. \ref{eq:VS}, by placing each spike on a unit circle depending on the relative spike time $t_i$ of how much time has passed since the start of the current EOD period in relation to the EOD period length. This set of vectors is then averaged and the absolute value of this average vector describes the VS. If the VS is zero the spikes happen equally in all phases of the EOD while if it is one all spikes happen at the exact same phase of the EOD. 

\begin{equation}
vs = |\frac{1}{n} \sum_n e^{iwt_i}|
\label{eq:VS}
\end{equation}


The serial correlation with lag k ($SC_k$) of $T$ is a measure how the ISI $T_i$ (the $i$-th ISI) influences the $T_{i+k}$ the ISI with a lag of x intervals. This is calculated as,  
 
\begin{equation}
SC_k = \frac{\langle (T_{i} - \langle T \rangle)(T_{i+k} - \langle T \rangle) \rangle}{\sqrt{\langle (T_i - \langle T \rangle)^2 \rangle}\sqrt{\langle (T_{i+k} - \langle T \rangle)^2 \rangle}}
\label{eq:SC}
\end{equation}
with the angled brackets again the averaging operator.


Finally the ISI-histogram was calculated within a range of 0--50\,ms and a bin size of 0.1\,ms. The burstiness was calculated as the percentage of ISI smaller than 2.5 EOD periods multiplied by the average ISI. This gives a rough measure of how how often a cell fires in the immediately following EOD periods compared to its average firing frequency. With a cell being more bursty the higher the percentage of small ISI and the lower the mean firing frequency of the cell.     


%burstiness: \todo{how to write as equation, ignore and don't show an equation?}
% \begin{equation}
% 	b = (T < 1/2EODf)/ N * \langle T \rangle
% \end{equation}

\begin{figure}[H]
\centering
% trim={<left> <lower> <right> <upper>}
\includegraphics[trim={10mm 5mm 10mm 5mm}, scale=0.8]{figures/f_point_detection.png}

\caption{\label{fig:f_point_detection} \todo{place right in text}On the left: The averaged response of a cell to a step in EOD amplitude. The beginning (at 0\,s) and end (at 1\,s) of the stimulus are marked by the gray lines. The detected values for the onset ($f_0$) and steady-state ($f_{inf}$) response are marked in \todo{color}. $f_0$ is detected as the highest deviation from the mean frequency before the stimulus while $f_{inf}$ is the average frequency in the 0.1\,s time window, 25\,ms before the end of the stimulus. On the right: The fi-curve visualizes the onset and steady-state response of the neuron for different stimuli contrasts. In \todo{color} the detected onset responses and the fitted Boltzmann, in \todo{color} the detected steady-state response and the linear fit.}
\end{figure}


The adaption behavior of the cell was characterized by the fi-curve consisting of the onset ($f_0$) and steady-state ($f_{inf}$) response. First the ISI frequency trace for each stimulus was calculated. The ISI frequency of a time point t is defined as the $1/T_i$ with $T_i$ the ISI the time point t falls into. This gives a frequency trace starting by the first spike and ending at the last spike. For the further analysis all trials done for a specific contrast were pointwise averaged after cutting them to the same length. This gives an averaged step response for each contrast as seen in figure \ref{fig:f_point_detection} on the left. 
In this frequency trace the onset $f_0$ and steady-state $f_{inf}$ response were detected (fig. \ref{fig:f_point_detection}). $f_0$ was defined as the farthest deviation from the mean frequency before the stimulus in the range of 25\,ms after stimulus onset. If there was no deviation farther than the variations before the stimulus, then the average frequency in that time window was used. This approximation made the detection of $f_0$ more stable for small contrasts and traces with high variation.   
The $f_{inf}$ response was defined as the average frequency of the trace in the 0.1\,s time window, 25\,ms before the end of the stimulus. 
Afterwards a Boltzmann was fitted to the onset response and a rectified line was fitted to the steady-state responses (FI-Curve fig. \ref{fig:f_point_detection}).




\subsection{Leaky Integrate and Fire Model}

% add info about simulation by euler integration and which time steps!
% show voltage dynamics with resistance : 

The above described cell characteristics need to be reproduced by a simple and efficient model to be able to simulate bigger populations in a reasonable time. The simplest commonly used neuron model is the perfect integrate-and-fire (PIF) model. It's voltage can be described in one equation: $\tau_m \frac{dV}{dt} = \frac{I}{R_m}$ with $I$ the stimulus current, $R_m$ the membrane resistance and a voltage threshold $V_\theta$. In this model $I$ is integrated and when this threshold is reached the voltage is reset to zero and a spike is recorded (see fig. \ref{fig:model_comparison} PIF). The model is useful for basic simulations but cannot reproduce the richer behavior of the p-units, as it has neither a memory of previous spikes that could cause the negative serial correlation between successive spikes nor can it show any adaption behavior. 

The next slightly more complex model is the leaky integrate-and-fire (LIF) model. As the name suggests it adds a leakage current to the PIF and as follows the equation \ref{eq:basic_voltage_dynamics} (fig. \ref{fig:model_comparison} LIF). The leakage current adds sub threshold behavior to the model but still cannot reproduce the adaption or serial correlation.

\begin{equation}
	\tau_m \frac{dV}{dt} = -V + IR_m
	\label{eq:basic_voltage_dynamics}
\end{equation}

To reproduce this behavior the model needs some form of memory of previous spikes. There are two main ways this can be added to the model as an adaptive current or a dynamic threshold. The biophysical mechanism of the adaption in p-units is unknown because the cell bodies are not accessible for intra-cellular recordings. Following the results of \cite{benda2010linear} a negative adaptive current was chosen, because the dynamic threshold causes divisive adaption instead of the subtractive adaption of p-units \citep{benda2005spike}. This results in an leaky integrate-and-fire model with adaption current (LIFAC) (fig. \ref{fig:model_comparison} LIFAC). The added adaptive current follow the dynamics:

\begin{equation}
	\tau_A \frac{dI_A}{dt} = -I_A + \Delta_A \sum \delta (t)
	\label{eq:adaption_dynamics}
\end{equation}

It is modeled as an exponential decay with the time constant $\tau_A$ and a strength called $\Delta_A$. $\Delta_A$ is multiplied with the sum of events in the spike train ($\delta (t)$) of the model cell. For the simulation using the Euler integration this results in an increase of $I_A$ by $\frac{\Delta_A}{\tau_A}$ at every time step where a spike is recorded. \todo{image of model simulation with voltage adaption and spikes using the toy model} The current of the from equation \ref{eq:basic_voltage_dynamics}  can thus be split into three currents for the modeling of the neuron:

\begin{equation}
	I = \alpha I_{Input} - I_A + I_{Bias}
	\label{eq:currents_lifac}
\end{equation}

The stimulus current $I_{Input}$, the bias current $I_{Bias}$ and the already discussed adaption current $I_A$. Note that in this p-unit model all currents are measured in mV because as mentioned above the cell body is not accessible for intra-cellular recordings and as such the membrane resistance $R_m$ is unknown \todo{ref mem res p-units}. $I_{Input}$ is the current of the stimulus, an amplitude modulated sine wave mimicking the frequency EOD. This stimulus is then rectified to model the receptor synapse and low-pass filtered with a time constant of $\tau_{dend}$ to simulate the low-pass filter properties of the dendrite (fig. \ref{fig:stim_development}). Afterwards it is multiplied with $\alpha$ a cell specific gain factor. This gain factor has the unit of cm because the $I_{Input}$ stimulus represents the EOD with a unit of mV/cm. $I_{Bias}$ is the bias current that causes the cells spontaneous spiking.   

Finally noise and an absolute refractory period were added to the model. The noise $\xi$ is drawn in from a Gaussian noise distribution and divided by $\sqrt{\Delta t}$ to get a noise which autocorrelation function is independent of the simulation step size $\Delta t$.  The implemented form of the absolute refractory period $t_{ref}$ keeps the model voltage at zero for the duration of $t_{ref}$ after a spike.


\begin{figure}[H]
\includegraphics[scale=0.6]{figures/model_comparison.pdf}
\caption{\label{fig:model_comparison} Comparison of different simple models normed to a spontaneous firing rate of ~10 Hz stimulated with a step stimulus. In the left column y-axis in mV in the right column the y-axis shows the frequency in Hz.  PIF: Shows a continuously increasing membrane voltage with a fixed slope and as such constant frequency for a given stimulus strength. LIF: Approaches a stimulus dependent membrane voltage steady state exponentially Also has constant frequency for a fixed stimulus value. LIFAC: Exponentially approaches its new membrane voltage value but also shows adaption after changes in the stimulus the frequency takes some time to adapt and arrive at the new stable value. }
% LIFAC + ref: Very similar to LIFAC the added absolute refractory period keeps the voltage constant for a short time after the spike and limits high fire rates. \todo{how to deal with the parameters}

\end{figure}

Together this results in the dynamics seen in equation \ref{eq:full_voltage_dynamics}. Not shown in the equation is the refractory period $t_{ref}$ and the $\tau_{dend}$ \todo{extra function describing $I_{input}$? rectify and filtering}

\begin{equation}
\begin{split}
	\tau_m \frac{dV}{dt} &= -V+I_{Bias} +\alpha I_{Input} - I_{A} + \sqrt{2D}\frac{\xi}{\sqrt{\Delta t}} \\
	\tau_A \frac{dI_A}{dt} &= -I_A + \Delta_A \sum \delta (t)
	\label{eq:full_voltage_dynamics}
\end{split}
\end{equation}


\begin{figure}[H]
\includegraphics[scale=0.6]{figures/stimulus_development.pdf}
\caption{\label{fig:stim_development} The stimulus modification in the model. The fish's EOD is simulated with a sin wave. It is rectified at the synapse and then further low-pass filtered in the dendrite.}
\end{figure}


\begin{table}[H]
\begin{tabular}{c|l|c}

 parameter & explanation & unit \\
 \hline
  $\alpha$   	&	stimulus scaling factor & [cm] \\
 $tau_m$    	&	membrane time constant & [ms]\\
 $I_{Bias}$ 	& 	bias current & [mV] \\
 $\sqrt{2D}$ 	&	noise strength & [mV$\sqrt{\text{s}}$]\\
 $\tau_A$ 		&	adaption time constant & [ms] \\
 $\Delta_A$ 	&	adaption strength & [mVms]\\
 $\tau_{dend}$ 	& 	time constant of dendritic low-pass filter & [ms] \\
 $t_{ref}$ 		&	absolute refractory period & [ms]
\end{tabular}
\caption{\label{tab:parameter_explanation} Overview about all variables of the model that are fitted.}
\end{table}





\subsection{Fitting of the Model}

% describe used errors 
% describe Nelder Mead 
This leaves the eight variables to be fitted to the cell. During the fitting and the analysis all models were simulated with at time step of 0.05\,ms.
The stimuli as described in the stimulus protocols section above were recreated for the stimulation of the model during the fitting process. The pure fish EOD was approximated by a simple sin function of the appropriate frequency, but it was decided to keep the amplitude of the sin at one to make the models more comparable. Changes in the amplitude can be compensated in the model by changing the input scaling factor and the time constant of the dendritic low-pass filter, so there is no qualitative difference.

During the fitting the baseline stimulus was simulated 3 times with 30\,s each and the step stimuli were simulated with a 0.5\,s delay, 0.5\,s duration and 0.5\,s recovery time. The contrasts were the same as in the cell recording. The step stimuli were repeated 8 times. 
With the simulation data the model characteristics were calculated the same way as for the cells (see above).
The error function was constructed from both the baseline characteristics: ISI-histogram, VS, CV, SC and burstiness and the fi-curve: the detections of $f_{inf}$ and $f_0$ responses for each contrast, the slope of the linear fit into the $f_{inf}$ and the frequency trace of one step response. 

The error of the VS, CV, SC, and burstiness was calculated as the scaled absolute difference:

\begin{equation}
err_i = |x^M_i - x^C_i| * c_i
\end{equation}
with $x^M_i$ the model value for the characteristic $i$, $x^C_i$ the corresponding cell value and $c_i$ a scaling factor that is the same for all cells but different between characteristics. The scaling factor was used to make all errors a similar size.

The error for the slope of the $f_{inf}$ fit was the scaled relative difference:

\begin{equation}
err_i = |1 - ((x^M_i - x^C_i) / x^C_i)| * c_i
\end{equation}

For the $f_{inf}$ and $f_0$ responses the average scaled difference off all contrasts was taken and finally the error for the ISI-histogram and the step-response was calculated with a mean-square error. For the histogram over all bins but for the step response only the first 50\,ms after stimulus onset as an error for the adaption time constant.  

All errors were then weighted and summed up for the full error. The fits were done with the Nelder-Mead algorithm of scipy minimize \citep{gao2012implementing}. All model variables listed above in table \ref{tab:parameter_explanation} were fit at the same time except for $I_{Bias}$. $I_{Bias}$ was determined before each fitting iteration and set to a value giving the correct baseline frequency.    



% errors
%[error_vs, error_sc, error_cv, error_hist, error_bursty, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope_at_straight, error_f0_curve]

% differences for baseline characteristics
% rms of ISI bins, f_0 response frequency trace
% abs diff of vs, sc, cv, burstiness 

% fi-curve difference between f_inf slope , mean relative error between f_points 

% baseline frequency "set" with I_Bias


\section{Results}



\section{Discussion}




\bibliography{citations} 
\bibliographystyle{apalike}


\end{document}