\begin{abstract}
    The simulation of a bowed string is challenging due to the strongly non-linear relationship between the bow and the string. This relationship can be described through a model of friction. Several friction models in the literature have been proposed, from simple velocity dependent to more accurate ones. Similarly, a highly accurate technique to simulate a stiff string is the use of finite-difference time-domain (FDTD) methods. As these models are generally computationally heavy, implementation in real-time is challenging. This paper presents a real-time implementation of the combination of a complex friction model, namely the elasto-plastic friction model, and a stiff string simulated using FDTD methods. We show that it is possible to keep the CPU usage of a single bowed string below 6 percent. For real-time control of the bowed string, the Sensel Morph is used.
    \end{abstract}
    \section{Introduction}
    \label{sec:intro}
    In physical modelling sound synthesis applications, the simulation of a bowed string is a challenging endeavour. This is mainly due to the strongly non-linear relationship between the bow and the string, through a model of friction. Such friction models can be categorised as static or dynamic; models of the latter type have only recently seen a major effort. As opposed to static friction models, where friction depends only on the relative velocity of the two bodies in contact, dynamic models describe the friction force through a differential equation.

     A recently popular dynamic model is the elasto-plastic model, first proposed in \cite{Dupont2002}. The model assumes that the friction between the two objects in contact is caused by a large ensemble of bristles, each of which contributes to the total friction force. The average bristle deflection is used as an extra independent variable for calculating the friction force. As shown in \cite{Serafin2003}, the elasto-plastic model can be applied to a bowed string simulation and it exhibits a hysteresis loop in the force versus velocity plane due to this multivariable dependency.
     This is consistent with measurements performed using a bowing machine in \cite{Woodhouse2003}.
     The elasto-plastic model has been thoroughly investigated in a musical context by Serafin et al. in \cite{Serafin2003, Serafin2004, Avanzini2005}.

    Regarding bowed string simulations, the first musical non-linear systems, including bowed strings, were presented by McIntyre, et al. in \cite{McIntyre1983}. Smith published the first real-time implementation of the bowed string using a digital waveguide (DW) for the string and a look-up table for the friction model in \cite{Smith1986}. Simultaneously, Florens, et al. published a real-time implementation using mass-spring systems for the string and a static friction model for the bow in \cite{Florens1986}.

    The dynamics of musical instruments are generally described by systems of  partial differential equations (PDEs). Specialised synthesis methods such as DWs \cite{Smith1992} and modal synthesis \cite{Morrison1993} are derived from particular solutions.  Mainstream time-stepping methods such as finite-difference time-domain (FDTD) methods were first proposed in \cite{Hiller, Hiller2, Chaigne}, and developed subsequently \cite{Bilbao2009, Bilbao2018}. In \cite{Maestre2014} the authors adapted the thermal model proposed by Woodhouse in \cite{Woodhouse2003} for real-time applications using a DW for the string implementation and a combination of the DW and FDTD methods for the bowing interaction. In \cite{Desvages2017, Desvages2015}, Desvages used FDTD methods for the implementation of the string in two polarizations and a static double exponential friction model introduced in \cite{Smith2000}. This was, however, not implemented in real-time. To the best of the authors' knowledge, the only known real-time implementation of any bow model applied to complete FDTD strings was presented in \cite{Willemsen2019} where the soft exponential friction function presented in \cite{Bilbao2009} was used. The current work can be considered an extension of this work.

    We are interested in bridging the gap between highly accurate physical models and efficient implementations so that these models can be played in real-time. In this work, we present an implementation of the elasto-plastic friction model in conjunction with a finite-difference implementation of the damped stiff string. Furthermore, we show that it is possible to play the string in real-time using the Sensel Morph controller \cite{Sensel2019}.

    This paper is structured as follows. In Section \ref{sec:elasto}, the elasto-plastic bow model in conjunction with a PDE model for a stiff string is described. Discretisation is covered in Section \ref{sec:discretisation}, and implementation details appear in Section \ref{sec:implementation}. In Section \ref{sec:results}, simulated results are presented and discussed. Some concluding remarks appear in Section  \ref{sec:conclusion}.

    \section{Elasto-Plastic Bow Model}\label{sec:elasto}

    Consider a linear model of transverse string vibration in a single polarization, where $u(x,t)$ represents string displacement as a function of time $t\geq 0$, in s, and coordinate $x\in[0,\,L]$ (in m) for some string length $L$ (in m). Using the subscripts $t$ and $x$ to denote differentiation with respect to time and space respectively, a partial differential equation describing the dynamics of the damped stiff string is \cite{Bilbao2009}
    \begin{equation}\label{eq:PDE}
        u_{tt} = c^2u_{xx}-\kappa^2u_{xxxx}-2\sigma_0u_t+2\sigma_1u_{txx}.
    \end{equation}
    Here, $c = \sqrt{T/\rho A}$ is the wave speed (in m/s) with tension $T$ (in N), material density $\rho$ (in kg$\cdot$m$^{-3}$) and cross-sectional area $A$ (in m$^2$). Furthermore, $\kappa = \sqrt{EI/\rho A}$ is the stiffness coefficient (in m$^2$/s) with Young's Modulus $E$ (in Pa) and area moment of inertia $I$ (in m$^4$). For a string of circular cross section we have radius $r$ (in m), cross-sectional area $A=\pi r^2$ and area moment of inertia $I=\pi r^4 /4$.  Lastly, $\sigma_0 \geq 0$ (in s$^{-1}$) and $\sigma_1 \geq 0$ (in m$^2$/s)
    %\SWcomment[these units for the damping coefs are correct, right?]
    are coefficients allowing for frequency-independent and frequency-dependent damping respectively.

    In our implementation we assume simply supported boundary conditions, which are defined as
    \begin{equation}
        u = u_{xx} = 0 \quad \text{where} \quad x = 0, L\, .
    \end{equation}
    % \SWcomment[No curly brackets for $x = \{0,L\}$? Is that because you can't have sets in the continuous domain?]

    \begin{figure}[ht]
        \centering
        \begin{tikzpicture}

        \def\radius{6}; % Radius of the string (>2!)
        \pgfmathsetmacro{\reps}{3}; % How may back-and-forths in the drawing of the springs
        \def\horShift{0.5}; %how far the bow is shifted to the right in b)
        \def\bowSpacing{0.2};
        \def\drawingSpacing{1.5}
        \def\bowWidth{5};

        %subfigure letters
        \node (A) at (-2.8, 0.5) {a)};
        \node (B) at (-2.8, 0.5 - \drawingSpacing) {b)};
        \node (C) at (-2.8, 0.5 - \drawingSpacing * 2) {c)};
        \node (D) at (-2.8, 0.5 - \drawingSpacing * 3) {d)};

        %bow velocity arrow
        \draw[->] (-1, 1.3) -- (1, 1.3) node [midway, above] (velText) {$v_\text{B}$};

        \pgfmathsetmacro{\zCoordTop}{0};
        \pgfmathsetmacro{\zYCoordBottom}{0};
        \def\springForZ{2}
        \foreach \drawing in {0, ..., 3}
        {
            %% Draw String
            \begin{scope}
                \clip (-1.5,-0.2- \drawing * \drawingSpacing) rectangle (1.5,1.5);
                \draw (0,-\radius + 0.25 - \drawing * \drawingSpacing) circle(\radius);
            \end{scope}

            %% Draw Bow
            \def\halfBW{\bowWidth*0.5}
            \pgfmathsetmacro{\halfNumDiag}{0.5 * \bowWidth / \bowSpacing};
            \draw[-] (-\halfBW + \drawing * \horShift,1 - \drawing * \drawingSpacing) -- (\halfBW + \drawing * \horShift, 1 - \drawing * \drawingSpacing);
            \foreach \bowDiag in {-\halfNumDiag, ...,\halfNumDiag}
            {
            \pgfmathtruncatemacro{\bD}{\bowDiag}
            % \ifnum\drawing=0
            %     \ifnum\bD<-1
            %         \draw[-] (\drawing * \horShift + \bowDiag * \bowSpacing, -\drawing * \drawingSpacing + 1) -- (\drawing * \horShift + \bowDiag * \bowSpacing + 0.1, -\drawing * \drawingSpacing + 0.1 + 1);
            %         \else
            %         \ifnum\bD>1
            %             \draw[-] (\drawing * \horShift + \bowDiag * \bowSpacing, -\drawing * \drawingSpacing + 1) -- (\drawing * \horShift + \bowDiag * \bowSpacing + 0.1, \drawing * -2 + 0.1 + 1);
            %         \fi
            %     \fi
            % \else
                \draw[-] (\drawing * \horShift + \bowDiag * \bowSpacing, -\drawing * \drawingSpacing + 1) -- (\drawing * \horShift + \bowDiag * \bowSpacing + 0.1, -\drawing * \drawingSpacing + 0.1 + 1);
            % \fi

            }

            \def\brokenSprings{{0, 1, 1, 0, 1, 0}};
            %% Draw Springs
            \foreach \springNo in {0, ..., 5}
            {
                % Calculate spring length depending on the radius of the string
                \pgfmathsetmacro{\startX}{\springNo  * 0.5 - 1.25};
                \pgfmathsetmacro{\calcSpace}{(\radius + 1) - \radius * sin(acos(\startX/\radius)) - 0.25};
                \pgfmathsetmacro{\springLength}{sqrt(\calcSpace*\calcSpace+\drawing*\horShift*\drawing*\horShift)};

                \pgfmathsetmacro{\spacing}{\springLength / (\reps + 2)};
                % spacing between two spring-back-and-forths
                \ifnum\drawing=0
                    \pgfmathsetmacro{\rot}{0};
                \else
                    \pgfmathsetmacro{\rot}{(270+(atan(\calcSpace/(\drawing*\horShift))))}; %rotation of the springs
                \fi

                \ifnum\drawing=1
                    \ifnum\springNo=\springForZ
                        \pgfmathsetmacro{\resTwo}{sqrt(\springLength*\springLength-\horShift*\horShift)};
                        \global\let\zCoordBottom = \resTwo;
                    \fi
                \fi

                \pgfmathsetmacro{\isBroken}{\brokenSprings[\springNo]};
                % debug code
                % \node (nodeTest\springNo) at (\springNo*1.1-2, -3 - 1 * \drawing + 0.3 * \springNo) {\isBroken};

                \begin{scope}[shift={(\startX + \drawing * \horShift,1 -\drawing * \drawingSpacing)}]
                    \pgfmathsetmacro{\xWidth}{0.1 - (\drawing * 0.02)};
                    \draw[-, rotate = \rot] (0, 0) -- (0, -\spacing * 0.5);
                    \draw[-, rotate = \rot] (0, -\spacing * 0.5) -- (\xWidth, -\spacing);
                    \def\Y{-\spacing}
                    \foreach \idx in {1,...,\reps}
                    {
                        \pgfmathsetmacro{\idxMinOne}{\idx-1};
                        \ifnum\drawing=2
                            \ifnum\isBroken=1
                                \pgfmathtruncatemacro{\idxT}{\reps * 0.5 + 1}
                                \ifnum\idx=\idxT
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing*0.6);
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing * 1.66) -- (-\xWidth,\Y - \idx * \spacing);
                                \else
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing);
                                \fi
                            \else
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing);
                            \fi
                        \else
                            \ifnum\drawing=3
                                \pgfmathtruncatemacro{\idxT}{\reps * 0.5 + 1}
                                \ifnum\idx=\idxT
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing*0.6);
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing * 1.66) -- (-\xWidth,\Y - \idx * \spacing);
                                \else
                                    \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing);
                                \fi
                            \else
                                \draw[-, rotate = \rot] (\xWidth, \Y - \idxMinOne * \spacing) -- (-\xWidth,\Y - \idx * \spacing);
                            \fi
                        \fi
                        \pgfmathsetmacro{\invXWidth}{\xWidth*-1};
                        \global\let\xWidth = \invXWidth;
                        \pgfmathsetmacro{\lastYPre}{\Y - \idx * \spacing};
                        \global\let\lastY = \lastYPre;
                    }
                    \draw[-, rotate = \rot] (\xWidth, \lastY) -- (0, \lastY - \spacing * 0.5);
                    \draw[-, rotate = \rot] (0, \lastY - \spacing * 0.5) -- (0, \lastY - \spacing);
                 \end{scope}

            }
            % \draw[<->] (2,2-0.707) -- node[right] {$r=\sqrt{2} \Rightarrow A=\pi(\sqrt{2})^2=2\pi$} (2,2+0.707);

            % \node(stringText) at (0, -\drawing * 2) {string};
            % \node[block, minimum height = 0.15cm, fill=white, draw=white] (bowText) at (\drawing * \horShift, 1.23 - \drawing * 2) {bow};
        }
        \filldraw[black] (-1.25+\springForZ*0.5 + \horShift,1-\drawingSpacing) circle (1pt) node[anchor=center](topZ){};
        \filldraw[black] (-1.25++\springForZ*0.5,1-\zCoordBottom-\drawingSpacing) circle (1pt) node[anchor=center](bottomZ){};

        \node [](leftNode) at (-1.25+\springForZ*0.5,-\drawingSpacing - 0.1) {};
        \node [](rightNode) at (-1.25 +\springForZ*0.5 + \horShift,-\drawingSpacing - 0.1) {};

        \draw[<->] (leftNode.center) -- (rightNode.center) node [midway, above] (TextNode) {$z$};
        \draw[dashed, darkgray] (leftNode) -- (bottomZ);
        \draw[dashed, darkgray] (rightNode) -- (topZ);
        %% Draw bow and string texts
            \node(stringText) at (0, 0) {string};
            \node(bowText) at (3, 1.1) {bow};
        %% Draw descriptions of z
        \def\zTexts{{"$z=0$", "$0<|z|<z_{\text{ba}}$", "$z_{\text{ba}}<|z|< z_\text{ss}$", "$|z|>z_\text{ss}$"}};

        \node[anchor = east](zText1) at (5.3, 0.5) {$z=0$};
        \node[anchor = east](zText1) at (5.3, 0.5 - \drawingSpacing) {$0<|z|\leq z_{\text{ba}}$};
        \node[anchor = east](zText1) at (5.3, 0.5 - \drawingSpacing * 2) {$z_{\text{ba}}<|z|< |z_\text{ss}|$};
        \node[anchor = east](zText1) at (5.3, 0.5 - \drawingSpacing * 3) {$|z|\geq|z_\text{ss}|$};

        \end{tikzpicture}
        \caption{\it Microscopic displacements of the bristles between the bow and the string. The bow moves right with a velocity of $v_\text{B}$. a) The initial state is where the average bristle displacement $z=0$. b) The bow has moved right relative to the string. The purely elastic, or presliding regime is entered (stick). c) After the break-away displacement $z_\text{ba}$, more and more bristles start to `break'. This is defined as the elasto-plastic regime. d) After all bristles have `broken', the steady state (slip) is reached and the purely plastic regime is entered.}
        \label{fig:elastoPlastic}
    \end{figure}

    As mentioned in the introduction, the elasto-plastic bow model assumes that the friction between the bow and the string is due to a large ensemble of bristles, each of which contributes to the total friction force. See Figure \ref{fig:elastoPlastic} for a graphical representation of this. The bristles are assumed to be damped stiff springs and can `break' after a given break-away displacement threshold. An extra term can be added to \eqref{eq:PDE} to include the bowing interaction
    \begin{equation}
        \begin{aligned}
        \label{eq:bowingTerm}
            u_{tt} = \hdots - \delta(x-x_\text{B})f(v, z)/\rho A.
        \end{aligned}
    \end{equation}
    Here, the spatial Dirac delta function $\delta(x-x_\text{B})$ (in m$^{-1}$) allows for the pointwise application of the force $f$ (in N) at externally supplied bowing position $x_\text{B}(t)$ (in m).

    %The force $f$ is dependent on the relative velocity $v$ between the string at the bowing point and the bow itself, %defined as
     In the following we will use the definitions found in \cite{Dupont2002}. The force $f$ is defined in terms of the relative velocity $v$ (in m/s) and average bristle displacement $z$ (in m) (see Figure \ref{fig:elastoPlastic}) as
    \begin{equation}\label{eq:forceFunction}
        f(v, z) = s_0z + s_1\dot z + s_2v + s_3w,
    \end{equation}
    where \begin{equation}\label{eq:relVel}
      v = u_t(x_\text{B}) - v_\text{B},
    \end{equation}
    where $v_\text{B}(t)$ is an externally supplied bow velocity,
    $s_0$ is the bristle stiffness (in N/m), $s_1$ is the damping coefficient (in kg/s), $s_2$ is the viscous friction (in kg/s) and $s_3$ is a dimensionless noise coefficient multiplied onto pseudorandom function $w(t)$ (in N) as done in \cite{Serafin2004} and adds noise to the friction force. Here, $\dot{z}$ indicates a time derivative of $z$, and is related to $v$ through
    \begin{equation}\label{eq:zdot}
        \dot z = r(v, z) = v \bigg[ 1-  \alpha(v, z)\frac{z}{z_\text{ss}(v)}\bigg],
    \end{equation}
    where $z_\text{ss}$ is the steady-state function
    \begin{equation}\label{eq:zss}
        z_\text{ss}(v) = \frac{\sgn(v)}{s_0}\Big[f_\text{C}+(f_\text{S}-f_\text{C})e^{-(v/v_\text{S})^2}\Big],
    \end{equation}
    with Stribeck velocity $v_\text{S}$ (in m/s), Coulomb force $f_\text{C} = f_\text{N}\mu_\text{C}$ and stiction force $f_\text{S} = f_\text{N}\mu_\text{S}$ (both in N). Here $\mu_\text{C}$ and $\mu_\text{S}$ are the dynamic and static friction coefficient respectively and $f_\text{N}(t)$ is the normal force (in N) which is, like $v_\text{B}(t)$, externally supplied. See Figure \ref{fig:zss} for a plot of \eqref{eq:zss}.

    \begin{figure}[ht]
    \centerline{\includegraphics[width=\paperFigWidth\textwidth]{figures/steadyState.eps}}
    \caption{\label{fig:zss}{\it A plot of the steady-state function $z_\text{ss}(v)$ with a force of 5 N.}}
    \end{figure}
    Furthermore, the adhesion map between the bow and the string is defined as
    \begin{equation}\label{eq:adhesionMap}
    \alpha(v, z) =
    \begin{aligned}
        \begin{cases}
        \begin{rightcases}
            &0 & |z| \leq z_\text{ba}\\
           &\alpha_\text{m}(v,z)&\ \ \ \, z_\text{ba}<|z|<|z_\text{ss}(v)|\\        &1 &|z|\geq|z_\text{ss}(v)|
            \end{rightcases}

            &\text{if}\  \sgn(v)=\sgn(z)\\
            \,0&\!\,\text{if}\  \sgn(v)\neq\sgn(z),
        \end{cases}
        \end{aligned}
    \end{equation}
    where the transition between the elastic and plastic behaviour is defined as
    \begin{equation}\label{eq:alphaM}
        \alpha_\text{m} = \frac{1}{2}\bigg[1+\sgn(z)\sin\bigg(\pi\frac{z-\sgn(z)\frac{1}{2}(|z_\text{ss}(v)|+z_\text{ba})}{|z_\text{ss}(v)|-z_\text{ba}}\bigg)\bigg],
    \end{equation}
    with break-away displacement $z_\text{ba}$, i.e., where the bristles start to break (see Figure \ref{fig:elastoPlastic} c)). A plot of the adhesion map can be found in Figure \ref{fig:alphaPlot}.\footnote{It is interesting to note is that in the literature on this topic such as \cite{Dupont2002, Serafin2003, Serafin2004, Avanzini2005}, a few inaccuracies can be found in the definition of $\alpha(v,z)$: 1) all uses of $z_\text{ss}$ in \eqref{eq:adhesionMap} and \eqref{eq:alphaM} lack the absolute value operator, 2) the multiplications with $\sgn(z)$ in \eqref{eq:alphaM} are excluded, 3) $\alpha(v,z)$ is undefined for $|z|=z_\text{ba}$ and $|z|=|z_\text{ss}(v)|$ (correct in the original paper by Dupont et al. \cite{Dupont2002}). It can be shown that only with the definitions presented here, is it possible to obtain the curve shown in Figure \ref{fig:alphaPlot}.}

    One of the difficulties in working with this model is that, due to the many approximations, the notion of an energy balance, relating the rate of stored energy in the system to power input and loss is not readily available. Such energy methods are used frequently in the context of physical modeling synthesis and virtual analog modeling as a means of arriving at numerical stability conditions for strongly nonlinear systems, as is the present case. See, e.g., \cite{Bilbao2009}. This means that we do not have a means of ensuring numerical stability in the algorithm development that follows. This does not mean, however, that an energy balance is not available.

    \begin{figure}[ht]
    \centerline{\includegraphics[width=\paperFigWidth\textwidth]{figures/drawAlpha3.eps}}
    \caption{\label{fig:alphaPlot}{\it A plot of the adhesion map $\alpha(v,z)$ plotted against $z$ when the signs of $v$ and $z$ are the same. The different regions of the map are shown with the coloured areas and correspond to Figure \ref{fig:elastoPlastic} according to: yellow - a) \& b), orange - c) and red - d).}}
    \end{figure}

    \section{Discretisation}\label{sec:discretisation}
    Finite-difference schemes for the stiff string in isolation are covered by various authors \cite{Chaigne, Bilbao2009}.

    Equation \eqref{eq:PDE} can be discretised at times $t = nk$, with sample $n \in \mathbb{N}$ and time-step $k = 1 / f_\text{s}$ (in s) with sample-rate $f_\text{s}$ (in Hz) and locations $x = lh$, where grid spacing $h$ (in m) needs to abide the following condition \cite{Bilbao2009}
    \begin{equation}\label{eq:stability}
        h \geq h_\text{min} = \sqrt{\frac{c^2k^2+4 \sigma_1k+\sqrt{(c^2k^2+4\sigma_1k)^2+16\kappa^2k^2}}{2}}
    \end{equation}
    and grid points $l \in [0,...,N]$, where $N=\text{floor}(L/h)$ and $N + 1$ is the total number of grid points. It is important to note that the closer $h$ is to $h_\text{min}$, the more accurate the scheme will be.
    Approximations for the derivatives found in \eqref{eq:PDE} are described in the following way \cite{Bilbao2009}:
    \begin{subequations}\label{eq:approximations}
        \begin{align}
            % \label{eq:secondSpacey}\delta_{yy}u_l^n &= \frac{1}{h^2}\big(u_{m+1}^n - 2u_m^n + u_{m-1}^n\big),\\
            %  \label{eq:fourthSpace}\delta_xxxx &= \frac{1}{h^4}\big(u_{l+2}^n - 4u_{l+1}^2 + 6 u_{l}^n - 4u_{l-1}^n + u_{l-2}^n\big),\\
            \label{eq:centerTime}
            u_{t} &\approx \delta_{t\cdot} u^n_l = \frac{1}{2k}\big(u_l^{n+1}-u_l^{n-1}\big),\\
            \label{eq:secondTime}
            u_{tt} &\approx \delta_{tt}u_l^n = \frac{1}{k^2} \big(u_l^{n+1} - 2u_l^n + u_l^{n-1}\big),\\
            \label{eq:secondSpacex}
            u_{xx} &\approx \delta_{xx}u_l^n = \frac{1}{h^2}\big(u_{l+1}^n - 2u_l^n + u_{l-1}^n\big),\\
            u_{txx} &\approx \label{eq:timeSpace}
            \delta_{t-}\delta_{xx}u_l^n = \; \frac{1}{hk^2}\big(u_{l+1}^n - 2u_l^n + u_{l-1}^n - u_{l+1}^{n-1} + 2u_l^{n-1} - u_{l-1}^{n-1}\big),
            \\
            \label{eq:fourthSpacex}
            u_{xxxx} &\approx\delta_{xxxx}u_l^n = \frac{1}{h^4}\big(u_{l+2}^n - 4u_{l+1}^n + 6u_l^n - 4u_{l-1}^n +u_{l-2}^n\big),
        \end{align}
    \end{subequations}
    with grid function $u_l^n$ denoting a discretised version of $u(x,t)$ at the $n$th time step and the $l$th point on the string. Note that in \eqref{eq:timeSpace}, the backwards time difference operator is used to keep \eqref{eq:FDS} explicit and thus computationally cheaper to update. Using the approximations shown in \eqref{eq:approximations}, \eqref{eq:bowingTerm} can be discretised to
    \begin{equation}
      \begin{aligned}
        \label{eq:FDS}
            \delta_{tt} u_l^n = &\: c^2 \delta_{xx} u_l^n -\kappa^2\delta_{xxxx} u_l^n - 2\sigma_0\delta_{t\cdot} u_l^n
            \\
            &+ 2\sigma_1\delta_{t-}\delta_{xx}u_l^n - J(x_\text{B}^n)f(v^n, z^n) / \rho A,
        \end{aligned}
    \end{equation}
    where the relative velocity described in \eqref{eq:relVel} can be discretised as
    \begin{equation}\label{eq:discRelVel}
    v^n = I(x_\text{B}^n)\delta_{t\cdot}u_l^n -  v_\text{B}^n.
    \end{equation}
        Here, $I(x_\text{B}^n)$ and $J(x_\text{B}^n)$ are weighting functions where the former interpolates the string displacement and velocity and the latter distributes the bowing term around time-varying bowing position $x_\text{B}^n$ (see Figure \ref{fig:interpol} and \cite{Bilbao2009}
    for more details on this). Furthermore,
    \begin{equation}\label{eq:discForceFunction}
        f(v^n,z^n) = s_0z^n + s_1r^n+s_2v^n+s_3w^n
    \end{equation}
    is the discrete counterpart of \eqref{eq:forceFunction} where
    \begin{equation}\label{eq:r}
        r^n = r(v^n,z^n) = v^n\bigg[1-\alpha(v^n,z^n)\frac{z^n}{z_\text{ss}(v^n)}\bigg]
    \end{equation}
    is the discrete counterpart of \eqref{eq:zdot}.
    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
        %  \draw [->] (0 0) edge (1 1);
        \draw[dashed] (0, 0) -- (5, 0);
         \node [block, draw=black](J) at (2.5, 1) {$J_3(x_\text{B})f(v,z)$};
         \node (u1) at (1, -0.5) {$u_{l_\text{B}-1}$};
         \node (u2) at (2, -0.5) {$u_{l_\text{B}}$};
         \node (u3) at (3, -0.5) {$u_{l_\text{B}+1}$};
         \node (u4) at (4, -0.5) {$u_{l_\text{B}+2}$};

        \foreach \id in {1,...,4}
        {
            \node [circle, draw=black, fill=white, inner sep=0pt,minimum size=5pt](a\id) at (\id, 0) {};
            \node [circle, fill=black, inner sep=0pt,minimum size=2pt](b\id) at (\id, 0.5) {};
            \draw [<-] (a\id) -- (b\id);
            \draw [-] (b\id) edge (J);
        }
        \node [block](NR) at (2.5, 2) {NR};
        \node [block](I) at (2.5, 3){$I_3(x_\text{B})u_l$};
        \draw[dashed] (0, 4) -- (5, 4);
        \foreach \id in {1,...,4}
        {
            \node [circle, draw=black, fill=white, inner sep=0pt,minimum size=5pt](c\id) at (\id, 4) {};
            \node [circle, fill=black, inner sep=0pt,minimum size=2pt](d\id) at (\id, 3.6) {};
            \draw [-] (c\id) -- (d\id);
            \draw [->] (d\id) edge (I);
        }
        \node(x) at (2.7, 4) {$\times$};
        \node(x) at (2.7, 0) {$\times$};
        \node(xb) at (2.7, 4.25) {$x_\text{B}$};
        \draw [->] (I) edge (NR);
        \draw [->] (NR) edge (J);

    \end{tikzpicture}
        \caption{\it Cubic interpolation at bowing point $x_\text{B}$. The interpolator $I$ retrieves the values of four grid points which are then used in the Newton-Raphson (NR) solver. This outputs the force function $f(v,z)$ that the spreading function $J$ in turn distributes over the same four grid points. This process happens every single sample. %See Appendix \ref{app:interpol} for more details.
        }
        \label{fig:interpol}
    \end{figure}

    At the bowing point we need to iteratively solve for two unknown variables: the relative velocity between the bow and the string $v^n$ and the mean bristle displacement $z^n$ of the bow at sample $n$.
    We can solve \eqref{eq:FDS} at $x_\text{B}^n$ using \eqref{eq:discRelVel} and identity \cite{Bilbao2009}
    \begin{equation}
        \delta_{tt}u_l^n = \frac{2}{k}\big(\delta_{t\cdot}u_l^n-\delta_{t-}u_l^n\big)
    \end{equation}
    resulting in
    %\begin{equation}
    %\label{eq:stiffStringFDS}
    %\begin{aligned}
    %\frac{2}{k}&\Big(v + v_\text{B}\Big) - \frac{2}{k^2}I(x_\text{B}^n)\delta_{t-}u_l^n  = \; c^2 I(x_\text{B}^n)\delta_{xx} u_l^n \\
    %&-\kappa^2I(x_\text{B}^n)\delta_{xxxx} u_l^n - 2\sigma_0(v
    %+ v_\text{B})\\
    %&+ 2\sigma_1I(x_\text{B}^n)\delta_{t-}\delta_{xx}u_l^n - J(x_\text{B}^n)f(v, z).
    %\end{aligned}
    %\end{equation}
    \begin{equation} \label{eq:incIdentity}
        I(x_\text{B}^n)J(x_\text{B}^n)f(v^n,z^n)/\rho A+\Big(\frac{2}{k}+2\sigma_{0}\Big) v^n+b^n = 0,
    \end{equation}
    % \SWcomment[or does this still need to be scaled by 1/h for it to be correctly solved in NR?]{}\SBcomment[Yes, you need the $1/h$...but (15) is only true if you use a pure spreading function selecting just one point...why not just do this? Otherwise you need to worry about the size of I*J. If you're moving the bow around, though, you definitely need this product though. ]
    where
    \begin{equation}\label{eq:bn}
            \begin{aligned}b^n =& \: \frac{2}{k}v_\text{B}^n-\frac{2}{k}I(x_\text{B}^n)\delta_{t-}u_l^n - c^2 I(x_\text{B}^n)\delta_{xx} u_l^n +\kappa^2I(x_\text{B}^n)\delta_{xxxx} u_l^n \\
        &+ 2\sigma_0v_\text{B}^n -2\sigma_1I(x_\text{B}^n)\delta_{t-}\delta_{xx}u_l^n
    \end{aligned}
    \end{equation}
    and can be pre-computed as its terms are not dependent on $v^n$ or $z^n$. Recalling \eqref{eq:forceFunction}, this can be rewritten to
    \begin{equation}\label{eq:newtonFunction}
    \begin{aligned}
        % J(x_\text{B}^n)\Big(
        &I(x_\text{B}^n)J(x_\text{B}^n)\Bigg(\frac{s_0z^n+s_1r^n+s_2v^n+s_3w^n}{\rho A}
        \Bigg)+\Big(\frac{2}{k} + 2\sigma_0 \Big)v^n+ b^n= 0.
        \end{aligned}
    \end{equation}
    % \SWcomment[is it ok to interpret the spreading operator like this? Also, I could include the $s_3w$ in $b$ instead (as it is not dependent on $v$ or $z$) but then it would be confusing when using $J$ for spreading the force as $s_3w$ is also part of the force function in  \eqref{eq:forceFunction}.] \SBcomment[OK, I don't get why you need the spreading operator anymore...] \SWcomment[For the scaling by $1/h$, or don't I need this anymore here?]
    % \begin{equation}\label{eq:newtonFunction}
    %     % J(x_\text{B}^n)\Big(
    %     s_0z+s_1((\mu_{t+})^{-1}\delta_{t+}) z+(s_2 + (\frac{2}{k} + 2\sigma_0)\rho A)v+s_3w
    %     % \Big)
    %     + b\rho A = 0\end{equation}
    % \SWcomment[This is how I am trying to implement it now: first multiplying everything in \eqref{eq:incIdentity} by $\rho A$ and then solving this for $v$ in \eqref{eq:velCalc}.]

    % Moreover,
    %     \begin{equation}
    %         \begin{aligned}b =& \: \frac{2}{k}v_\text{B}-\frac{2}{k}I(x_\text{B}^n)\delta_{t-}u_l^n - c^2 I(x_\text{B}^n)\delta_{xx} u_l^n +\kappa^2I(x_\text{B}^n)\delta_{xxxx} u_l^n \\
    %     &+ 2\sigma_0v_\text{B} -2\sigma_1I(x_\text{B}^n)\delta_{t-}\delta_{xx}u_l^n.
    % \end{aligned}
    % \end{equation}
    % and can be pre-computed as its terms are not dependent on $v$ or $z$.

    To obtain the values of $v^n$ and $z^n$, multivariate Newton-Raphson (NR) is used. If \eqref{eq:newtonFunction} is defined to be $g_1  = g_1(v^n, z^n)$ and
    \begin{equation}\label{eq:g2}
       g_2(v^n, z^n) = r^n - a^n = 0,
    \end{equation}
    with
    \begin{equation}\label{eq:an}
        a^n = (\mu_{t-})^{-1}\delta_{t-} z^n
    \end{equation}
    (where the operators applied to $z^n$ denote the trapezoid rule \cite{Bilbao2009}) we obtain the following iteration
    \begin{equation}\label{eq:NRit}
        \begin{bmatrix}
        v_{(i+1)}^n\\
        z_{(i+1)}^n
        \end{bmatrix}
        =
        \begin{bmatrix}
        v_{(i)}^n\\
        z_{(i)}^n
        \end{bmatrix}
        -
        \begin{bmatrix}
        \frac{\partial g_1}{\partial v} & \frac{\partial g_1}{\partial z}\\
        \frac{\partial g_2}{\partial v} & \frac{\partial g_2}{\partial z}\\
        \end{bmatrix}^{-1}
        \begin{bmatrix}
        g_1\\
        g_2
        \end{bmatrix}\,
        ,
    \end{equation}
    where $i$ is the iteration number capped by 50 iterations, and the convergence threshold is set to $10^{-7}$.
    % To obtain the values of $v$ and $z$ at sample $n$, an iterative solving method such as Newton-Raphson (NR) needs to be used and is defined as \cite{Wallis1685}
    % \begin{equation}
    %     y_{i+1} = y_{i} - \frac{g(y_i)}{g'(y_i)} \quad \text{while} \quad |y_{i+1}-y_i| > \phi
    % \end{equation}
    % where $g(y)$ is an arbitrary function dependent on to-be-calculated variable $y$ at iteration index $i$. The calculation is done until the difference between the unknown variable at the next iteration and the current iteration is smaller than a threshold $\phi$.

    % As we need to find the roots of \eqref{eq:zdot}, $g$ with $y=\dot z$ is defined as
    % \begin{equation}
    %   g(\dot z) = v\bigg[1-\alpha(v, z)\frac{z}{z_\text{ss}(v)}\bigg] -  \dot z(v,z) = 0,
    % \end{equation}
    % and
    % \begin{equation}
    %     \dot z_{(i+1)} = \dot z_{(i)} - \frac{g(\dot z_{(i)})}{g'(\dot z_{(i)})}
    % \end{equation}
    % where
    % \begin{equation}\label{eq:derivativeG}
    %     g'(\dot z_{(i)}) = -\frac{s_1}{s_2+\frac{2}{k} + 2\sigma_0}\frac{\partial g(\dot z_{(i)})}{\partial v} + \frac{k}{2}\frac{\partial g(\dot z_{(i)})}{\partial z} - 1.
    % \end{equation}
    % % \begin{equation}\label{eq:derivativeG}
    % %     g'(\dot z^i) = -\frac{s_1}{s_2+(\frac{2}{k} + 2\sigma_0)\rho A}\frac{dg(\dot z^i)}{dv} + \frac{k}{2}\frac{dg(\dot z^i)}{dz} - 1.
    % % \end{equation}
    % The derivatives in \eqref{eq:derivativeG} can be found in \cite{Serafin2004}. In the NR iteration, the newly calculated value for $\dot z$ and the values of $z$ and $\dot z$ at the previous time step are used to calculate an estimate of $z$ using the trapezoid rule
    % \begin{equation}\label{eq:trapRule}
    %     z^n = z^{n-1} + \frac{k}{2}(\dot z_{(i+1)} + \dot z^{n-1}).
    % \end{equation}
    % Inserting this into \eqref{eq:newtonFunction} we can calculate $v$ using
    % \begin{equation}\label{eq:velCalc}
    %     v = \frac{-s_0z-s_1\dot z-s_3w-b}{s_2 + \frac{2}{k} + 2\sigma_0}.
    % \end{equation}
    % % \begin{equation}\label{eq:velCalc}
    % %     v = \frac{-s_0z-s_1\dot z-s_3w-b\rho A}{s_2 + (\frac{2}{k} + 2\sigma_0)\rho A}.
    % % \end{equation}
    % From \eqref{eq:trapRule} and \eqref{eq:velCalc} it is now also clear how the coefficients that the derivatives in \eqref{eq:derivativeG} are multiplied with are obtained.

    \section{Implementation}\label{sec:implementation}
    In this section, we will elaborate on the implementation; the parameters used and the system architecture. The real-time implementation of the discrete-time model shown in the previous section has been done using C++ together with the JUCE framework \cite{JUCE}. The application is shown in Figure \ref{fig:application}. The parameters we used can be found in Table \ref{tab:parameters}, most of which are based on implementations by Serafin in \cite{Serafin2004}. These parameters will be static, i.e., are not user-controlled (except for $z_\text{ba}$ and $s_3$ which rely on $f_\text{N}$). A demonstrative video can be found in \cite{video}.
        \begin{figure}[ht]
    \centerline{\includegraphics[width=\paperFigWidth\textwidth]{figures/JUCEapp.png}}
    \caption{\label{fig:application}{\it The elasto-plastic bowed string application. The bow is shown as a yellow rectangle, moves on interaction and its opacity depends on the finger force. The state $\mathbf{u}^n$ is visualised using the cyan curve and stopping-finger position is shown as a yellow circle. The grey lines show the `frets' corresponding to semi-tones as a visual reference for the stopping position and do not influence the model.}}
    \end{figure}
    \begin{table}[ht]
      \caption{{\it Parameter values. Values for the fundamental frequency $f_0$ can be found in Section \ref{sec:results}.}}
        \centering
      \begin{tabular}{|c|c|c|c|}\hline
        Parameter & Symb. (unit) & Value (notes)\\ \hline
        Material Density &$\rho$ (kg$\cdot$m$^{-3}$) & $7850$ \\
        Radius & $r$ (m) & $5\cdot10^{-4}$\\
        String length & $L$ (m) & $1$ \\
        Wave speed & $c$ (m/s) & $2 f_0/L$\\
        Young's modulus & $E$ (Pa) & $2\cdot 10^{11}$\\
        Freq. indep. damping & $\sigma_0$ (s$^{-1}$) & $1$\\
        Freq. dep. damping & $\sigma_1$ (m$^{2}$/s) & $5 \cdot 10^{-3}$\\
        Coulomb friction & $\mu_\text{C}$ (-) & $0.3$ ($<\mu_\text{S}$) \\
        Static friction & $\mu_\text{S}$ (-) & $0.8$ ($>\mu_\text{C}$) \\
        Normal force & $f_\text{N}$ (N) & 10 \\
        Bow velocity & $v_\text{B}$ (m/s) & 0.1 \\
        Bow position & $x_\text{B}$ (m) & 0.25 \\
        Stribeck velocity & $v_\text{S}$ (m/s) & $0.1$ \\
        Bristle stiffness & $s_0$ (N/m)& $10^4$ \\
        Bristle damping & $s_1$ (kg/s)& $0.001\sqrt{s_0}$ \\
        Viscous friction & $s_2$ (kg/s) & $0.4$ \\
        Noise coefficient & $s_3$ (-) & $0.02f_\text{N}$\\
        Pseudorandom func. & $w$ (N) & $-1<w<1$\\
        Break-away disp.& $z_\text{ba}$ (m) & $0.7 f_\text{C}/s_0$ ($<f_\text{C}/s_0$) \\
        Sample rate & $f_\text{s}$ (Hz) & 44,100 \\
        Time step & $k$ (s) & $1/f_\text{s}$ \\
        %NR threshold & $\phi$ (-) & $10^{-7}$ \\
        \hline
     \end{tabular}
        %
      \label{tab:parameters}
    \end{table}
    We use the passivity condition proposed by \cite{Astrom2008} for our choices of different parameter-values. As this condition applies to the LuGre model first proposed in \cite{Canudas1993, Canudas1995} from which the elasto-plastic model evolved, further investigation is required to conclude whether these conditions are identical for the elasto-plastic model.
    \subsection{Sensel Morph}
    As mentioned in Section \ref{sec:intro}, the Sensel Morph (or Sensel for short) is used as an interface to control the bowed string (see Figure \ref{fig:sensel}). The Sensel is a highly sensitive touch controller containing ca. 20,000 pressure sensitive sensors that allow for expressive control of the implementation \cite{Sensel2019}.
    \begin{figure}[ht]
    \centerline{\includegraphics[width=\paperFigWidth\textwidth]{figures/IMG_0637.jpg}}
    \caption{\label{fig:sensel}{\it The Sensel Morph: an expressive touch sensitive controller used for controlling the real-time elasto-plastic bowed string implementation.}}
    \end{figure}

    \subsection{Interaction}
    The first finger the Sensel registers is linked to the following parameters: the normal force of the bow $f_\text{N}$ (finger pressure), the bowing velocity $v_\text{B}$ (vertical finger velocity) and bowing position $x_\text{B}$ (horizontal finger position). The parameters are limited by the following conditions: $0 \leq f_\text{N} \leq 10$, $-0.3 \leq v_\text{B} \leq 0.3$ and $0<x_\text{B}<L$. The second finger acts as a stopping finger on the string. As done in \cite{Willemsen2019}, for a string stopped at location $x_\text{f}\in[0,L]$ and $l_\text{f}=\text{floor}(x_\text{f}/h)$ we use
    \begin{equation}
    u_l^n =
        \begin{cases}
            \hfil 0, & l = l_\text{f} - 1 \vee l = l_\text{f}\\
            \hfil (1-\alpha_\text{f}^\epsilon) u_l^n, & l = l_\text{f} + 1\\
            \hfil u_l^n, & \text{otherwise}
        \end{cases}
    \end{equation}
    where $\alpha_\text{f} = x_\text{f} / h - l_\text{f}$ and $\epsilon = 7$ is a heuristic value that has been found to most linearly alter pitch between grid points.

    \subsection{System Architecture}\label{sec:systemArch}
    Implementation of the scheme shown in \eqref{eq:FDS} starts by expanding the operators shown in \eqref{eq:approximations} and solving for the state at the next sample $\mathbf{u}^{n+1}$ where $\mathbf{u}$ is a vector containing the values for all grid points $l\in[0,...,N]$.

    \begin{figure}[ht]
    \centerline{\includegraphics[width=\paperFigWidth\textwidth]{figures/systemArchitecture.pdf}}
    \caption{\label{fig:systemArch}{\it The system architecture. See Section \ref{sec:systemArch} for a thorough explanation.}}
    \end{figure}

    An overview of the system architecture can be found in Figure \ref{fig:systemArch}. The three main components of the application are the Sensel controlling the application, the violin string class that performs the simulation and the main application class that moderates between these and the auditory and visual outputs. The black arrows indicate instructions that one of these components can give to another and the hollow arrows indicate data flows. Moreover, the arrows are accompanied by coloured boxes, depicting what thread the instruction or data flow is associated with and at what rate this runs.

    The graphics thread has the lowest priority, is denoted by the green boxes and runs at 15 Hz. The redraw instruction merely retrieves the current string state $\mathbf{u}^n$ and bow and finger position and visualises this as shown in Figure \ref{fig:application}.

    The thread checking and receiving data from the Sensel runs at 150 Hz and is denoted by the blue boxes. The parameters that the user interacts with (bowing force, velocity and position) are also updated at this rate.

    The highest priority thread is the audio thread denoted by the orange boxes and runs at 44,100 Hz. The violin string class gets updated at this rate and performs operations in the order shown in Algorithm \ref{alg:calcOrder}.
    % following order:
    % \begin{enumerate}
    %     \item Calculate $f(v^n, z^n)$ in \eqref{eq:discForceFunction} using the values for $v^n$ and $z^n$ obtained using NR \eqref{eq:NRit}.
    %     \item Calculate $\mathbf{u}^{n+1}$ using the calculated force function.
    %     \item Update the states: switch the (C++) pointer from the vector containing the current values of $\mathbf{u}$ to $\mathbf{u}^{n-1}$ and do the same for $\mathbf{u}^{n+1}$ and $\mathbf{u}$.
    % \end{enumerate}

    \begin{algorithm}[ht]
    \setstretch{1.25}
    \fbox{\parbox{0.9\linewidth}{
     \For{t = 1:lengthSound}{
     calculate computable part $b^n$ (Eq. \eqref{eq:bn})\\
     $\epsilon = 1$\\
     $i = 0$\\
      \While{$\epsilon <$ tol $\wedge\ i < 50 \wedge f_\text{C} > 0$}{
        calculate..
        \vspace{0.15cm}
        \\
    \begin{minipage}[c]{0.3\linewidth}
    1. $z_\text{ss}(v_{(i)}^n)$ \\
    2. $\alpha(v_{(i)}^n,z_{(i)}^n)$ \\
    3. $r(v^n_{(i)}, z^n_{(i)})$ \\
    4. $g_1$, $g_2$
    \end{minipage}
    \begin{minipage}[c]{0.6\linewidth}
    (Eq. \eqref{eq:zss} in discrete-time)\\
        (Eq. \eqref{eq:adhesionMap} in discrete-time)\\
        (Eq. \eqref{eq:r})\\
        (Eqs. \eqref{eq:newtonFunction} and \eqref{eq:g2})
    \end{minipage}
    \vspace{0.01cm}
    \\
        5.--9. Compute derivatives of 1.--4. in the same order. \\
        10. Perform vector NR to obtain $v_{(i+1)}^n$ and $z_{(i+1)}^n$\\
        11. Calculate $\epsilon$: $\epsilon = \norm{
        \begin{bmatrix}
        v_{(i+1)}^n\\
        z_{(i+1)}^n
        \end{bmatrix} -
        \begin{bmatrix}
        v_{(i)}^n\\
        z_{(i)}^n
        \end{bmatrix}}$\\
        12. Increment $i$: $i = i + 1$
      }
      Repeat 1.--3. using the values for $v^n$ and $z^n$ from the NR iteration.
      \vspace{0.15cm}
      \\
      \begin{minipage}[c]{0.4\linewidth}
    Calculate $f(v^n,z^n)$\\
    Calculate $\mathbf{u}^{n+1}$
    \end{minipage}
    \begin{minipage}[c]{0.5\linewidth}
    (Eq. \eqref{eq:discForceFunction})\\
    (Eq. \eqref{eq:FDS} expanded)
    \end{minipage}
      \vspace{0.15cm}
     \\
    $\mathbf{u}^{n-1} = \mathbf{u}^n$\\
    $\mathbf{u}^{n} = \mathbf{u}^{n+1}$
     }
     }}
     \vspace{0.12cm}
     \caption{Pseudocode showing the order of calculations.\label{alg:calcOrder}}
    \end{algorithm}

    \section{Results and Discussion}\label{sec:results}

    Figure \ref{fig:output44100} shows the output waveforms for a string with $f_0 = 440$ Hz at different points along the string. The bowing parameters are $f_\text{N} =$ 5 N and $v_\text{B} =$ 0.1 m/s. The figure shows the traditional Helmholtz motion, which is the characteristic motion of a bowed string.

    \begin{figure}[ht]
      \centering
      \begin{tikzpicture}[->,node distance=3cm,
        thick,main node/.style={circle,draw}]

        \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\paperFigWidth\textwidth]{figures/newPaperWaveform.eps}};
        \node (A) at (0.3, 2.8) {a)};
        \node (B) at (0.3, 1.2) {b)};
      \end{tikzpicture}
      \caption{\it Output waveforms of the simulation at different positions along the string where $N$ denotes the number of points of the string ($f_0 =$ 440 Hz, $f_\text{N} =$ 5 N and $v_\text{B} =$ 0.1 m/s). \label{fig:output44100}}
    \end{figure}

    To test whether the implementation exhibits a hysteresis loop, the force vs. relative velocity plane was visualised. In Figure \ref{fig:hysteresis}, this plot can be found for which the same parameters have been used. The figure shows values for 500 samples around $t = 0.5f_\text{s}$. As can be seen from the figure, the hysteresis loop is achieved and is similar to the one observed in \cite{Smith2000}. The group of values around $v=0$ are due to the sticking behaviour, and the others (the loop on the left) to the slipping behaviour.

    \begin{figure}[ht]
      \centering
      \begin{tikzpicture}[->,node distance=3cm, scale=1.14, % needed for the correct arrow placement in PhD thesis
        thick,main node/.style={circle,draw}]

        \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.8\textwidth]{figures/hysteresis3.eps}};
        % \filldraw[black] (arr2B) (2,2) circle (1pt) node[anchor=center](topZ){};
        % \filldraw[black] (arr2E) (3,1.5) circle (1pt) node[anchor=center](topZ){};
        % (arr2B) edge[bend right] node [arrow] {} (arr2E);

      \node (arr1B) at (3.8, 3.15) {};
      \node (arr1E) at (5.7, 2.65) {};
      \node (arr2B) at (6.8, 1.2) {};
      \node (arr2E) at (5, 1) {};
      \node (arr3B) at (1.4, 1.7) {};
      \node (arr3E) at (1.5, 2.6) {};
      \path[every node/.style={font=\sffamily\small}]

        (arr1B) edge[bend left = 30] node [left] {} (arr1E)
        (arr2B) edge[bend left = 35] node [left] {} (arr2E)
        (arr3B) edge[bend left = 60] node [left] {} (arr3E);
        % \begin{scope}[x={(image.south east)},y={(image.north west)}]
        %     \draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
        % \end{scope}
      \end{tikzpicture}
      \caption{\it Hysteresis loop showing 500 values. The values around $v=0$ are due to sticking behaviour and the loop on the left is due to slipping behaviour. \label{fig:hysteresis}}
    \end{figure}

    % Empirical investigation on the behaviour of the model showed that, for low bow forces (around 0.001 N), where a real bowed string shows a so-called multiple slipping, we encounter instability at \SWcomment[as a result of the NR iteration not being able to converge]{}. Using higher sample rates resolves this issue. At higher forces, the NR converges after ca. 1-5 iterations.

    For testing the speed of the algorithm, a MacBook Pro with a 2.2 GHz Intel Core i7 processor was used. The algorithm was tested using different frequencies according to the violin tuning of empty strings: $f_0 = 196.0$ (G3), $293.66$ (D4), $440.0$ (A4) and $659.26$ (E5) Hz corresponding to $N = 95$, $71$, $49$, and $33$ grid points respectively. The results can be seen in Table \ref{tab:results}. When the total number of strings is smaller than 4, always the lowest frequency strings are used.
    %This behaviour will require further simulations to be completely understood.
    % \begin{table}[h]
    %   \caption{{\it Analysis of the amount of iterations for strings with different fundamental frequencies ($f_0$) tested at different sample rates ($f_\text{s}$) for 2 seconds of simulation. The average values are given together with the maximum number of iterations observed. When the capping is used, a percentage is shown denoting the percentage of samples where this capping was used.}}
    % 	\centering
    %   \begin{tabular}{|c|c|c|c|c|c|c|}\hline

    %     \multirow{ 2}{*}{\diagbox{$f_0$}{$f_\text{s}$}} & \multicolumn{2}{c|}{44,100}& \multicolumn{2}{c|}{441,000}& \multicolumn{2}{c|}{882,000}\\
    %     \cline{2-7}
    %     & avg& max &avg &max & avg & max\\
    %     \hline
    %     196.00 & 3.35 & 1.18 \% & 2.50& 0.03\% & 2.33 & 7 \\
    %     293.66 & 3.14 & 0.64\% & 2.37 & 0.007\% & 2.11 & 6\\
    %     440.00 & 2.99 & 0.27\% & 2.57 & 10& 2.15 & 6\\
    %     659.26 & 3.29 & 10 & 2.73 & 8 & 2.54 & 6 \\
    %     \hline
    %  \end{tabular}
    % 	%
    %   \label{tab:results}
    % \end{table}

    \begin{table}[ht]
      \caption{{\it CPU usage for different amounts of strings. The values are averages over a 10 s period both for the enabled and disabled graphics thread. All strings are bowed simultaneously (polyphonically).}}
        \centering
      \begin{tabular}{|c|c|c|}\hline

        Amount of strings & Graphics (\%) & No graphics (\%)\\
        \hline
        1 & 44.8 & 5.95\\
        2 & 47.7 & 9.54\\
        3 & 52.8 & 12.1 \\
        4 & 60.9 & 17.9\\
        \hline
     \end{tabular}
        %
      \label{tab:results}
    \end{table}

    From Table \ref{tab:results} it can be observed that for one string, the CPU usage is $<6\%$ with the graphics thread disabled. This is a great result, given the fact that both the bow and the string model are computationally complex. Empirical investigation shows that the NR algorithm converges after ca. 3-4 iterations and the capping of 50 iterations never has to be used. A single string (but also more) could thus safely be used as an audio plugin in parallel to others without the user having to worry about auditory dropouts. %Furthermore, it can be observed that the differences in CPU usage decrease as the number of strings increases. This can be explained by the fact that the number of points for higher strings are less than that of lower strings and thus need less computational power.

    \section{Conclusions}\label{sec:conclusion}
    In this paper, we presented a real-time implementation of an elasto-plastic friction model with applications to a  bow exciting a string, discretised using a finite-difference approach.

    With a single string we are able to keep the CPU usage down to $<6\%$ making for an efficient implementation that could be used in parallel with other virtual instruments or plugins.

    Future work includes parameter design and including an instrument body for more realistic sounding results, as well as listening tests to verify the perceivable differences between simpler friction models versus the elasto-plastic model.

    \section{Acknowledgments}
    Many thanks to the anonymous reviewers for giving their valuable input. This work is supported by NordForsk's Nordic
    University Hub Nordic Sound and Music Computing Network
    NordicSMC, project number 86892.


