but uses a cost function weighted by occupancy predictions from a self-training stochastic model (Figure \[fig:ProposedArch\]). At each step, the system measures how much of the previous hour the space was occupied, and the expected occupancy is used to find the best sequence of $N$ future heat inputs to the thermal zone that minimizes the expected cost. The optimization is $$\begin{aligned}\min_{u_{k}\cdots u_{k+N-1}}\quad & \sum_{j=0}^{N-1}{\mathbb{E}\left[g(x_{k+j},u_{k+j},\tau,\Gamma_{k+j})\right]}\\
\textrm{subject to\quad} & \begin{aligned}x_{i+1} & =Ax_{i}+B_{u}u_{i}+B_{w}{\mathbb{E}\left[w_{i}\right]}\quad\forall i\in\mathbb{Z}^{+}\\
0 & \leq u\leq u_{\max}
\end{aligned}
\end{aligned}
\label{eq:firstMpcDef}$$ where

-   $k\in\mathbb{Z}^{+}$ is the current time step, and $j\in[0,N-1]$ is the optimization index over the horizon;

-   $A\in\mathbb{R}^{n\times n}$ describes the building’s thermal dynamics;

-   $x\in\mathbb{R}^{n\times1}$ contains the building’s thermal state;

-   $u_{k\ldots k+N-1}$ contains the controller output, constrained within the system’s capacity $u_{\max}$;

-   $B_{u}$ is a vector that connects the heat input $u$ to the zone air volume;

-   $w_{k}$ is the current weather observation, and $w_{k+1\ldots k+N-1}$ contains an up-to-date weather prediction;

-   $B_{w}$ is a vector that connects the weather conditions to the building envelope;

-   $\tau$ is the temperature setpoint, which is constant for this study (but can be varied in practice);

-   $\Gamma_{k}$ is the latest occupancy measurement, and $\Gamma_{k+1\ldots k+N-1}$ are the predicted 