diff --git "a/data_all_eng_slimpj/shuffled/split2/finalzzgfxe" "b/data_all_eng_slimpj/shuffled/split2/finalzzgfxe" new file mode 100644--- /dev/null +++ "b/data_all_eng_slimpj/shuffled/split2/finalzzgfxe" @@ -0,0 +1,5 @@ +{"text":"\n\\section{Conclusion} \\label{sec:concl}\n\n\\noindent This paper presents an automatic HVAC control system, featuring real-time occupancy recognition, dynamic occupancy prediction, and simulation-guided model predictive control, implemented in a low-cost embedded system (Raspberry Pi). We deployed and evaluated our system for providing automatic HVAC control in the large public indoor space of a mosque. Our experiments showed that our real-time occupancy recognition system can reach 90\\% accuracy, whereas our occupancy prediction system can reach 85\\% accuracy. We employ real-time HVAC control guided by an on-board EnergyPlus simulator, which is able to achieve more than 30\\% energy saving while maintaining the comfort level within acceptable range. Importantly, our system is sufficiently general and can be deployed in other types of buildings with large public indoor spaces.\n\nNotably, we ported the EnergyPlus simulator to the Raspberry Pi embedded system platform. We release our Raspberry Pi version of EnergyPlus publicly \\cite{eplus_rpi} to enable other researchers to take advantage of our work for future building automation projects.\n\nOur testbed has been evaluated in buildings with somewhat predictable occupancy patterns. It is challenging to apply our system to settings with irregular occupancy patterns. In future work, we will explore robust online HVAC control using minimal occupancy prediction. Augmented reality is also being integrated in HVAC control system \\cite{ARReprt}. Online algorithms have been applied to wireless sensor based building control \\cite{chauToN,AftabeEnergy}. Robust online control can ensure good performance in the presence of dynamic irregular environmental factors.\n\n\\section{Simulation-guided Model Predictive Control} \\label{sec:eval}\n\n\\noindent Building upon our occupancy-prediction from Section~\\ref{sec:prediction} and our temperature-response simulation from Section~\\ref{sec:simulation}, we now propose a model predictive control algorithm in Section~\\ref{subsec:control_framework}, and evaluate it in a real-world HVAC system in Section~\\ref{subsec:eval_res}.\n\n\\begin{figure}[ht!]\n \\centering\n \\includegraphics[width=\\linewidth]{figs\/eval_framework.pdf}\n \\caption{Framework of model predictive control algorithm.}\n \\label{fig:eval_framework}\n\\end{figure}\n\n\\subsection{HVAC Control Framework} \\label{subsec:control_framework}\n\n\\noindent The framework of our model predictive control consists of several parts that interact with one another as illustrated in Figure~\\ref{fig:eval_framework}. {\\color{black} Here, a control algorithm provides an HVAC setpoint schedule to the EnergyPlus simulator through the BCVTB interface. Based on this schedule and the local weather information, the EnergyPlus simulator performs simulations and provides temperature response to the control algorithm. Note that the local weather information is provided by the {\\em EnergyPlus Weather File} \\cite{eplus_weather} which includes temperature, humidity, pressure, wind speed, solar radiation, luminance, precipitation etc.} Now, based on the temperature response as well as the occupancy prediction, the control algorithm checks whether thermal-comfort criteria will be satisfied; if so, then there is no need for any modifications to the HVAC setpoint schedule; if not, then the HVAC setpoint schedule is modified subject to the thermal-comfort threshold, before being sent again to the EnergyPlus simulator, and so on. {\\color{black} Once the HVAC setpoint schedule is finalized, the HVAC system starts following this schedule, and the control algorithm starts monitoring the real-time temperature, humidity, and occupancy data, to determine the actual thermal comfort that resulted from its control decisions, and adjust its thermal-comfort threshold accordingly.}\n\n\n\n\\begin{algorithm}[hbtp!]\n\\small\n\\SetAlgoLined\n\\DontPrintSemicolon\n\\SetKwInput{Input}{Input}\n\\SetKwInOut{Output}{Output}\n\\SetKwInOut{Initialization}{Initialization}\n\\SetKwComment{Comment}{$\\triangleright$\\hspace{-4pt}\\ }{}\\SetInd{0.2em}{0.35em}\n\\Input{$t_{\\rm now}$, \\textbf{Initialization:} $\\tau \\leftarrow 0, {\\rm timer} \\leftarrow 0$}\n\\hrule\n\\If{${\\sf occup}_{\\rm now}=0\\ and\\ {\\rm timer}=0$}\n{\n $T_{\\rm target} \\leftarrow {\\sf setpoint}_{\\rm uo}$ \\\\%\\Comment*[r]{}\n Set HVAC setpoint to $T_{\\rm target}$ \\Comment*[r]{\\textit{increase setpoint}}\n $\\tau \\leftarrow \\emph{Pre-cooling}(t_{\\rm now}, t_{\\rm pd\\_oc})$ \\Comment*[r]{\\textit{pre-cooling time}}\n ${\\rm timer} \\leftarrow t_{\\rm now} + \\tau$\n}\n\\eIf{$t_{\\rm now}={\\rm timer}$}\n{\n $T_{\\rm target} \\leftarrow {\\sf setpoint}_{\\rm oc}$ \\\\%\\Comment*[r]{}\n Set HVAC setpoint to $T_{\\rm target}$ \\Comment*[r]{\\textit{start pre-cooling}}\n ${\\rm timer} \\leftarrow\\ 0$\n}\n{\n Wait for timer expiry \\Comment*[r]{\\textit{no pre-cooling yet}}\n}\n\\caption{{\\tt HVAC-MPC}}\n\\label{alg:control}\n\\end{algorithm}\n\n\nHaving provided an overview of our framework for model predictive control, we will now explain the control algorithm therein. In particular, we call this algorithm {\\tt HVAC-MPC}, the pseudocode of which is outlined in Algorithm~\\ref{alg:control}. First, in line~1 the algorithm checks whether the building is unoccupied at the current time. If so, then in lines 2 and 3 it instructs the HVAC system to increase the temperature setpoint (see Table~\\ref{tab:setpoints} for the exact setpoints used by the algorithm). \n\n\\begin{table}[hbtp!]\n \\small\n \\caption{Setpoints used by {\\tt HVAC-MPC}. Here, ${\\sf setpoint}_{\\rm oc}$ is used when the building is occupied; ${\\sf setpoint}_{\\rm uo}$ is used when unoccupied.}\n \\label{tab:setpoints}\n \\centering\n \\begin{tabular}{ c | c}\n \n\t\\hline \\hline\n Occupied (${\\sf setpoint}_{\\rm oc}$) & Unoccupied (${\\sf setpoint}_{\\rm uo}$) \\\\\n \n 24$^\\circ$C & 28$^\\circ$C \\\\\n\t\\hline \\hline\n \\end{tabular}\n\\end{table}\n\nAfter that, in lines 4 and 5, the occupancy prediction is used to determine when the building is expected to become occupied in the future, and determine the optimal pre-cooling time accordingly (here the algorithm uses a procedure called \\emph{Pre-cooling}, the workings of which will be explained later on in this section). Then, in line~7, the algorithm checks whether the time has come for the pre-cooling to start. If so, then it instructs the HVAC system to decrease the temperature setpoint, before resetting the corresponding timer (see lines 8 to 10). On the other hand, if the time has not yet come to start pre-cooling, the algorithm simply waits until it does (see lines 11 and 12).\n\n\n\n\\begin{figure}[hbtp!]\n \n \\scalebox{0.745}{\n \\begin{tikzpicture}[node distance = 1.5cm, auto]\n\n\n \\node (start) [startstop] {Begin};\n \\node (init) [init, below of=start, text width=4.5cm, node distance=1.45cm]\n {$t_{\\rm min} \\gets t_{\\rm now}$\\\\\n $t_{\\rm max} \\gets t_{\\rm pd\\_oc}$\\\\\n $t^* \\gets t_{\\rm min}+(t_{\\rm max}-t_{\\rm min})\/2$};\n \\node (if1) [decision, below of=init, aspect=3.0, node distance=1.85cm]\n {$t_{\\rm min}< t_{\\rm max}$};\n \\node (run) [process, below of=if1, text width=7.3cm, node distance=2.00cm]\n {Run simulation with HVAC turned off from $t_{\\rm now}$ \n to $t^*-1$, and turned on from $t^*$ to $t_{\\rm pd\\_oc}$};\n \\node (if2) [decision, below left = 1.4cm and -1.60cm of run, aspect=2.0]\n {\\hspace{0.2em} $T_{\\rm sim}[t_{\\rm pd\\_oc}$+1$]>$\\\\\n ${\\sf setpoint}_{\\rm oc}$};\n \\node (if3) [decision, right of=if2, aspect=2.0, node distance=5.75cm]\n\t {\\hspace{0.4em} $T_{\\rm sim}[t_{\\rm pd\\_oc}$--1$]\\leq$\\\\\n\t ${\\sf setpoint}_{\\rm oc}$};\n \\node (late) [process, below of=if2, text width=4.9cm, node distance=2.30cm]\n {$t_{\\rm max} \\gets t^*-1$\\\\\n $t^* \\gets t_{\\rm min}+(t^*-t_{\\rm min})\/2$};\n \\node (soon) [process, below of=if3, text width=4.9cm, node distance=2.30cm]\n {$t_{\\rm min} \\gets t^*+1$\\\\\n $t^* \\gets t^*+(t_{\\rm max}-t^*)\/2$}; \n \\node (dot) [dot, below left = 0.20cm and 0.30cm of soon] {};\n \n \n \\node (return) [init, below of=dot, node distance=1.7cm] {Output $t^*$};\n \\node (end) [startstop, below of=return, node distance=1.25cm] {End};\n \\node (input) [input, right of=run, node distance=4.5cm] {};\n\n \n \\draw [arrow] (start) -- (init);\n \\draw [arrow] (init) -- (if1);\n \\draw [arrow] (if1.south) -- node[near start] {yes} (run.north);\n \n \\draw [arrow] (run.south) -- +(0,-11pt) node[align=center, near end, below] {simulated temperature ($T_{\\rm sim}$)} -- +(-91pt,-11pt) -- (if2.north);\n \\draw [arrow] (input) -- node {\\ \\ \\ \\ \\ \\ \\ $T[t_{\\rm now}]$} (run.east);\n \\draw [arrow] (if2) -- node[align=left] {yes (too late)} (late);\n \\draw [arrow] (late.east) -- (dot);\n \\draw [arrow] (if2) -- node[align=left] {no} (if3);\n \\draw [arrow] (if3) -- node[align=left] {yes (too soon)} (soon);\n \\draw [arrow] (soon.west) -- (dot);\n \\draw [arrow] (if3.east) -- +(10pt,0) node[near start] {no} |- +(0,-110pt) -- +(-32pt, -110pt) -- +(-150pt, -110pt) node[near start, below] {$t^*$ is the best possible pre-cooling time} -- (return.north);\n \\draw [arrow] (if1.east) -- +(20pt,0) node[near start] {no} -- +(112pt,0) |- +(0,-267pt) -- (return.east);\n \\draw [arrow] (dot.west) -- +(-150pt,0) |- +(-60pt,219pt) -- (if1.west);\n \n \n \\draw [arrow] (return) -- (end);\n \\end{tikzpicture}}\n \\caption{Flowchart of our \\emph{Pre-cooling} procedure, which determines the pre-cooling time based on the predicted occupancy.}\n \\label{fig:eval_precool_flowchart}\n\\end{figure}\n\n\n\n\nHaving explained the pseudocode of {\\tt HVAC-MPC}, we now explain the workings of the \\emph{Pre-cooling} procedure used therein. Figure~\\ref{fig:eval_precool_flowchart} illustrates the flowchart of this procedure. Basically, the goal here is to determine the time $t^*$ at which the pre-cooling should start; this time falls within a certain range of feasible times, denoted by $[t_{\\rm min}, t_{\\rm max}]$. Initially, the algorithm sets $t_{\\rm min}$ to be equal to the current time (i.e., $t_{\\rm now}$), sets $t_{\\rm max}$ to be equal to the predicted time of occupancy (i.e., $t_{\\rm pd\\_oc}$), and sets $t^*$ to be right in the middle between the two (i.e., $t^* = t_{\\rm min}+(t_{\\rm max}-t_{\\rm min})\/2$). After that, $t^*$ is adjusted iteratively as follows. In each iteration, the algorithm runs an EnergyPlus simulation in which the HVAC is switched off from $t_{\\rm min}$ to $t^*-1$, and then the pre-cooling starts at $t^*$, leaving the HVAC on from $t^*$ to $t_{\\rm max}$. Thus, we obtain the simulated temperature, $T_{\\rm sim}[t]$, for every $t\\in [t_{\\rm min}, t_{\\rm max}]$. These simulated temperatures should ideally satisfy the following conditions:\n\n\n\n\\begin{figure*}[t]\n \\centering\n \\begin{subfigure}[b]{0.475\\textwidth}\n \\centering\n \\includegraphics[width=\\textwidth]{figs\/eval_res_a.pdf}\n \\caption{{\\bf Without {\\tt HVAC-MPC}:} full-powered HVAC at\n all times (indicated by the strip at the bottom) despite\n intermittent occupancy.}\n \\label{fig:eval_res_a}\n \\end{subfigure}\n \\hfill\n \\begin{subfigure}[b]{0.475\\textwidth}\n \\centering\n \\includegraphics[width=\\textwidth]{figs\/eval_res_b.pdf}\n \\caption{{\\bf Without {\\tt HVAC-MPC}:} incurred thermal\n comfort sensation. PMV index is always outside the recommended\n [-0.5,+0.5] range.}\n \\label{fig:eval_res_b}\n \\end{subfigure}\n \\begin{subfigure}[b]{0.475\\textwidth}\n \\centering\n \\includegraphics[width=\\textwidth]{figs\/eval_res_c.pdf}\n \\caption{{\\bf With {\\tt HVAC-MPC}:} occupancy and\n temperature forecasts are used to find the best possible pre-cooling schedule\n as indicated by the sequence of HVAC state transitions from\n {\\em off} to {\\em on} in the strip at the bottom.}\n \\label{fig:eval_res_c}\n \\end{subfigure}\n \\quad\n \\begin{subfigure}[b]{0.475\\textwidth}\n \\centering\n \\includegraphics[width=\\textwidth]{figs\/eval_res_d.pdf}\n \\caption{{\\bf With {\\tt HVAC-MPC}:} The PMV index is almost\n always within the recommended [-0.5,+0.5] range during the periods in which the building is occupied.}\n \\label{fig:eval_res_d}\n \\end{subfigure}\n \\caption[]{Results of HVAC model predictive control ({\\tt HVAC-MPC}) in our testbed.}\n \\label{fig:eval_results}\n\\end{figure*}\n\n\n\n\n\n\\begin{equation}\\label{condition1}\nT_{\\rm sim}[t_{\\rm pd\\_oc}]={\\sf setpoint}_{\\rm oc}\n\\end{equation}\n\\begin{equation}\\label{condition2}\nT_{\\rm sim}[t]>{\\sf setpoint}_{\\rm oc},\\ \\forall t : t^* \\leq t < t_{\\rm pd\\_oc}\n\\end{equation}\n\n\\noindent which basically means that the temperature becomes satisfactory exactly when needed, and not before. The algorithm checks whether the above two conditions hold. Now:\n\\begin{itemize}\\itemsep-0.5em\n\\item if Condition~\\eqref{condition1} does not hold, it implies that the pre-cooling process started too late, and so $t^*$ should be set to an earlier time. To this end, the algorithm sets $t_{\\rm max}$ to be equal to $t^*-1$, and then updates $t^*$ as follows:\n\\begin{equation}\nt^* \\gets t_{\\rm min}+(t^*-t_{\\rm min})\/2\n\\end{equation}\n\\item if Condition~\\eqref{condition2} does not hold, it implies that the pre-cooling process started too soon, and so $t^*$ should be delayed. To this end, the algorithm sets $t_{\\rm min}$ to be equal to $t^*+1$, and then updates $t^*$ as follows:\n\\begin{equation}\nt^* \\gets t^*+(t_{\\rm max}-t^*)\/2\n\\end{equation}\n\\end{itemize}\nAfter that, the algorithm proceeds to the next iteration to check whether the new $t^*$ needs any further adjustments. This process is repeated until either $t_{\\rm min}\\geq t_{\\rm max}$, or conditions \\eqref{condition1} and \\eqref{condition2} are both met. Either way, the best possible $t^*$ is found.\n\n\n\n\n\n\\subsection{Evaluation Results} \\label{subsec:eval_res}\n\n\n\\noindent In this subsection, we evaluate the performance of our {\\tt HVAC-MPC} algorithm. To this end, we consider two standard measures of thermal comfort, namely \\emph{Predicted Mean Vote} (PMV) and \\emph{Predicted Percentage Dissatisfied} (PPD) \\cite{pmv}. Specifically, PMV quantifies the human perception of thermal sensation on a scale that runs from -3 to +3, where -3 is very cold, 0 is neutral, and +3 is very hot. On the other hand, PPD is built upon PMV to quantify the percentage of occupants that are dissatisfied given the current thermal conditions. {\\color{black} The recommended PMV range for thermal comfort is between -0.5 and +0.5 for indoor spaces, while the acceptable PPD range is between 5\\% and 10\\% \\cite{ashrae55}.}\n\n\nWe compared our {\\tt HVAC-MPC} algorithm against a baseline alternative, where the HVAC is turned on throughout the day, regardless of the varying occupancy. The evaluation results are shown in Figure~\\ref{fig:eval_results}. Specifically:\n\\begin{itemize}\n\\item Figure~\\ref{fig:eval_res_a} depicts the observed occupancy, the indoor and outdoor temperatures, and the HVAC status \\emph{given the baseline HVAC control};\n\\item Figure~\\ref{fig:eval_res_b} depicts the thermal comfort according to PMV and PPD \\emph{given the baseline HVAC control};\n\\item Figure~\\ref{fig:eval_res_c} depicts the predicted occupancy, the indoor temperature, and the HVAC status \\emph{given {\\tt HVAC-MPC} algorithm};\n\\item Figure~\\ref{fig:eval_res_d} depicts the thermal comfort according to PMV and PPD \\emph{given {\\tt HVAC-MPC} algorithm}.\n\\end{itemize}\n\n\\begin{figure*}[htbp!]\n \\begin{subfigure}[b]{0.47\\textwidth}\n \\centering\n \\includegraphics[height=1.6in]{figs\/eval_energy_a.pdf}\n \\caption{When compared to the immediately preceding day.}\n \\label{fig:eval_energy_a}\n \\end{subfigure}\n \\qquad\n \\begin{subfigure}[b]{0.47\\textwidth}\n \\centering\n \\includegraphics[height=1.6in]{figs\/eval_energy_b.pdf}\n \\caption{When compared to the same day of the preceding week.}\n \\label{fig:eval_energy_b}\n \\end{subfigure}\n \\caption{Reduction in HVAC energy consumption achieved by {\\tt HVAC-MPC} (Algorithm~\\ref{alg:control}).}\n \\label{fig:eval_energy}\n\\end{figure*}\n\n\nLet us first comment on the results of the baseline HVAC control. As can be seen in Figure~\\ref{fig:eval_res_a}, the HVAC is turned on throughout the day, despite the significant changes in both the occupancy and the external temperature. In terms of thermal comfort, the baseline HVAC control performs rather poorly, as shown in Figure~\\ref{fig:eval_res_b}. Here, the recommended range for PMV is highlighted by the dotted region. As can be seen, the PMV index is outside the recommended range throughout the day. Furthermore, according to the PDD index, a considerable percentage of occupants are dissatisfied most of the day.\n\n\nMoving on to the results of our {\\tt HVAC-MPC} algorithm, Figure~\\ref{fig:eval_res_c} shows how the HVAC is switched off for a considerable number of hours. This is because, whenever the building becomes unoccupied, {\\tt HVAC-MPC} increases the temperature setpoint and predicts the future temperature and occupancy to find the best possible time for pre-cooling. Figure~\\ref{fig:eval_res_d}, on the other hand, depicts the PMV and PPD indices throughout the day. As can be seen, when the building is occupied, the PMV index is almost always within the recommended range. Likewise, when the building is occupied, the PPD is close to 5\\% (which is the best possible PPD score that can be achieved).\n\n\n{\\color{black} Finally, we present the energy savings that are attained by our {\\tt HVAC-MPC} algorithm. The algorithm was activated in the testbed building for a duration of one week in total and the results are provided in Figure~\\ref{fig:eval_energy}. In particular, Figure~\\ref{fig:eval_energy_a} shows the results for three different days, where each day is in a different month. For each day shown, the algorithm performance is compared with the immediately preceding day where {\\tt HVAC-MPC} is not activated. Figure~\\ref{fig:eval_energy_b} shows the results of another experiment where we activated {\\tt HVAC-MPC} for four consecutive days in the same week. For each day, the results are compared with the corresponding day of the previous week in which {\\tt HVAC-MPC} was not activated. The purpose of this experiment was to find out how much energy is saved by the MPC algorithm relative to the same day of the previous week. The energy savings attained by {\\tt HVAC-MPC} range from 23\\% to 39\\%. Table~\\ref{tab:eval_energy} lists the average daily savings, the standard deviation, and the total energy savings over the experiment period.}\n\n\\begin{table}[hbtp!]\n \\small\n \\caption{Summary of energy savings attained by {\\tt HVAC-MPC}.}\n \\label{tab:eval_energy}\n \\centering\n \\begin{tabular}{ p{6.5cm} | c}\n \n\t\\hline \\hline\n Average daily savings over experiment period & 456 kWh \\\\ \\hline\n Standard deviation of daily savings & 118 kWh \\\\ \\hline\n Total savings over the seven-day experiment & 3197 kWh \\\\\n\t\\hline \\hline\n \\end{tabular}\n\\end{table}\n\n\n\\section{Occupancy Recognition} \\label{sec:recognition}\n\n\\noindent Occupancy information is crucial for many applications, such as building management and human behavior studies. We develop an occupancy recognition system based on real-time video processing of a video stream to infer the occupancy patterns dynamically. This raises a number of challenges. First, structures differ from one building to another, leading to the possibility of occupants being obscured by various obstacles, such as pillars. Hence, we need to track the movements of occupants to determine the occupancy more accurately. Second, our algorithm is executed on an embedded system (e.g., Raspberry Pi), which has limited processing power and memory space compared to a typical desktop computer; this is particularly challenging since the typical video-processing algorithms are computationally demanding.\n\nThe basic idea of our occupancy-recognition algorithm is to count the number of people crossing a virtual reference line in the video, captured by a fisheye camera. Objects are identified as moving blobs (i.e., a set of connected points whose position is changing during the video stream); every such blob is interpreted as a person. Whenever a moving blob is detected, the algorithm keeps track of its movement to determine whether it passes the virtual reference line, and then updates the number of occupants accordingly. In particular, we position the line near the entrance of the space. Whenever the moving blob passes inward, the total number of occupants is increased by 1, and whenever the moving blob passes outward, the total number of occupants is decreased by 1.\n\nOur algorithm consists of the following five steps: (1) background isolation, (2) silhouette detection, (3) object tracking, (4) inward\/outward logging, and (5) inconsistency resolution. The flowchart of our algorithm is presented in Figure~\\ref{fig:flowchart}. In our implementation, two open-source projects were used: \\emph{OpenCV} \\cite{opencv_library} and \\emph{openFramework} \\cite{ox_library}. Next, we will explain each step in details.\n\n\n\\begin{figure}[ht!]\n \\centering\n \\scalebox{0.75}{\n \\begin{tikzpicture}[node distance = 1.5cm, auto]\n\n \n \\node (init) [init] {Initialize Algorithm};\n \\node (isol) [process, right of=init, node distance=4.7cm, text width=4.0cm] {Isolate background by comparing current and previous frames};\n \\node (extr) [process, below of=isol, node distance=1.65cm, text width=3.6cm] {Extract silhouettes in current frame};\n \\node (add) [process, below of=extr, node distance=1.45cm, text width=3.7cm] {Add each silhouette to a tracking list};\n \\node (if) [decision, below of=add, text width=5.2cm, aspect=4, node distance=1.7cm] {If a silhouette passes a reference line};\n \\node (upda) [process, left of=if, text width=2cm, node distance=4.7cm] {Update occupancy};\n \\node (rese) [process, below of=if, text width=4.0cm, node distance=1.75cm] {Reset occupancy if \\\\inconsistency detected};\n\n \n \\draw [arrow] (init) -- (isol);\n \\draw [arrow] (isol) -- (extr);\n \\draw [arrow] (extr) -- (add);\n \\draw [arrow] (add) -- (if);\n \\draw [arrow] (if) -- node[auto] {yes} (upda);\n \\draw [arrow] (if) -- node[auto] {no} (rese);\n \\draw [arrow] (rese.east) -- +(35pt,0) |- (isol.east);\n \\draw [arrow] (upda) |- (rese);\n \\end{tikzpicture}}\n \\caption{Flowchart of our occupancy-recognition algorithm.}\n \\label{fig:flowchart}\n\\end{figure}\n\n\n\n\\subsection{Background Isolation} \\label{sub:background_updating}\n\n\\noindent The purpose of background isolation is to identify a background image in the current video frame. Note that the appearance of the background may vary over the course of the video, depending on the time-of-day (e.g., turning on the lights at night may significantly alter the appearance of the background compared to natural light). The shadows of occupants must also be taken into consideration during the background isolation. To overcome these challenges, we employ the Gaussian mixture-based background\/foreground segmentation algorithm proposed in \\cite{zivkovic2006efficient,zivkovic2004improved}, and implemented on OpenCV.\n\n\n\n\\subsection{Silhouette Detection} \\label{sub:silhouette_searching}\n\n\\noindent In our setting, the term ``silhouette'' is used to refer to the border of a set of continuous points. Silhouette detection is based on the algorithm proposed in \\cite{Suzuki85Topological}. The silhouettes of moving objects are extracted by comparing the current frame with the previous one; see Figure~\\ref{fig:videoprocessing_result} for some examples. Here, only the silhouettes larger than a certain threshold area, $A$, are considered. The threshold is adjusted depending on the viewpoint and orientation of the camera. Furthermore, we use different values of $A$ for different parts of the space, to reflect the fact that individuals appear smaller as they move farther away from the camera. Importantly, the silhouettes of two or more people may overlap, and may, therefore, be interpreted as only one individual. To overcome this challenge, we use a machine-learning technique which will be explained later on in Section~\\ref{sub:machine_learning}.\n\n\\begin{figure}[ht!]\n \\centering\n \\includegraphics[width=.99\\linewidth]{figs\/extract}\n \\caption{Examples of silhouette detection, taken from different buildings in which our system is deployed.}\n \\label{fig:videoprocessing_result}\n\\end{figure}\n\n\n\n\\subsection{Object Tracking} \\label{sub:object_tracking}\n\n\\noindent After obtaining the silhouettes of occupants, their bounding boxes are logged for tracking. To this end, the list ${T_a}$ of silhouettes from the last frame is maintained. The algorithm then obtains the list ${T_b}$ of silhouettes from the current frame. For each bounding box $B_b$ in ${T_b}$, the algorithm determines whether there exists a box $B_a$ in $T_a$ that is within a certain distance, $d$, from $B_b$. If so, then $B_b$ is assumed to be the new location of $B_a$. Consequently, $B_a$ is updated in $T_a$, and its location is set to be that of $B_b$, in preparation for the next iteration of the algorithm. Note that the silhouettes are detected when they are moving. However, in cases where people might stop for a few seconds and then continue to walk, those objects will be removed from $T_a$ when they are missed for a certain number of seconds.\n\n\n\n\\subsection{Inward\/Outward Logging} \\label{sub:in_out_checking}\n\n\\noindent Given the collection of moving objects and their locations, a virtual reference line is used to count occupants. Specifically, whenever the locations are updated, the algorithm checks every object to determine whether that object has crossed from one side of the line to the other. If so, then the number of occupants is updated according to the direction of the movement. For inward movement, the number of occupants increases by 1, otherwise it decreases by 1. Furthermore, since the silhouettes of any two moving objects may overlap, the width of the bounding box can be used to infer the number of occupants contained in each object.\n\n\n\n\\subsection{Inconsistency Resolution} \\label{sub:error_detection}\n\n\\noindent With all the techniques described thus far, the performance of the algorithm may not be satisfactory, due to one major challenge: \\emph{the silhouettes of different occupants may overlap}. In this case, some of the overlapping occupants may go undetected by the algorithm. This problem becomes even more evident when the movement patterns are affected by whether the occupants are entering or leaving the building, e.g., due to the fact that occupants arrive one by one, but leave all at once. For instance, in our application domain, the pace at which people leave is significantly faster than the pace at which they enter. Consequently, when all occupants leave at once, the number of overlapping silhouettes increases, leading to a larger number of people going undetected by the algorithm. As a result, the algorithm on average misses more occupants leaving than entering the building, leading to the erroneous conclusion that there are still occupants in the building when in fact there are none.\n\nTo resolve such inconsistency, two simple techniques are used. First, if the number of occupants becomes negative, the occupant counter is frozen until another object crosses the reference line inward. Second, if no moving object is detected for a certain period of time, the occupant counter is reset to zero. While these simple techniques reduce the error, they are clearly insufficient. In Section~\\ref{sub:machine_learning}, we propose a dedicated technique to address this issue.\n\n\n\n\\subsection{Improvement by Machine Learning} \\label{sub:machine_learning}\n\n\\noindent As mentioned earlier, one of the major challenges that we have encountered while deploying our occupancy-detection algorithm is to resolve the problem of overlapping silhouettes. One solution is based on the width of bounding box; the wider the box, the more occupants it contains. However, we observe that such a solution is insufficient, especially when an occupant happens to be directly in front of another. To resolve this issue, we employ machine-learning and image-classification techniques, coupled with randomized principal component analysis (PCA) \\cite{halko2011finding}, which is implemented in \\cite{scikit-learn}.\n\nIn more detail, we collected 13,000 blobs from video footages spanning a period of one week and segmented each such blob as a separate image to create our training dataset. The number of occupants in each image was manually identified; see Figure~\\ref{fig:trainingdata} for some examples. The images were then transformed to grayscale in order to reduce the computational load. After that, the images were rescaled to the same size, 30$\\times$15 pixels, thereby making the size of each image 450 pixels. Second, randomized PCA is used to project the pixels in the original array to a smaller array that preserves the characteristics of the images, as a set of 25 features for each image in this case. The projection aims to further reduce the computational complexity. Moreover, we added the original width, height and the ratio of black pixels to the set of features. After obtaining the features, Gaussian Naive Bayes is used to classify the blobs with respect to the number of occupants.\n\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[width=0.75\\linewidth]{figs\/silhouettes}\n\\caption{Sample images from the training dataset used for machine learning and image classification.}\n\\label{fig:trainingdata}\n\\end{figure}\n\n\n\n\\subsection{Privacy Enhancement} \\label{sub:privacy_concerns}\n\n\\noindent In our system, the videos and images are discarded immediately after processing. Still, privacy invasion is always a concern for video based detection methods. With this in mind, we introduced a number of techniques to preserve the privacy of the occupants. First of all, to prevent any potential hacker from accessing the video feed, we ensured that the camera stream can only be accessed by a single process at a time. Consequently, when our system is running, all the other programs are blocked from accessing the camera.\nIn addition, a hardware-based solution has been tested. Specifically, we created a frosted lens by overlaying a semi-transparent layer in front of the camera, so as to blur the camera feed. In so doing, the faces of occupants are no longer recognizable; see Figure~\\ref{fig:withoutlayer} for an illustration.\n\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[width=0.8\\linewidth]{figs\/frost}\n\\caption{Enhanced privacy by using frosted lens on camera.}\n\\label{fig:withoutlayer}\n\\end{figure}\n\n\n\n\\subsection{Evaluation Results} \\label{sec:occupancy_detection_results}\n\n\\noindent In this section, we evaluate the accuracy of our occupancy recognition. To this end, we collected video footages from our testbed, each with a frame size of 800$\\times$600 pixels, and a sample rate of 30 frames per second. The true occupancy was obtained by manually counting the number of occupants in each frame. Due to this laborious process, we were only able to obtain the true occupancy in a small number of videos, which are used in the evaluations.\n\nWe start by defining the accuracy rate as follows:\n\\begin{equation}\n {\\sf AccuracyRate} \\triangleq 1-\\frac{{\\sf Missing}_{\\rm in}+{\\sf Missing}_{\\rm\n out}}{{\\sf Total}_{\\rm in}+{\\sf Total}_{\\rm out}}\n\\end{equation}\nwhere ${\\sf Total}_{\\rm in}$ is the number of individuals who entered the building and ${\\sf Missing}_{\\rm in}$ is the number of such individuals who were undetected by the algorithm. Conversely, ${\\sf Total}_{\\rm out}$ is the number of individuals who exited the building and ${\\sf Missing}_{\\rm out}$ is the number of those who exited without being detected by our algorithm.\n\nTable~\\ref{tab:occupancyresults_1} presents the system accuracy given different numbers of occupants over different durations. As can be seen, the algorithm is able to recognize the number of occupants with high accuracy, even when over 400 individuals enter the building in just 20 minutes. Naturally, given a greater rate at which occupants enter the building, the accuracy of the system decreases because there are more cases in which the occupants overlap (in many such cases, it was hard, even for a human, to determine the exact number of occupants, and the video had to be replayed several times before the human was able to determine the true occupancy with certainty).\n\n\\begin{table}[ht!]\n\\centering\n\\caption{Results of occupancy recognition given different durations and different numbers of occupants.}\n\\label{tab:occupancyresults_1}\n\\scalebox{0.85}{\n\\begin{tabular}{@{}c|c|c@{}}\n\\hline\\hline\nVideo Length & Total No. of Occupants & ${\\sf AccuracyRate}$ \\\\\n & of Occupants & \\\\ \\hline\n 40 mins & 127 & 90\\% \\\\\n 40 mins & 154 & 90\\% \\\\\n 20 mins & 407 & 84\\% \\\\ \\hline\\hline\n\\end{tabular}}\n\\end{table}\n\nNext, we evaluate our system over one-day periods during the weekend, weekday and Friday. Note that in our testbed Friday is the busiest day in the week due to the Friday sermon, which takes place only once a week, and typically attracts a large audience. The results are presented in Table~\\ref{tab:occupancyresults_2}. As expected, the system accuracy correlates with the occupancy rates. In particular, the system is least accurate on Friday (which is the busiest day in our experiment), and most accurate during the weekend (which is the least busy in our experiment). Importantly, the accuracy seems sufficiently high throughout the week to provide a reasonable approximation of the actual occupancy state in the building, which is arguably sufficient for our purpose of HVAC control.\n\n\\begin{table}[ht!]\n\\centering\n\\caption{Results of occupancy recognition comparing weekend, weekday, and Friday.}\n\\label{tab:occupancyresults_2}\n\\scalebox{0.85}{\n\\begin{tabular}{@{}c|c|c@{}}\n\\hline\\hline\nType & Video Length & ${\\sf AccuracyRate}$ \\\\ \\hline\nWeekend & 1 day & 88\\% \\\\\nWeekday & 1 day & 86\\% \\\\\nFriday & 1 day & 81\\% \\\\ \\hline\\hline\n\\end{tabular}}\n\\end{table}\n\nWe now turn our attention to quantifying the loss in accuracy that occurs when using our privacy-preserving frosted lens from Section~\\ref{sub:privacy_concerns}. The results of this evaluation are presented in Table~\\ref{tab:occupancyresults_3}. As can be seen, the frosted lens only reduces the accuracy slightly, and that is despite the fact that the video footage is considerably blurred, as we have shown earlier in Figure~\\ref{fig:withoutlayer}.\n\n\\begin{table}[htbp!]\n\\centering\n\\caption{Results of occupancy recognition comparing normal lens and frosted lens.}\n\\label{tab:occupancyresults_3}\n\\scalebox{0.85}{\n\\begin{tabular}{@{}c|c|c|c@{}}\n\\hline\\hline\nType & Video Length & Total No. & ${\\sf AccuracyRate}$ \\\\\n & & of Occupants & \\\\ \\hline\nNormal Lens & 160 mins & 322 & 87.8\\% \\\\\nFrosted Lens & 160 mins & 339 & 80.2\\% \\\\ \\hline\\hline\n\\end{tabular}}\n\\end{table}\n\nNext, we evaluate the effectiveness of our machine-learning technique from Section~\\ref{sub:machine_learning}. To this end, we use three performance measures that are widely used in the Machine-Learning literature. The first is ${\\sf Precision}$, which is defined as the fraction of occupants that were correctly classified out of all those who were classified as either moving inward or as moving outward. The second measure is ${\\sf Recall}$, defined as the fraction of occupants that were correctly classified out of all those who actually entered the building or exited it. {\\color{black} Since it is often possible to have a naive classifier that has a high ${\\sf Precision}$ but a low ${\\sf Recall}$ or vice versa, a better metric called ${\\sf F1\\mbox{-}Score}$ has been utilized in \\cite{f1score1,f1score2}, which is basically a harmonic mean of ${\\sf Precision}$ and ${\\sf Recall}$}. Based on those three measures, Table~\\ref{tab:occupancyresults_4} shows the results before and after applying our machine-learning technique. The evaluation is carried out using 10-fold cross-validation of our dataset of 13,000 blobs. As can be seen, according to the most important measure, namely ${\\sf F1\\mbox{-}Score}$, our machine-learning technique from Section~\\ref{sub:machine_learning} significantly improves the performance of our system.\n\nFinally, to better understand how occupancy changes during the daytime in our application, we plotted in Figure~\\ref{fig:occupancy_plot} the actual occupancy, as well as the occupancy detected by our algorithm, given a typical Friday, and a typical Saturday. As can be seen, the general occupancy trend is clearly captured by the algorithm.\n\n\n\\begin{table}[ht!]\n\\centering\n\\caption{Results of occupancy recognition comparing with and without machine-learning technique.}\n\\label{tab:occupancyresults_4}\n\\scalebox{0.85}{\n\\begin{tabular}{@{}c|c|c|c@{}}\n\\hline\\hline\nType & ${\\sf Precision}$ & ${\\sf Recall}$ & ${\\sf F1\\mbox{-}Score}$ \\\\ \\hline\nWithout Machine Learning & 0.97 & 0.27 & 0.42 \\\\\nWith Machine Learning & 0.69 & 0.78 & 0.73 \\\\ \\hline\\hline\n\\end{tabular}}\n\\end{table}\n\n\\begin{figure*}[ht!]\n \\centering\n \\includegraphics[width=1\\linewidth]{figs\/occup_rec.pdf}\n \\caption{How occupancy changes during a typical day. Each peak represents one of the five daily prayers in Islam. We distinguish between Friday and other days of the week due to the Friday sermon, which precedes the midday prayer and usually attracts many more worshippers compared to any other prayer throughout the week (note that the scale of the y-axis is greater in the left plot than in the right plot).}\\label{fig:occupancy_plot}\n\\end{figure*}\n\n\\section{Introduction} \\label{sec:intro}\n\n\\noindent Heating, ventilation, and air-conditioning (HVAC) units, which are a primary target of building automation, make up almost 50\\% of the energy consumed in both residential and commercial buildings \\cite{HVACConsumption}. In general, building automation systems aim to intelligently control building facilities in response to dynamic environmental factors, while maintaining satisfactory performance in energy consumption and comfort. The primary functions of a building automation system include: (1) sensing of the environmental factors by measurements, and (2) optimizing control strategies based on the current and predictive states of building and occupancy. These tasks require an integrated process of sensing, computation, and control.\n\nTraditional building automation systems rely on fairly inaccurate occupancy sensors, which hinder the responsiveness of automation systems. For example, passive infrared and ultra-sound occupancy sensors produce poor accuracy, because they are unable to determine the occupancy state adequately when occupants remain stationary for a prolonged period of time. They also have a limited range which hinders their performance, especially in a large area. More accurate sensing technology, such as cameras that use visible or infra-red lights, can significantly improve the accuracy of occupancy recognition.\n\nOn the other hand, model predictive control, by which the future thermal response and external environmental factors are anticipated to make control decisions accordingly, has been considered in a number of studies \\cite{mpc1,mpc2,mpc3,mpc5,mpc6,mpc7} which are shown to be more effective than classical PID and hysteresis controllers that do not consider anticipated events. However, these studies are often based on time-invariant, first-principle linear models (also known as lumped element resistance-capacitance (RC) models \\cite{lti_rc}), considering only simple building geometry and single-zone in near-future time horizon. Although these linear models are easier for calibration (e.g., using frequency domain decomposition, or subspace system identification methods \\cite{lti_rc, mpc_rc_calib1, mpc_rc_calib2}), the error accumulates considerably when a longer time horizon is considered in model predictive control. While non-linear models are rather complicated and impractical, other alternatives based on physical models of building thermal response can provide a feasible solution.\n\nRecently, there have been remarkable advances in embedded system technologies, which provide low-cost platforms with powerful processors and sizeable memory storage in a small footprint. In particular, the emergence of \\emph{system-on-a-chip} technology \\cite{soc}, which integrates all major components of a computer into a single chip, can provide versatile computing platforms with low-power consumption and mobile network connectivity in a cost-effect\\-ive manner for mass production. As a result, smartphones are able to rapidly evolve from single-core to multi-core processors with a low incremental production cost. Notably, the \\emph{Raspberry Pi} project \\cite{rpi}, which originally aimed to provide affordable solutions for the teaching of computer science, has rapidly evolved for a wide range of advanced scientific projects. Therefore, there are plenty of opportunities to harness recent embedded system technologies in intelligent building automation systems. Particularly, sophisticated computational tasks can be conducted on these embedded systems efficiently, such as real-time video processing and accurate building thermal response simulation (e.g., \\cite{embedded_ref2}).\n\n\\medskip\n\nWith this in mind, we designed and implemented an occupancy-predictive HVAC control system in a low-cost yet powerful embedded system (using Raspberry Pi 3) for building automation. The rest of the paper is organized as follows. In Section~\\ref{sec:related}, we present the background information and literature review. In the remaining sections, we highlight three key features of our system.\n\n\n\\paragraph{{\\em(Section~\\ref{sec:recognition})} Real-time Video-based Occupancy Recognition}\nWe apply advanced video-processing techniques to analyze the features of occupants from video cameras, and automatically classify and infer the states of occupancy. Moreover, we consider privacy enhancement using a frosted lens. Our system achieves 80-90\\% accuracy for occupancy recognition by real-time video processing. Furthermore, we improve the performance of our occupancy recognition by using Machine Learning for considerably crowded settings.\n\n\\paragraph{{\\em(Section~\\ref{sec:prediction})} Dynamic Occupancy Prediction}\nWe employ various linear and non-linear regression models to capture and predict occupancy trends according to different day-of-week, seasonal patterns, etc. We present general as well as domain-specific approaches for occupancy prediction. Our models are able to identify the future occupancy trends considering a variety of dynamic usage patterns.\n\n\\paragraph{{\\em(Sections~\\ref{sec:simulation}-\\ref{sec:eval})} Simulation-guided Model Predictive Control}\nWe employ \\emph{EnergyPlus} simulator \\cite{eplus} for real-time HVAC control. We ported EnergyPlus simulator to the Raspberry Pi embedded system platform for simulation-guided model predictive control. A co-simulation framework is utilized to provide accurate building thermal response simulation under proper calibration. Noteworthily, we also release our Raspberry Pi version of EnergyPlus publicly \\cite{eplus_rpi} to enable other researchers to take advantage of our work for future building automation projects.\n\n\n\\medskip\n\nOur automatic HVAC control system is intended for public indoor spaces, such as corridors, libraries, or communal areas. Unlike private spaces such as homes, these public indoor spaces are not controlled by a particular occupant and can be affected by a diverse set of occupancy patterns. Such patterns tend to vary more dynamically in public spaces compared to private ones, posing challenges for effective occupancy sensing and prediction systems.\n\nIn particular, our system is deployed and evaluated for providing automatic HVAC control in the large public indoor space of a mosque (see Figure~\\ref{fig:mosque}), which is the worship place for followers of Islam. Typically, mosques have large public spaces, and are open 24-hours a day and 7-days a week. There are nearly 5,000 mosques in the UAE \\cite{NumberOfMusquesInUAE}, and over 55,000 mosques in Saudi Arabia \\cite{NumberOfMusquesInSaudi}. Due to the hot climate in this region, HVAC is required on a regular basis. The results obtained from our testbed implementation in Section~\\ref{sec:testbed} demonstrate the significant energy savings that can be achieved by using automatic HVAC control systems in public indoor spaces.\n\n\\begin{figure}[htp!]\n \\centering\n \\includegraphics[width=1.0\\linewidth]{figs\/mosque}\n \\caption{A large public indoor space of a mosque is used as a testbed for our automatic HVAC control system. Fisheye video camera, temperature and humidity sensors, as well as real-time controller for HVAC have been deployed in our testbed.}\n \\label{fig:mosque}\n\\end{figure}\n\n\\section{Model}\n\nThe number of occupants is denoted by ${O}(t)$ at time $t$. Consider a single-zone model of a building, where the indoor room temperature is denoted by $T_{\\rm i}(t)$ and outdoor temperature by $T_{\\rm o}(t)$.\nLet $Q_{\\rm AC}(t)$ be heat transfer from HVAC system, where as $Q(O(t))$ be the heat emitted by occupants.\nThe temperature change of $T_{\\rm i}(t)$ is modeled by \n\\begin{equation}\nC_{\\rm r} \\frac{{\\rm d} T_{\\rm i}(t)}{{\\rm d} t} =\n\\frac{T_{\\rm o}(t) - T_{\\rm i}(t)}{R_{\\rm r}} + Q_{\\rm AC}(t) + Q(O(t))\n\\end{equation}\nwhere $C_{\\rm r}$ is the heat capacity of the room, and $R_{\\rm r}$ is the thermal resistance of walls in the room.\n\nBy Euler method, we discretize time into time slots $(t_1, t_2, ..., t_T)$.\n\\begin{equation}\nC_{\\rm r} (T_{\\rm i}(t_i) - T_{\\rm i}(t_{i-1})) =\n\\frac{T_{\\rm o}(t_i) - T_{\\rm i}(t_i)}{R_{\\rm r}} + Q_{\\rm AC}(t_i) + Q(O(t_i))\n\\end{equation}\n\nLet ${\\tt E}(Q_{\\rm AC}(t))$ be the energy consumption for the HVAC system. Let $H(t)$ be the ambient humidity, $\\underline{T}(H(t))$ and $\\overline{T}(H(t))$ be the range of comfortable room temperature with respect to the humidity.\n\nSuppose that the data of occupancy, outdoor temperature and ambient humidity are predicted for an interval $T$, denoted by $\\big(\\hat{O}(t), \\hat{T}_{\\rm o}(t), \\hat{H}(t)\\big)_{t=1}^T$. Define an optimization problem of temperature control given predicted data $\\big(\\hat{O}(t), \\hat{T}_{\\rm o}(t), \\hat{H}(t)\\big)_{t=1}^T$ as follows.\n\n\\begin{align}\n& \\min_{\\big(Q_{\\rm AC}(t)\\big)_{t=1}^T} \\quad \\sum_{t = 1}^T {\\tt E}(Q_{\\rm AC}(t)) \\\\\n& \\mbox{subject to} \\notag \\\\\n& C_{\\rm r} \\frac{{\\rm d} T_{\\rm i}(t)}{{\\rm d} t} =\n\\frac{\\hat{T}_{\\rm o}(t) - T_{\\rm i}(t)}{R_{\\rm r}} + Q_{\\rm AC}(t) + Q(\\hat{O}(t)) \\\\\n& \\underline{T}(\\hat{H}(t)) \\le T_{\\rm i}(t) \\le \\overline{T}(\\hat{H}(t)) \\mbox{\\ if\\ } \\hat{O}(t) \\ge 0\n\\end{align}\n\n\nDefine several control strategies:\n\\begin{enumerate}\n\n\\item ({\\tt MPC}) Model predictive control strategy optimizes $Q_{\\rm AC}(t)$ for an interval $T$, based on predicted data $\\big(\\hat{O}(\\tau), \\hat{T}_{\\rm o}(\\tau), \\hat{H}(\\tau)\\big)_{\\tau=t}^{T+t}$.\n\n\\item ({\\tt AHC}) Ad hoc control strategy optimizes each $Q_{\\rm AC}(t)$ at time $t$ based on previous decisions $\\big(Q_{\\rm AC}(\\tau)\\big)_{\\tau