\section{Examples}

\subsection{Factorial and Fibonacci}

These examples show that the \pfc\ backward chaining facility can do
such standard examples as the factorial and Fibonacci functions.

Here is a simple example of a \pfc\ backward chaining rule to compute
the Fibonacci series.
\example
fib(0,1).
fib(1,1).
fib(N,M) <=
  N1 is N-1,
  N2 is N-2,
  fib(N1,M1),
  fib(N2,M2),
  M is M1+M2.
\end{verbatim}\end{quote}

Here is a simple example of a \pfc\ backward chaining rule to compute
the factorial function.

\example
=> fact(0,1).
fact(N,M) <=
  N1 is N-1,
  fact(N1,M1),
  M is N*M1.
\end{verbatim}\end{quote}

\subsection{Default Reasoning}

This example shows how to define a default rule.  Suppose we would
like to have a default rule that holds in the absence of contradictory
evidence. We might like to state, for example, that an we should
assume that a bird can fly unless we know otherwise.  This could be
done as:

\example
bird(X), ~not(fly(X)) => fly(X).
\end{verbatim}\end{quote}
We can, for our convenience, define a {\em default} operator which
takes a \pfc\ rule and qualifies it to make it a default rule.  This
can be done as follows:
\example
default((P => Q)),{pfcAtom(Q)} => (P, ~not(Q) => Q).
\end{verbatim}\end{quote}
where \prolog{pfcAtom(X)} holds if \prolog{X} is a ``logical atom''
with respect to \pfc\ (i.e . not a conjunction, disjunction, negation,
etc).

