\documentclass[10pt]{article}

\usepackage{fullpage}
\usepackage{setspace}
\usepackage{parskip}
\usepackage{titlesec}
\usepackage[section]{placeins}
\usepackage{xcolor}
\usepackage{breakcites}
\usepackage{lineno}
\usepackage{hyphenat}





\PassOptionsToPackage{hyphens}{url}
\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{%
  \errmessage{\noexpand\@combinedblfloats could not be patched}%
}%
\makeatother


\usepackage{natbib}




\renewenvironment{abstract}
  {{\bfseries\noindent{\abstractname}\par\nobreak}\footnotesize}
  {\bigskip}

\titlespacing{\section}{0pt}{*3}{*1}
\titlespacing{\subsection}{0pt}{*2}{*0.5}
\titlespacing{\subsubsection}{0pt}{*1.5}{0pt}


\usepackage{authblk}


\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{latexsym}
\usepackage{textcomp}
\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs,array,multirow}
\usepackage{amsfonts,amsmath,amssymb}
\providecommand\citet{\cite}
\providecommand\citep{\cite}
\providecommand\citealt{\cite}
% You can conditionalize code for latexml or normal latex using this.
\newif\iflatexml\latexmlfalse
\AtBeginDocument{\DeclareGraphicsExtensions{.pdf,.PDF,.eps,.EPS,.png,.PNG,.tif,.TIF,.jpg,.JPG,.jpeg,.JPEG}}





\usepackage{float}