One we have defined this, we can use it to state that birds fly by
default, but penguins do not.
\example
% birds fly by default.
=> default((bird(X) => fly(X))).

isa(C1,C2) =>
  % here's one way to do an isa hierarchy.
  {P1 =.. [C1,X],
    P2 =.. [C2,X]},
  (P1 => P2).

=> isa(canary,bird).
=> isa(penguin,bird).

% penguins do not fly.
penguin(X) => not(fly(X)).

% chilly is a penguin.
=> penguin(chilly).

% tweety is a canary.
=> canary(tweety).
\end{verbatim}\end{quote}

\subsection{KR example}

isa hierarchy. roles.  types. classification. etc.

\subsection{Maintaining Functional Dependencies}

\label{sec:funcdep}

One useful thing that \pfc\ can be used for is to automatically
maintain function Dependencies in the light of a dynamic database of
fact. The builtin truth maintenance system does much of this.
However, it is often useful to do more.  For example, suppose we want
to maintain the constraint that a particular object can only be
located in one place at a given time.  We might record an objects
location with an assertion \prolog{at(Obj,Loc)} which states that the
current location of the object \prolog{Obj} is the location
\prolog{Loc}.

Suppose we want to define a \pfc\ rule which will be triggered
whenever an \prolog{at/2} assertion is made and will remove any
previous assertion about the same object's location.  Thus to reflect
that an object has moved from location A to location B, we need merely
add the new information that it is at location B.  If we try to do
this with the \pfc\ rule:
\example
at(Obj,Loc1),
at(Obj,Loc2),
{Loc1\==Loc2}
=>
~at(Obj,Loc1).
\end{verbatim}\end{quote}
we may or may not get the desired result.  This rule will in fact
maintain the constraint that the database have at most one
\prolog{at/2} assertion for a given object, but whether the one kept
is the old or the new depends on the particular search strategy being
used by \pfc\.  In fact, under the current default strategy, the new
assertion will be the one retracted.

We can achieve the desired result with the following rule:
\example
at(Obj,NewLoc),
{at(Obj,OldLoc), OldLoc\==NewLoc}
  =>
  ~at(Obj,OldLoc).
\end{verbatim}\end{quote}
This rule causes the following behavior. Whenever a new assertion
\prolog{at(O,L)} is made, a Prolog search is made for an assertion that
object O is located at some other location.  If one is found, then it
is removed.

We can generalize on this rule to define a meta-predicate
\prolog{function(P)} which states that the predicate whose name is
\prolog{P} represents a function.  That is, \prolog{P} names a
relation of arity two whose first argument is the domain of the
function and whose second argument is the function's range.  Whenever
an assertion \prolog{P(X,Y)} is made, any old assertions matching
\prolog{P(X,\_)} are removed.  Here is the \pfc\ rule:
\example
function(P) =>
  {P1 =.. [P,X,Y],
   P2 =.. [P,X,Z]},
  (P1,{P2,Y\==Z} => ~P2).
\end{verbatim}\end{quote}

We can try this with the following results:
\example
| ?- add(function(age)).
Adding (u) function(age)
Adding age(A,B),{age(A,C),B\==C}=> ~age(A,C)
yes

| ?- add(age(john,30)).
Adding (u) age(john,30)
yes