%%% Your header encountered errors when converting with LaTeXML
%%% Please uncomment it incrementally and check for problems
%%%   If you need assistance, contact us at help@authorea.com
%%% 
%
%\iflatexml
%% \documentclass[num-refs]{wiley-article} % Not (yet) supported by LaTeXML.
%\fi
%\usepackage{graphicx}
%
%\usepackage[space]{grffile}
%
%% \usepackage{latexsym} % Not (yet) supported by LaTeXML.
%
%% \usepackage{textcomp} % Not (yet) supported by LaTeXML.
%
%\usepackage{longtable}
%
%% \usepackage{tabulary} % Not (yet) supported by LaTeXML.
%
%\usepackage{booktabs,array,multirow}
%\usepackage{booktabs,array,multirow}
%\usepackage{booktabs,array,multirow}
%
%\usepackage{amsfonts,amsmath,amssymb}
%\usepackage{amsfonts,amsmath,amssymb}
%\usepackage{amsfonts,amsmath,amssymb}
%
%\usepackage{natbib}
%
%\usepackage{url}
%
%\usepackage{hyperref}
%
%\hypersetup{colorlinks=false,pdfborder={0 0 0}}
%% \usepackage{etoolbox} % Not (yet) supported by LaTeXML.
%
%\makeatletter
%% First macro on next line not (yet) supported by LaTeXML: 
%% \patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{%
%%  \errmessage{\noexpand\@combinedblfloats could not be patched}%
%%}%
%\makeatother
%\newif\iflatexml\latexmlfalse
%\providecommand{\tightlist}[][]{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
%\AtBeginDocument{\DeclareGraphicsExtensions{.pdf,.PDF,.eps,.EPS,.png,.PNG,.tif,.TIF,.jpg,.JPG,.jpeg,.JPEG}}
%\usepackage[utf8]{inputenc}
%
%% \usepackage[english]{babel} % Not (yet) supported by LaTeXML.
%\papertype{Original Article}
%% First macro on next line not (yet) supported by LaTeXML: 
%% \runningauthor{Matteo Cavalleri}


\begin{document}

\title{Supporting Information for ``AI-enabled Micro Motion Sensors for Revealing the Random Daily Activities of Caged Mice''}



\author[1]{Yifan Liu}%
\author[1]{Meng Chen}%
\author[2]{Chishing Chan}%
\author[1]{Ho-yin Chan}%
\author[1]{Jianping Wang}%
\author[1]{Xinge Yu}%
\author[1]{Xinyue Li}%
\author[1]{Wen Jung Li}%
\affil[1]{City University of Hong Kong}%
\affil[2]{CASCUBE Limited}%


\vspace{-1em}



  
  \date{May 30, 2024}


\begingroup
\let\center\flushleft
\let\endcenter\endflushleft
\maketitle
\endgroup





\selectlanguage{english}
\begin{abstract}
This Supporting Information includes:

\emph{{Supplementary text describing Preliminary Status Classifer, segmentation methods, model training and validation details; two supplementary tables, two supplementary figures and one supplementary video.}}

Corresponding author(s) Email:~{ \emph{~{hoychan@cityu.edu.hk; xinyueli@cityu.edu.hk; wenjli@cityu.edu.hk} ~}}%%
\end{abstract}%



\sloppy


\section*{Supplementary Text}

\subsection*{Preliminary Status Classifier}

FFT energy $E_f$ of a signal sequence is defined as follows:
\begin{equation}
E_f=\sum_{i=1}^NF_i^2\label{fft_energy}
\end{equation}
where $F_i$ is the $i^{th}$ amplitude of the Fourier transform of $a_t$ and $N$ is the length of the amplitude array. $a_t$ is the total acceleration, which combines the accelerations in three axes (i.e., x, y, and z) as follows:
\begin{equation}
$a_t$ =\sqrt{a_{xt}^2+a_{yt}^2+a_{zt}^2}\label{acc_t}
\end{equation}
The other parameter \(Var\left(a_t\right)\) is the acceleration variance of the signal sequence, which is expressed as follows:
\begin{equation}
Var\left(a_t\right)=\frac{\sum_{i=1}^n\left(a_{ti}-\overline{a_t}\right)^2}{n} \label{var_at}
\end{equation}
In Equation (\ref{var_at}), $n$ is the length of the acceleration array.

\subsection*{Segmentation Method}
\subsubsection*{Fixed-window Segmentation (FWS)}
The IMU reading of $t^{th}$ sampling is denoted as $x_t$,$x_t$, and all the readings from $1^{st}$ sampling to $t^{th}$ are $X_t$; therefore, the relationship between $x_t$ and $X_t$ is \(X_t=\left\{x_1,\ x_2,\ ...\ x_t\right\}\). Each reading consists of 3-axis acceleration and 3-axis angular velocity, which is expressed as follows:
\begin{equation}
$x_t$=\left[a_{xt},\ a_{yt},\ a_{zt},\ g_{xt},\ g_{yt},\ g_{zt}\right]\label{x_t}
\end{equation}
Then, the segmentation process divides the signal $X_t$ into slices, which is a set of contiguous readings. The slice set is denoted as $S$ and \(s_1,\ s_2\ ...\ s_t\in S\), and the $n^{th}$ slice $s_n$ consisting of the readings between $a^{th}$ and $b^{th}$ is as follows:
\begin{equation}
$s_n$=\left[x_a,\ x_{a+1},\ ...\ x_b\right]\label{slice_n}
\end{equation}
The window size of the $n^{th}$ slice is denoted as $L_n$. Since FWS usually divides raw sensor signals into same-length slices, $L_n$ is a constant value for all slices, denoted as $L$. In CSM, we set $L$ to 1 second, and the readings passed into the FWS is divided into 1-second slices. Since the sampling frequency of our sensor is 25, one FWS slice can contain 25 readings.

\subsubsection*{Probability Density Function Segmentation (PDFS)}
However, not all of the mice behaviors end in or last for 1 second, and the sample length would be less than 1 second. Thus, if a behavior's duration deviates from the length of a predefined fixed window, the quality of the features extracted from that sample would be low, as they could not represent the entire sample. For instance, one of the features is the mean value of accelerations in the x-direction of a slice containing a behavior within a fixed window (e.g., 1 second). If the duration of that behavior is much shorter than 1 second, the slice must contain information of other behavior(s), which would dominate the mean value. Thus, to solve this problem, we design the first Adaptive Window Segmentation (AWS) named the probability density function segmentation (PDFS), which utilizes a probability density function (PDF) with a multivariate Gaussian distribution. The PDF function defines the probability of a reading belonging to a slice and decides whether to extend the slice to include the reading \hyperref[csl:1]{(Mickey \& Rencher, 1998)}.

Due to the uncertainty in the window size and their boundary positions, during the processing, we define the stop boundary point of the previous slice as the changepoint and elapsed time since the last changepoint as the "run". $r_t$ is the length of the current run if it stops at time $t$, and the reading set with run length $r_t$ is \(x_t^{\left(r\right)}\). The PDF for all the readings of the current run \(x_t^{\left(r\right)}\) at time t falls within a particular range, which can be expressed as follows:
\begin{equation}
\(f_n\left(x_t^{\left(r\right)}\right)=\frac{1}{\left(\sqrt{2\pi}\right)^d\cdot\left|\frac{r_t-1}{r_t}K\right|^{\frac{1}{2}}}e^{-\frac{1}{2}}\sum_{_{i=1}}^{r_t}\left(x_i-\mu\right)^T\cdot\frac{r_t}{\left(r_t-1\right)S}\cdot\left(x_i-\mu\right)\)\label{fn_equation}
\end{equation}
First, we define two windows: a base window $W_b$ with a fixed size ($b$) and an expanding window W_e with another fixed size ($e$) that is much smaller than that of the base window. Each run starts from the beginning of a $W_b$, and we first calculate the probability density ($p_1$) of the data in current run. Then, the run is extended by adding one $W_e$ to $W_b$ to form a new temporary segmentation window (\(b + e\)), and the probability density ($p_2$) of current run is calculated. By comparing the two probability density values, the decision of extending the current window is made. If $p_1$ is smaller than $p_2$, the base window is taken as the segmentation window. Otherwise, the extending window is kept. For the next round, the probabilities before and after adding an expanding window will be calculated again for the comparison and determination of the expanding. 

We define the expanding times of the temporary segmentation window as $n_e$, and the run length in PDFS at time $t$ is determined by those three parameters.
\begin{equation}
\(r_t=b+n_e\cdot e\)\label{r_t}
\end{equation}
\subsubsection*{Bayesian OnlineOnline ChangepointChangepoint Detection Detection Segmentation (BOCDS)}
We design the second AWS utilizing one of the popular changepoint detection techniques, the Bayesian Online Changepoint Detection (BOCD). Therefore, this segmentation method is named the Bayesian Online Changepoint Detection Segmentation (BOCDS). It can generate an accurate posterior prediction of the next data point \(x_{t+1}\) in the sequence based on the received sensor readings \(x_{1:t}\), which can be expressed as follows:
\begin{equation}
P\left(x_{t+1}|x_{1:t}\right)=\sum_{r_t}^{ }P\left(x_{t+1}|r_t,\ x_t^{\left(r\right)}\right)\cdot P\left(r_t|x_{1:t}\right)\label{prob_reading}
\end{equation}
The details about the equation derivation are referred to in Adams et al.'s work\hyperref[csl:2]{(Adams \& MacKay, 2007)}. Based on this equation, we could predict the next data point and detect the abrupt change in the signal sequence. We first input the four primary parameters required by the model and set one of the boundaries at the stop point of the last slice. Then, we start to calculate several probabilities, including predictability, growth probability, and changepoint probability, starting from the next point. The related prediction is conducted based on these probabilities. If this point is predicted as the changepoint, the current run would stop at this point; otherwise, the run length would increase, and we would perform a similar step for the next data point. Using the BOCDS, the continuous readings are divided into windows of different sizes in real-time.

\subsubsection*{CSM-1(PSC+FWS+PDFS) \& CSM-2 (PSC+FWS+BOCDS)}
Based on the PSC and three segmentation methods mentioned above, we construct two combined segmentation methods (CSMs). The first CSM consists of the PSC, FWS and PDFS and the second is formed by the PSC, FWS and BOCDS. In the first CSM, PSC decides the readings belongs to static or dynamic behaviors. The static readings are divided into same-size segments in FWS, while the dynamic readings are processed by PDFS. For the second CSM, BOCDS replaces PDFS while keeping other setting same with the first CSM.

\subsection*{Model training and validation}
For model training and validation, the confusion matrix is calculated to evaluate the performance of our trained model, along with another three metrices defined as follows:
\begin{equation}
Recall\left(A\right)=\frac{L_{TP}\left(A\right)}{L_{TP}\left(A\right)+L_{FN}\left(A\right)}\label{recall_a}
\end{equation}
\begin{equation}
Precision\left(A\right)=\frac{L_{TP}\left(A\right)}{L_{TP}\left(A\right)+L_{FP}\left(A\right)}\label{precision_a}
\end{equation}
\begin{equation}
F_1\left(A\right)=\frac{2\cdot Precision\left(A\right)\cdot Recall\left(A\right)}{Precision\left(A\right)+Recall\left(A\right)}\label{f1_a}
\end{equation}

where \(L_{TP}(A)\) is the total time length of the true positive case for behavior $A$, \(L_{FN}(A)\) is the total time length of a false negative error for behavior $A$, and \(L_{FP}(A)\) is the total time length of a false-positive error for behavior A. In the usual classification evaluation, the three metrics are calculated based on the true or false predicted case number. In our case, readings are divided into slices of different lengths with the AWSs. Therefore, we evaluate prediction accuracy based on the time lengths of the correctly and incorrectly classified behaviors.

A high recall value indicates that most of the behavior samples are correctly classified, while a high precision value means the percentage of correct prediction is large among the total related prediction \hyperref[csl:3]{(Powers, 2020)}. To evaluate the overall performance, we calculate the accuracy for the whole training model as follows:
\begin{equation}
Accuracy(total)=\frac{L_{TP}\left(total\right)}{L_{total}}\label{accuracy_total}
\end{equation}
where \(L_{total}\)is the total time length of the validation set and \(L_{TP}\left(total\right)\) is the total time length of all the true positive cases in the validation set. The overall accuracy is the key parameter representing the overall effectiveness and accuracy of a classification system, but this accuracy is highly affected by the ratio of samples between different behaviors. If a dataset is not well-balanced between behaviors, the accuracy is dominated by the behaviors with high numbers of samples. Thus, we adapt the average recall value (macro-recall) $Recall_{avg}$ as the main parameter to represent the model accuracy, which is expressed as follows:
\begin{equation}
\(Recall_{avg}=\frac{1}{M}\sum_{A=1}^MRecall\left(A\right)\)
\end{equation}
where $M$ is the number of behavior types, which equals 8 in our system. As a 4-fold cross validation is employed in this paper to resample our dataset and evaluate our machine learning model, the average recall value among 4-fold could be defined as follows:
\begin{equation}
\(Recall_{4-fold}=\frac{1}{4}\sum_{K=1}^4Recall_{avg-K}\)
\end{equation}
here \(Recall_{avg-K}\) is the macro-recall value of the $K^th$ fold.

\section*{Supplementary Tables}\selectlanguage{english}
\begin{table}[H]
\centering
\normalsize\begin{tabulary}{1.0\textwidth}{CCC}
Behavior & Label & Description \\
Resting & RE & Stay still and motionless \\
Walking & W & Walking around in the cage \\
Rearing & RA & Standing on its hind legs and raise forelimbs from the ground \\
Digging & DI & Using forelimbs to dig material put on the cage bottom \\
 &  & Swings its front legs fast to throw the bedding particles around \\
Eating & E & Eating food placed in cage \\
Grooming & G & Grooming itself to keep clean \\
Drinking water & DW & Drinking water placed in cage \\
Scratching & S & Using hindlimb to scratch its body \\
\end{tabulary}
\caption{{Labels and descriptions for eight common mouse behaviors
{\label{849893}}%
}}
\end{table}\selectlanguage{english}
\begin{table}[H]
\centering
\normalsize\begin{tabulary}{1.0\textwidth}{CC}
Time domain & Frequency domain \\
30 features (6 axes) & 8 features (2 axes) \\
Maximum & DC component \\
Minimum & FFT amplitude peak \\
Variance & FFT entropy \\
Average & FFT energy \\
Root Mean Square &  \\
\end{tabulary}
\caption{{The calculated features in the recognition system.
{\label{319944}}%
}}
\end{table}

\section*{Supplementary Figures}\selectlanguage{english}
\begin{figure}[H]
\begin{center}
\includegraphics[width=1.00\columnwidth]{figures/Mouse-Proj-yifan/Figure-S1}
\caption{{\textbf{Fig. S1. ~}Mouse tracking system hardware setup. (A)
Experimental setup. (B) The collected acceleration and angular velocity
signals
{\label{322443}}%
}}
\end{center}
\end{figure}\selectlanguage{english}
\begin{figure}[H]
\begin{center}
\includegraphics[width=1.00\columnwidth]{figures/Figure-S2/Figure-S2}
\caption{{\textbf{Fig. S2.~~}The working principle of the Combined Segmentation
Method (CSM)
{\label{673767}}%
}}
\end{center}
\end{figure}

\section*{Supplementary Video}


Rich media available at \url{https://drive.google.com/file/d/1p3rGwQ0969xrQChddNo0BshdFSEYHzeH/view?usp=sharing}

\selectlanguage{english}
\FloatBarrier
\section*{References}\sloppy
\phantomsection
\label{csl:1}{Methods of Multivariate Analysis}. (1998). \textit{Journal of the American Statistical Association}, \textit{93}(443), 1239. \url{https://doi.org/10.2307/2669873}

\phantomsection
\label{csl:2}{Bayesian online changepoint detection}. (2007). \textit{ArXiv Preprint ArXiv:0710.3742}.

\phantomsection
\label{csl:3}{Evaluation: from precision, recall and F-measure to ROC, informedness, markedness and correlation}. (2020). \textit{ArXiv Preprint ArXiv:2010.16061}.

\end{document}