| ?- add(age(john,31)).
Adding (u) age(john,31)
Removing age(john,30).
yes
\end{verbatim}\end{quote}

Of course, this will only work for functions of exactly one argument,
which in Prolog are represented as relations of arity two.  We can
further generalize to functions of any number of arguments (including
zero), with the following rule:

\example

function(Name,Arity) =>
  {functor(P1,Name,Arity),
   functor(P2,Name,Arity),
   arg(Arity,P1,PV1),
   arg(Arity,P2,PV2),
   N is Arity-1,
   merge(P1,P2,N)},
  (P1,{P2,PV1\==PV2} => ~P2).

merge(_,_,N) :- N<1.
merge(T1,T2,N) :-
  N>0,
  arg(N,T1,X),
  arg(N,T2,X),
  N1 is N-1,
  merge(T1,T2,N1).

\end{verbatim}\end{quote}
The result is that adding the fact \prolog{function(P,N)} declares P
to be the name of a relation of arity N such that only the most recent
assertion of the form $P(a_{1},a_{2},\ldots,a_{n-1},a_{n})$ for a
given set of constants $a_{1},\ldots,a_{n-1}$ will be in the database.
The following examples show how we might use this to define a
predicate \prolog{current\_president/1} that identifies the current
U.S. president and \prolog{governor/3} that relates state, a year and
the name of its governor.
\example
% current_president(Name)
| ?- add(function(current_president,1)).
Adding (u) function(current_president,1)
Adding current_president(A),
       {current_president(B),A\==B}
	=>
        ~current_president(B)
yes

| ?- add(current_president(reagan)).
Adding (u) current_president(reagan)
yes

| ?- add(current_president(bush)).
Adding (u) current_president(bush)
Removing current_president(reagan).
yes

% governor(State,Year,Governor)
| ?- add(function(governor,3)).
Adding (u) function(governor,3)
Adding governor(A,B,C),{governor(A,B,D),C\==D}=> ~governor(A,B,D)
yes

| ?- add(governor(pennsylvania,1986,thornburg)).
Adding (u) governor(pennsylvania,1986,thornburg)
yes

| ?- add(governor(pennsylvania,1987,casey)).
Adding (u) governor(pennsylvania,1987,casey)
yes

% oops, we misspelled thornburgh!
| ?- add(governor(pennsylvania,1986,thornburgh)).
Adding (u) governor(pennsylvania,1986,thornburgh)
Removing governor(pennsylvania,1986,thornburg).
yes
\end{verbatim}\end{quote}

\subsection{Spreadsheets}

One common kind of constraints is often found in spreadsheets in
which one value is determined from a set of other values in which the
size of the set can vary.  This is typically found in spread sheets
where one cell can be defined as the sum of a column of cells.  This
example shows how this kind of constraint can be defined in \pfc\ as well.
Suppose we have a relation \prolog{income/4} which records a person's
income for a year by source.  For example, we might have assertions like:
\example
income(smith,salary,1989,50000).
income(smith,interest,1989,500).
income(smith,dividends,1989,1200).
income(smith,consulting,1989,2000).
\end{verbatim}\end{quote}
We might also with to have a relation \prolog{total\_income/3} which
records a person's total income for each year.  Given the database
above, this should be:
\example
total_income(smith,1989,53700).
\end{verbatim}\end{quote}

One way to do this in \pfc\ is as follows:
\example
income(Person,Source,Year,Dollars) => {increment_income(Person,Year,Dollars)}.

=> pfcUndoMethod(increment_income(P,Y,D),decrement_income(P,Y,D)).

increment_income(P,Y,D) :-
  (retract(total_income(P,Y,Old)) -> New is Old+D ; New = D),
  assert(total_income(P,Y,New)).

decrement_income(P,Y,D) :-
  retract(total_income(P,Y,Old)),
  New is Old-D,
  assert(total_income(P,Y,New)).
\end{verbatim}\end{quote}
We would probably want to use the \pfc\ rule for maintaining
functional Dependencies described in Section~\ref{sec:funcdep} as
well, adding the rule:
\example
=> function(income,4).
\end{verbatim}\end{quote}

\subsection{Extended Reasoning Capability}

The truth maintenance system in \pfc\ makes it possible to do some
reasoning that Prolog does not allow.  From the facts
\begin{quote}
$p \vee q$ \\
$p \rightarrow r$ \\
$q \rightarrow r$ \\
\end{quote}
it follows that $r$ is true.  However, it is not possible to directly
encode this in Prolog so that it can be proven.  We can encode these
facts in \pfc\ and use a simple proof by contradiction strategy
embodied in the following Prolog predicate:
\example
prove_by_contradiction(P) :- P.
prove_by_contradiction(P) :-
  \+ (not(P) ; P)
  add(not(P)),
    P       -> rem(not(P))
  otherwise -> (rem(not(P)),fail).
\end{verbatim}\end{quote}
This procedure works as follows.  In trying to prove P, succeed
immediately if P is a know fact.  Otherwise, providing that
\prolog{not(P)} is not a know fact, add it as a fact and see if this
gives rise to a proof for \prolog(P).  if it did, then we have derived
a contradiction from assuming that \prolog{not(P)} is true and
\prolog{P} must be true.  In any case, remove the temporary assertion
\prolog{not(P)}.

In order to do the example above, we need to add the following rule or
\prolog{or} and a rule for general implication (encoded using the
infix operator \prolog{==>}) which generates a regular forward
chaining rule and its counterfactual rule.
\example
:- op(1050,xfx,('==>')).

(P ==> Q) =>
  (P => Q),
  (not(Q) => not(P)).

or(P,Q) =>
  (not(P) => Q),
  (not(Q) => P).
\end{verbatim}\end{quote}
With this, we can encode the problem as:
\example
=> or(p,q).
=> (p ==> x).
=> (q ==> x).
\end{verbatim}\end{quote}

When these facts are added, the following trace ensues:
\example
Adding (u) (A==>B)=>(A=>B), (not(B)=>not(A))
Adding (u) or(A,B)=>(not(A)=>B), (not(B)=>A)
Adding (u) or(p,q)
Adding not(p)=>q
Adding not(q)=>p
Adding (u) p==>x
Adding p=>x
Adding not(x)=>not(p)
Adding (u) q==>x
Adding q=>x
Adding not(x)=>not(q)
\end{verbatim}\end{quote}

Then, we can call \prolog{prove\_by\_contradiction/1} to show that
\prolog{p} must be true:
\example
| ?- prove_by_contradiction(x).
Adding (u) not(x)
Adding not(p)
Adding q
Adding x
Adding not(q)
Adding p
Removing not(x).
Removing not(p).
Removing q.
Removing not(q).
Removing p.
Removing x.
yes
\end{verbatim}\end{quote}

% \subsection{Parsing}


\section{Mutable variables}

\begin{frame}
  \frametitle{Introduction}

  All the languages we have seen so far belong to the realm of
  \emph{functional} programming language.
  %
  In particular, in these languages variables are \emph{immutable}.

  \bigskip

  In this lecture, we study language $\lggeW$, a small \emph{imperative}
  programming language with \emph{mutable} variables
\end{frame}

\begin{frame}
  \frametitle{Language \lggeW}
  %
  %
  Let $\VARS$ be a set of variables,
  %
  $n \in \naturals$, $t \in \{\ktrue,\kfalse\}$, and $\var{x} \in \VARS$.
  %
  \[
  \begin{array}{llclll}
    \AEXPS & a & \Coloneqq & n \bnfsep \var{x} \bnfsep a_1 + a_2 \bnfsep a_1 * a_2
    & \text{Arith.\ exp.\ }
    \\
    \\
    \BEXPS & b  & \Coloneqq
                           & t \bnfsep b_1 \land b_2 \bnfsep \neg b \bnfsep a_1 \leq a_2
    & \text{Bool.\ exp.\ }
    \\
    \\
    \STMTS  & s & \Coloneqq & \sskip & \text{no nop}
    \\
           &&& {s_1 ; s_2} & \text{sequence}
    \\
           &&& \cset{x}{a} & \text{assign}
    \\
           &&&  \csite{b}{s_1}{s_2} & \text{if-then-else}
    \\
           &&&  \cwhile{b}{s} & \text{while}
  \end{array}
  \]
\end{frame}

\begin{frame}
  \frametitle{Dynamics -- big step semantics}
  %
  $\Sigma$ represents the memory, formally, it's a map
  $\Sigma : \VARS \rightarrow \naturals$ from variable names to
  (positive) integers.
  %
  \[
  \semrule
  {}
  {\,}
  {\bsjudge{\wconf{\Sigma}{n}}{n}}
  \qquad\qquad
  \semrule
  {}
  {\,}
  {\bsjudge{\wconf{\Sigma}{\var{x}}}{\Sigma(\var{x})}}
  \]

  \[
  \semrule
  {}
  {
    \bsjudge{\wconf{\Sigma}{a_1}}{n_1}
    \and
    \bsjudge{\wconf{\Sigma}{a_2}}{n_2}
    \and
    n_1 + n_2 = n
  }
  {\bsjudge{\wconf{\Sigma}{a_1 + a_2}}{n}}
  \]

  and similarly for other operators and for Boolean expressions.

\end{frame}

\begin{frame}
  \frametitle{Dynamics -- sequencing}
  \[
  \semrule
  {\wsemrulename{set}}
  {\bsjudge{\wconf{\Sigma}{a}}{n}}
  {
    \jtrans
    {\wconf{\Sigma}{\cset{x}{a}}}
    {\wconf{\upmap{\Sigma}{x}{n}}{\sskip}}
  }
  \]

  \[
  \semrule
  {\wsemrulename{skip}}
  {\,}
  {
    \jtrans
    {\wconf{\Sigma}{\sskip ; s}}
    {\wconf{\Sigma}{s}}
  }
  \]

  \[
  \semrule
  {\wsemrulename{seq}}
  { \jtrans
    {\wconf{\Sigma}{s_1}}
    {\wconf{\Sigma}{s'_1}}
  }
  {
    \jtrans
    {\wconf{\Sigma}{s_1 ; s_2}}
    {\wconf{\Sigma}{s'_1 ; s_2}}
  }
  \]

\end{frame}

\begin{frame}
  \frametitle{Dynamics}
  \[
  \semrule
  {\wsemrulename{ift}}
  {\bsjudge{\wconf{\Sigma}{b}}{\ktrue}}
  {
    \jtrans
    {\wconf{\Sigma}{\csite{b}{s_1}{s_2}}}
    {\wconf{\Sigma}{s_1}}
  }
  \]

  \[
  \semrule
  {\wsemrulename{iff}}
  {\bsjudge{\wconf{\Sigma}{b}}{\kfalse}}
  {
    \jtrans
    {\wconf{\Sigma}{\csite{b}{s_1}{s_2}}}
    {\wconf{\Sigma}{s_2}}
  }
  \]

  %
  \[
  \hspace{0.5cm}
  \semrule
  {\wsemrulename{w}}
  {\,}
  {
    \jtrans
    {\wconf{\Sigma}{\cwhile{b}{s}}}
    {\wconf{\Sigma}{
        \csite
        {b}
        {(s; \cwhile{b}{s})}
        {\sskip}
      }
    }
  }
  \]

\end{frame}

% \begin{frame}
%   \frametitle{Statics}
%   \[
%   \tyrule
%   {\wtyrulename{e}}
%   {\,}
%   {\wejudge{\Gamma}{\Sigma}{\ebool{\ktrue}}{\ebool{}}}
%   \]

% \[
% \tyrule
% {\wtyrulename{skip}}
% {\,}
% {\wsjudge{\Gamma}{\Sigma}{\sskip}}
% \]

%   \[
%   \tyrule
%   {\wtyrulename{ite}}
%   {
%     \wejudge{\Gamma}{\Sigma}{e}{\ebool{}}
%     \and
%     \wsjudge{\Gamma}{\Sigma}{s_1}
%     \and
%     \wsjudge{\Gamma}{\Sigma}{s_2}
%   }
%   {
%     \wsjudge{\Gamma}{\Sigma}{\site{e}{s_1}{s_2}}
%   }
%   \]
% \end{frame}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\chapter{   Machine Learning}
% CHAPTER SETTINGS
\graphicspath{{./images/machine_learning/}}

\section{xx}

\subsection{Explaing bagging}
Known more formally as Bootstrapped Aggregation is where the same algorithm has different perspectives on the problem by being trained on different subsets of the training data.

\subsection{Explaing boosting}
Different algorithms are trained on the same training data.

\subsection{Explaing blending}
Known more formally as Stacked Generalization or Stacking is where a variety of models whose predictions are taken as input to a new model that learns how to combine the predictions into an overall prediction.


\section{Vibration based SHM though DL}
The vibration-based approach for damage assessment using ML techniques has been investigated thoroughly  for several SHM applications.
Furthermore, introducing DL techniques for data-driven SHM applications has presented new scopes for investigating large scale structures and enhanced the process of data acquisition and processing of large datasets acquired by sensors of different types~\cite{Carden2004,Sohn1996}.
Generally, the conventional approach for damage localisation requires prior knowledge of the approximate damage locations~\cite{Xu2018,Dorafshan2016}.
Therefore, the identification process regarding candidates for the damaged locations is complex and can consume plenty of time.
Damage locations identification under the vibrational approach is based on the fact that the damage cause changes in the vibration characteristics such as modal shapes, frequencies, and damping~\cite{Doebling},
which can be utilised in the identification of damaged locations from the registered data response of a structure.
A vibration-based approach can be categorised into two classes:
model-based (parametric) and non-model-based or (non-parametric).
Parametric methods require computational models and associated assumptions about the investigated structure.
In general parametric methods can achieve good accuracy, however, there is no guarantee regarding the availability of accurate information about the structural system in the real-world~\cite{Azimi2020}.
As a result, the non-parametric methods arise due to the challenges in developing robust computational models.
With non-parametric methods, there are no prior assumptions about the structural system.
%ML techniques contributed to both of these categories.
%They are usually used to extract the modal parameters in the scope of non-model-based methods [43,44].
%The traditional ML methods involve two phases in non-model-based methods.
%The first phase is feature extraction, in which sensor data (e.g., acceleration) are used to extract effective features, thereby eliminating the cumbersome manual feature extraction process.
%The second phase is a classification procedure that identifies the location
%and/or level of damage [45].
%Support Vector Machines (SVM), Probabilistic ANNs (PNN) [46–48], Fuzzy ANNs (FNN) [49], and Extreme Learning Machine Networks (e.g., online sequential) [50] are some of the popular methods that are used for vibration-based SHM.

In the following, several vibration-based for SHM using DL techniques are presented.
Authors in~\cite{Abdeljaber2017} introduced a damage identification approach based on output-only response data.
In which, various damage cases (loose bolt) were investigated, accordingly training data were generated based on the acceleration response.
Authors in this approach have trained several CNNs separately regarding each damage case, and accordingly, the probability of damage (PoD) was determined.
By investigating scenarios of undamaged, single damage and multiple damage cases, they obtained \(0.54\%\) average error for specifically identified cases.

Authors in~\cite{Lin2017} introduced a new approach to structural damage detection using CNN.
Moreover, the authors have developed a numerical model of simply supported Euler Bernoulli beam.
The detection model was designed to learn features and to identify damaged locations, moreover, it led to excellent results regarding the accuracy of damaged locations on the noise-free and noisy dataset.
Wang and Cha in~\cite{Cha2018} proposed an unsupervised CNN model, that is able to extract the feature representations from the unlabelled data.
The authors in their model used raw acceleration signals (sensitive to the damage presence) that were acquired from an intact lab-scale steel bridge.
Then, the acquired response vector was normalised followed by applying the continuous wavelet transform (CWT) and fast Fourier transform (FFT).
The output was then fed into a CNN auto-encoder,
Accordingly, the extracted damage features were fed into one-class (OC) SVMs as novelty detectors corresponding to the sensors.
Consequently, the approximation of damage location (loose-bolt) was estimated based on the locations of the sensors with the highest novelty rates.

Motivated by human vision and thinking, authors in~\cite{Cha2018} presented a computer vision and deep-learning framework for anomaly detection.
The proposed approach consists of two steps.
In the first step, data conversion by data visualisation is carried out, in which it mimics human vision and thinking.
In data visualisation,  the registered data response of acceleration is transformed into images plotted in gray-scale.
In the second step, the training dataset is labeled manually, then fed into deep convolutional neural networks (DCNNs).
The proposed technique was tested on one-year data and achieved a global accuracy of \(87,0\%\) and it could be used for real-time SHM.
Moreover, Tang et al. in~\cite{Tang2019} presented a DL technique for data anomaly detection which can be considered as an improved technique to the previous work in~\cite{Cha2018}.
Initially, the raw time series measured data are split into segments, and data in the time and frequency domain are visualised.
Images related to each section are stacked as a single dual-channel (red and green).
Then, the training dataset is fed into a CNN that learns how to perform data anomaly classification.
The main difference between the previous approach and this approach was in using imbalanced data in which the number of samples of different classes was unequal, however, in this approach the used data were balanced.
Finally, the comparison shows that this approach outperformed the previous one and achieved higher accuracy for all data anomaly patterns.

Authors in~\cite{Wu2019} presented a study of the deep CNN method in estimating the dynamic response of a linear single-degree-of-freedom (SDOF) system, a nonlinear SDOF, and a multidegree of freedom (MDOF) streel frame.
In some cases, the convolutional kernel can approximate the numerical integration operator, and the convolutional layer can be interpreted as a dominant frequency extraction operator.
Moreover, different cases of noise-contaminated signals were investigated.
Additionally, MLP method was used as a reference to the proposed CNN approach.
A comparison between the results obtained by the MLP and CNN shows that the CNN approach is more accurate and robust against noisy input data.

Authors in ~\cite{Oh2019}  presented a study of the CNN technique for SHM application for response estimation of tall buildings under wind excitation.
The proposed CNN model was trained on measured structural response data which take wind data measured as inputs in order to predict strains in future wind loads.
In order to measure the performance of the proposed technique, it was verified with unseen data never used at the training phase and it was able to accurately estimate the maximum and minimum strains.
Authors in~\cite{Li2020} proposed a CNN model for damage detection of a bridge structure.
Moreover, the authors compared the performance of the CNN model with other techniques such as random forest, SVM, KNN, and decision tree, and the results showed that the accuracy was enhanced by at least \(15\%\).

Since the acceleration response signal is highly prone to noise~\cite{Azimi2020}, researchers begin utilising other types of sensor data or use alternative features.
Li et al. in ~\cite{Li2020a} investigated damage in bridge structure accordingly, proposed a supervised learning technique based on the CNN model.
Dataset was acquired by deflection of a scaled-down model bridge by a fibre-optic gyroscope.
Then, the dataset was fed into a 1D-CNN model to classify three states of damage and an intact class (benchmark/damage-free).
To investigate the performance of the proposed model, a cross-validation technique was applied.
It showed that the accuracy of the CNN model increased by at least \(15.3\%\) over other conventional methods such as SVM, KNN, decision trees, and random forests.
Authors in \cite{Lopez-Pacheco2020} introduced a novel frequency-domain convolutional neural network (FDCNN) for damage detection based on Bouc-Wen hysteric model~\cite{Ismail2009}.
In the FDCNN method utilises only acceleration measurements for damage diagnosis, that are sensitive to environmental noise.
Moreover, FDCNN reduces the computational time during the learning process, which increase noise robustness.
The FDCNN introduced the spectral pooling operator responsible for attenuating the noise in measurements.
The proposed method was validated through comparing it with different CNN model.
The performance of the proposed method was higher regarding damage identification in building structures.

Finally, with smart monitoring as a target, authors in~\cite{Hung2020}  proposed a hybrid deep learning model for damage detection for SHM.
The proposed model can deal with different damage levels and accurately detect damage by combining 1D-CNN and Long-Short Term Memory (LSTM) into a single end-to-end model fed by the raw time-series, and as a result, avoiding signal preprocessing step.
Moreover, the proposed model verified that with low noise levels,  accurate damage detection can be achieved.


% Created 2017-11-16 Thu 21:40
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\usepackage{helvet}
\usepackage{xcolor}
\definecolor{lgray}{rgb}{0.90,0.90,0.90}
\usetheme{Boadilla}
\usecolortheme{seahorse}
\author{Dale J. Barr}
\date{University of Glasgow}
\title{Research Cycle 08: General Linear Model}
\hypersetup{
 pdfauthor={Dale J. Barr},
 pdftitle={Research Cycle 08: General Linear Model},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 24.5.1 (Org mode 8.3.4)},
 pdflang={English}}
\begin{document}

\maketitle

\section*{Slides}
\label{sec:org209b55c}

\begin{frame}[label={sec:org519e389}]{What is the ``General Linear Model'' (GLM)?}
\begin{definition}[General Linear Model or GLM]
A general mathematical framework for expressing relationships
among variables
\end{definition}

\begin{itemize}
\item Differs from the ``cookbook'' approach to statistics

\begin{itemize}
\item \(t\)-test, ANOVA, ANCOVA, \(\chi^2\) test, regression, correlation, etc.
\end{itemize}

\item Can express/test linear relationships between a numerical dependent
variable and any combination of independent variables (categorical
or continuous)

\item Can even be generalized to categorial dependent variables (through
``Generalized Linear Models''; \alert{NB}: advanced)
\end{itemize}
\end{frame}

\begin{frame}[label={sec:org5caa19b}]{ANOVA, Regression, ANCOVA}
\begin{columns}
\begin{column}[t]{.33\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/CholesterolByEthnic.png}

\begin{center}\begin{scriptsize}
Fig 1a.  Cholesterol levels by ethnic group and gender (male=sqr, female=tri).
\end{scriptsize}\end{center}
\end{column}

\begin{column}[t]{.33\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/CholesterolByAge.png}

\begin{center}\begin{scriptsize}
Fig 1a.  Cholesterol levels by age.
\end{scriptsize}\end{center}
\end{column}

\begin{column}[t]{.34\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/CholesterolByGenderAge.png}

\begin{center}\begin{scriptsize}
Fig 1a.  Cholesterol levels by age and gender.
\end{scriptsize}\end{center}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org39d43bb}]{How the GLM represents relationships}
\begin{center}
\begin{tabular}{ll}
\hline
Component of GLM & Notation\\
\hline
DV & \(Y\)\\
Grand Average & \(\mu\) ``mu''\\
Main Effects & \(A, B, C, \ldots\)\\
Interactions & \(AB, AC, BC, ABC, \ldots\)\\
Random Error & \(S(Group)\)\\
\hline
\end{tabular}
\end{center}

\begin{scriptsize}
\begin{tabular}{c@{\hspace{6pt}}@{=}@{\hspace{6pt}}c@{\hspace{6pt}}@{+}@{\hspace{6pt}}c@{\hspace{6pt}}@{+}@{\hspace{6pt}}c@{\hspace{6pt}}@{+}@{\hspace{6pt}}c}
Score & Grand Avg. & Main Effects    & Interactions          & Error\\
  $Y$ & $\mu$         & $A+B+C+ \ldots$ & $AB+AC+BC+ABC+\ldots$ & $S(Group)$ \\
\end{tabular}
\end{scriptsize}

\begin{itemize}
\item Components of the model are estimated from the observed data
\item Tests are performed ( \(F\) ) to see whether its variability is too large to be introduced by chance
\end{itemize}
\end{frame}

\begin{frame}[label={sec:org7b16a49}]{An example: Simple Linear Regression}
\begin{columns}
\begin{column}{.4\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/satisfaction.png}
\end{column}
\end{columns}

\begin{center}
\begin{tabular}{c@{\hspace{6pt}}@{=}@{\hspace{6pt}}c@{\hspace{6pt}}@{+}@{\hspace{6pt}}c@{$\times$}c@{\hspace{6pt}}@{+}@{\hspace{6pt}}c}
 $Y_i$   & $\mu$    & $b$   & $X_i$   & $e_i$   \\
 Score_i & Baseline & Slope & Hours_i & Error_i \\
 $Y_i$   & $50$     & $3$   & $X_i$   & $e_i$   \\
\end{tabular}

$e_i \sim N(\mu=0, \sigma^2=10)$
\end{center}
\end{frame}

\section*{One-Factor Analysis of Variance}
\label{sec:orgc2d4fee}

\begin{frame}[label={sec:org378e3be}]{Making comparisons across groups}
\begin{example}[Spelling]
You wish to compare the benefits of three different spelling programs.  Do
these programs yield differences in spelling performance?
\end{example}

\(H_0: \mu_1 = \mu_2 = \mu_3\)

\begin{alertblock}{Factors and Levels}
Factor: a categorical variable that is used to divide subjects into
groups, usually to draw some comparison.  Factors are composed of
different \emph{levels}.  \alert{Do not confuse factors with levels!}
\end{alertblock}
\end{frame}

\begin{frame}[label={sec:org3a09c0a}]{Means, Variability, and Deviation Scores}
\begin{columns}
\begin{column}{.3\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/spelling-00.pdf}
\end{column}

\begin{column}{.7\columnwidth}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org7555801}]{Means, Variability, and Deviation Scores}
\begin{columns}
\begin{column}{.3\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/spelling-01.pdf}
\end{column}

\begin{column}{.7\columnwidth}
\(Y_{..} = \frac{\sum_{ij} Y_{ij}}{N}\)
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:orgdc8b882}]{Means, Variability, and Deviation Scores}
\begin{columns}
\begin{column}{.3\columnwidth}
\includegraphics[width=.9\linewidth]{08_glm_img/spelling-02.pdf}
\end{column}

\begin{column}{.7\columnwidth}
grand mean $Y_{..} = \frac{\sum_{ij} Y_{ij}}{N}$\\[6pt]
$SD_Y = \sqrt{\frac{\sum_{ij} \left(Y_{ij}-Y_{..}\right)^2}{N}}$\\[6pt]
deviation score: $Y_{ij} - Y_{..}$
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:orga7d2341}]{GLM for One-Factor ANOVA}
\begin{columns}
\begin{column}{.3\columnwidth}
\only<1| handout:0>{\includegraphics[scale=.5]{08_glm_img/spelling-01.pdf}}
\only<2| handout:0>{\includegraphics[scale=.5]{08_glm_img/spelling-03.pdf}}
\only<3-| handout:1>{\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}}
\end{column}

\begin{column}[t]{.7\columnwidth}
\only<1| handout:0>{$Y_{ij} = \mu$\\}
\only<2| handout:0>{$Y_{ij} = \mu + A_i$\\}
\only<3-| handout:1>{$Y_{ij} = \mu + A_i + S(A)_{ij}$\\}

\begin{block}<4->{Estimation Equations}
\begin{eqnarray*}
\hat{\mu} &=& Y_{..} \\
\hat{A_i} &=& Y_{i.}-\hat{\mu}\\
\widehat{S(A)}_{ij} &=& Y_{ij} - \hat{\mu} - \hat{A_i}
\end{eqnarray*}
\end{block}

\only<4->{Note that $\sum_{i} \hat{A_i} = 0$ and $\sum_{ij} \widehat{S(A)}_{ij} = 0$}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:orgfb5bcf0}]{Sources of Variance}
\begin{columns}
\begin{column}{.3\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.7\columnwidth}
\(Y_{ij} = \mu + A_i + S(A)_{ij}\)

\begin{eqnarray*}
Y_{ij}-\mu &=& A_i + S(A)_{ij}\\
individual &=& group + random
\end{eqnarray*}

\begin{block}{Sum of Squares (SS)}
A measure of variability consisting of the sum of squared \emph{deviation}
scores, where a deviation score is a score minus a mean.
\end{block}

\(SS_{A} = \sum \left(Y_{i.}-\mu\right)^2\)
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org79855a1}]{Decomposition Matrix}
\begin{columns}
\begin{column}{.25\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.75\columnwidth}
\begin{center}
\begin{scriptsize}
$\hat{\mu}=100$

$\hat{A_1}=120-100=20$

$\hat{A_2}=97-100=-3$

$\hat{A_3}=83-100=-17$
\end{scriptsize}
\end{center}

\begin{center}
\begin{scriptsize}
\begin{tabular}{rr@{\hspace{6pt}}@{=}@{\hspace{6pt}}r@{\hspace{6pt}}@{+}@{\hspace{6pt}}r@{\hspace{6pt}}@{+}@{\hspace{6pt}}r}
&$Y_{ij}$ & $\hat{\mu}$ & $\hat{A_i}$ & $\widehat{S(A)}_{ij} \\ \hline
&124 & 100 &  20 &  4 \\
&129 & 100 &  20 &  9 \\
&115 & 100 &  20 & -5 \\
&112 & 100 &  20 & -8 \\
&101 & 100 &  -3 &  4 \\
& 88 & 100 &  -3 & -9 \\
&107 & 100 &  -3 & 10 \\
& 92 & 100 &  -3 & -5 \\
& 76 & 100 & -17 & -7 \\
& 91 & 100 & -17 &  8 \\
& 84 & 100 & -17 &  1 \\
& 81 & 100 & -17 & -2 \\ \hline
$SS=$ & 123318 & 120000 & 2792 & 526 \\
\end{tabular}
\end{scriptsize}
\end{center}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org6e0477a}]{Logic of ANOVA}
\begin{columns}
\begin{column}{.25\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.75\columnwidth}
\begin{itemize}
\item Compare two estimates of the variability, the \emph{between-group}
estimate (SS\_\{between\}) and the \emph{within-group} estimate (SS\_\{within\})
\item If \(H_0: \mu_1=\mu_2=\mu_3\) is true, then these two measures
estimate the same quantity.
\item The extent to which the between-group variability exceeds the
within-group variability gives evidence against \(H_0: \mu_1=\mu_2=\mu_3\).
\end{itemize}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org8d4ad61}]{Calculating SS\_\{between\} and SS\_\{within\}}
\begin{columns}
\begin{column}{.25\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.75\columnwidth}
\begin{center}
\begin{scriptsize}
\begin{tabular}{rr@{\hspace{6pt}}@{=}@{\hspace{6pt}}r@{\hspace{6pt}}@{+}@{\hspace{6pt}}r@{\hspace{6pt}}@{+}@{\hspace{6pt}}r}
&$Y_{ij}$ & $\hat{\mu}$ & $\hat{A_i}$ & $\widehat{S(A)}_{ij} \\ \hline
&124 & 100 &  20 &  4 \\
&129 & 100 &  20 &  9 \\
&115 & 100 &  20 & -5 \\
&112 & 100 &  20 & -8 \\
&101 & 100 &  -3 &  4 \\
& 88 & 100 &  -3 & -9 \\
&107 & 100 &  -3 & 10 \\
& 92 & 100 &  -3 & -5 \\
& 76 & 100 & -17 & -7 \\
& 91 & 100 & -17 &  8 \\
& 84 & 100 & -17 &  1 \\
& 81 & 100 & -17 & -2 \\ \hline
$SS=$ & 123318 & 120000 & 2792 & 526 \\
\end{tabular}
\end{scriptsize}
\end{center}

\begin{alertblock}{check your math}
\(SS_Y=SS_{\mu}+SS_A+SS_{S(A)}\)
\end{alertblock}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org78258d4}]{\(H_0\) and Sums of Squares}
\begin{columns}
\begin{column}{.27\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.73\columnwidth}
\(Y_{ij} - \mu = A_i + S(A)_{ij}\)

\begin{block}{Scenario A}
\(SS_{A} = 2792\)

\(SS_{S(A)}=526\)

\(SS_{A} + SS_{S(A)}=3318\)
\end{block}

\begin{block}{Scenario B}
\(SS_{A} = 266\)

\(SS_{S(A)}=3052\)

\(SS_{A} + SS_{S(A)}=3318\)
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org99e0600}]{Mean Square and Degrees of Freedom}
\begin{columns}
\begin{column}{.27\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.73\columnwidth}
\begin{block}{Degrees of Freedom (df)}
The number of observations that are ``free to vary''.

\(df_{A} = K-1\)

\(df_{S(A)} = N-K\)

where \(N\) is the number of subjects and \(K\) is the number of groups.
\end{block}

\begin{block}{Mean Square (MS)}
A sum of squares divided by its degrees of freedom.

\(MS_A = \frac{SS_A}{df_A} = \frac{2792}{2} = 1396\)

\(MS_{S(A)} = \frac{SS_{S(A)}}{df_{S(A)}} = \frac{526}{9} = 58.4\)
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:orge81a0ef}]{The \(F\)-ratio}
\begin{columns}
\begin{column}{.4\columnwidth}
\begin{block}{F density function}
\includegraphics[width=.9\linewidth]{f-ratio.pdf}

If \(F_{obs} > F_{crit}\), then reject \(H_0\)
\end{block}
\end{column}

\begin{column}{.58\columnwidth}
\begin{block}{F ratio}
A ratio of mean squares, with df\_\{numerator\} and df\_\{denominator\} degrees of freedom.

\(F_A = \frac{MS_A}{MS_{S(A)}} = \frac{1396}{58.4} = 23.886\)
\end{block}

\includegraphics[width=.9\linewidth]{08_glm_img/ftable.jpg}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile,label={sec:org2c33abb}]{Density/Quantile functions for \emph{F}-distribution}
 \begin{small}

\begin{center}
\begin{tabular}{ll}
name & function\\
\hline
\texttt{pf(x, df1, df2, lower.tail = FALSE)} & density (get \(p\) given \(F_{obs}\))\\
\texttt{qf(p, df1, df2, lower.tail = FALSE)} & quantile (get \(F_{crit}\) given \(p\))\\
\hline
\end{tabular}
\end{center}

\end{small}
\end{frame}

\begin{frame}[label={sec:org4be8ac6}]{Summary Table}
\begin{columns}
\begin{column}{.27\columnwidth}
\includegraphics[scale=.5]{08_glm_img/spelling-05.pdf}
\end{column}

\begin{column}{.73\columnwidth}
\begin{block}{Scenario A}
\begin{scriptsize}
\begin{center}
\begin{tabular}{lrrrrrl}
\hline
Source & \(df\) & \(SS\) & \(MS\) & \(F\) & \(p\) & Error\\
\hline
\(\mu\) & 1 & 120000 & 120000.0 & 2053.232 & <.001 & \(S(A)\)\\
\(A\) & 2 & 2792 & 1396.0 & 23.886 & <.001 & \(S(A)\)\\
\(S(A)\) & 9 & 526 & 58.4 &  &  & \\
\hline
Total & 12 & 123318 &  &  &  & \\
\hline
\end{tabular}
\end{center}
\end{scriptsize}
\end{block}

\begin{block}{Scenario B}
\begin{scriptsize}
\begin{center}
\begin{tabular}{lrrrrrl}
\hline
Source & \(df\) & \(SS\) & \(MS\) & \(F\) & \(p\) & Error\\
\hline
\(\mu\) & 1 & 120000 & 120000.0 & 353.878 & <.001 & \(S(A)\)\\
\(A\) & 2 & 266 & 133.0 & .392 & .687 & \(S(A)\)\\
\(S(A)\) & 9 & 3052 & 339.1 &  &  & \\
\hline
Total & 12 & 123318 &  &  &  & \\
\hline
\end{tabular}
\end{center}
\end{scriptsize}
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile,label={sec:orgb0a9f55}]{Overview of One-Way ANOVA}
 \begin{columns}
\begin{column}{.52\columnwidth}
\begin{scriptsize}
\begin{enumerate}
\item Write the GLM: \(Y_{ij} = \mu + A_i + S(A)_{ij}\)
\item Write down the estimating equations:
\begin{itemize}
\item \(\hat{\mu} = Y_{..}\)
\item \(\hat{A_i} = Y_{i.}-\hat{\mu}\)
\item \(\widehat{S(A)_{ij}} = Y_{ij}-\hat{\mu}-\hat{A_i}\)
\end{itemize}
\item Compute estimates for all terms in model.
\item Create \emph{decomposition matrix.}
\item Compute \(SS\), \(MS\), \(df\).
\begin{itemize}
\item \(df_{\mu}=1\)
\item \(df_{A}=K-1\)
\item \(df_{S(A)}=N-K\)
\item \(MS=SS/df\)
\end{itemize}
\item Construct a summary ANOVA table.
\item Compare F\_\{obs\} with F\_\{crit\}.
\end{enumerate}
\end{scriptsize}
\end{column}

\begin{column}{.45\columnwidth}
\begin{block}{R}
use the \texttt{aov()} function, e.g.:

\begin{minted}[frame=lines,fontsize=\scriptsize,linenos,tabsize=2]{r}
spelling$A <- factor(spelling$A)
mod <- aov(Y ~ A, data = spelling)
summary(mod)
\end{minted}

\begin{tiny}

\url{http://talklab.psy.gla.ac.uk/stats/onefactoranova.html#sec-3-2}

\end{tiny}
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org8c29850}]{Other GLMs}
\begin{itemize}
\item one-sample \(t\)-test
\(Y_i - c = \beta_0 + e_i\)

\item two-sample \(t\)-test
\(Y_i = \beta_0 + \beta_1 X_i + e_i\)
\begin{itemize}
\item where \(X_i \in \left(0, 1\right)\)
\end{itemize}

\item paired-samples t-test
\(Y_{1i} - Y_{2i} = \mu + e_i\)

\item simple linear regression
\(Y_{i} = \beta_0 + \beta_1 X_i + e_i\)

\item multiple regression
\(Y_{i} = \beta_0 + \beta_1 X_{1i} + \beta_2 X_{2i} + e_i\)

\item ANCOVA
\(Y_{i} = \beta_0 + \beta_1 X_{1i} + \beta_2 X_{2i} + \beta_3 X_{1i} X_{2i} + e_i\)
\begin{itemize}
\item where \(X_{1i} \in \left(0, 1\right)\) and \(X_{2i} \in \mathbb{R}\)
\end{itemize}
\end{itemize}
\end{frame}
\end{document}


\subsection{Primary Expression}

\begin{grammar}
\underbrace{\nonterminal{primary-expression}}_{=:P}
    \produces
	\underbrace{\nonterminal{float-literal}}_{=:F} \\
    \produces
	\lexkeyword{(}
	\underbrace{\nonterminal{additive-expression}}_{=:A}
	\lexkeyword{)}\\
\end{grammar}

\paragraph{Item automata for P}
\[
\begin{tikzpicture}[
    every text node part/.style={align=center},
    initial text =
]
    \node[state,initial]
	(S)[rounded rectangle, draw]
	{
	    {$[U\to .F]$} \\
	    {$[U\to .(A)]$}
	};
    \node[state]
	(LP)[rounded rectangle, draw,below right=2em and 5em of S]
	{
	    {$[U\to (.A)]$}
	};
    \node[state]
	(A)[rounded rectangle, draw,right=of LP]
	{
	    {$[U\to (A.)]$}
	};
    \node[state,accepting]
	(E)[rounded rectangle, draw,above right=2em and 5em of A]
	{
	    {$[U\to F.]$} \\
	    {$[U\to (A).]$}
	};
    \path[->] (S) edge  node [above] {F} (E);
    \path[->] (S) edge  node [above] {\lexkeyword{(}} (LP);
    \path[->] (LP) edge  node [above] {A} (A);
    \path[->] (A) edge  node [above] {\lexkeyword{)}} (E);
\end{tikzpicture}
\]