% \section{Peak Estimation with Uncertainty for Continuous-Time Systems}
\section{Continuous-Time Uncertain Peak Estimation}
\label{sec:unified}
This section combines the uncertainty formulations from section \ref{sec:uncertainty} to form a pair of primal-dual infinite-dimensional LPs. The variables $\theta \in \Theta, w \in W$ will respectively denote time-independent and  time-dependent uncertainties of sizes $N_\theta, N_w$. The dynamics $f$  have $N_s$ switching subsystems $f_k(t, x, \theta, w)$ which are valid in regions $X_k \subseteq X$.
% The time-varying disturbance process $d(t)$ satisfies integral constraints $\int_{t=0}^T{h_i(d(t)) dt} = e_i$ for $i = 1, \ldots, N_h$. 
% Dynamics may switch arbitrarily between
% \begin{equation}
%     \dot{x} = f_k(t, x, w, d) \qquad k = 1 \ldots N_s.
% \end{equation}

\subsection{Continuous-Time Measure Program}
A combined uncertain peak estimation measure program is detailed in Program \eqref{eq:peak_meas_un} with indices $k=1, \ldots, N_s$ for the switching subsystems,
\begin{subequations}
\label{eq:peak_meas_un}
\begin{align}
p^* = & \ \textrm{max} \quad \inp{p(x)}{\mu_p} & \label{eq:peak_meas_un_obj} \\
    & \mu_p = \delta_0 \otimes\mu_0 + \textstyle\sum_{k} \pi^{tx\theta}_\#\Lie_{f_{k}}^\dagger \mu_{k} \label{eq:peak_meas_un_flow}\\
    & \mu_0(X_0) = 1 & \label{eq:peak_meas_un_prob}\\
    & \mu_{k} \in \Mp{[0, T] \times X \times \Theta \times W} &\forall k\label{eq:peak_meas_un_occ}\\
    & \mu_p \in \Mp{[0, T] \times X \times \Theta} & \\
    & \mu_0 \in \Mp{X_0 \times \Theta}.& \label{eq:peak_meas_un_init}
\end{align}
\end{subequations}
% The symbol $\forall k$ is an abbreviation for $\forall k = 1, \ldots, N_s$.
\begin{thm}
% \vspace{-0.5cm}
The solution $p^*$ to program \eqref{eq:peak_meas_un}  will yield an upper bound to $P^*$ in \eqref{eq:peak_traj}.  \label{thm:peak_meas}
\end{thm}
\begin{proof}
First assume $N_s = 1$ with $X^1=X$, so there is only one switching domain. An optimal achievement of \eqref{eq:peak_traj} reaching the peak value of $P^*$ may be characterized by the tuple $(x_0^*, t^*, x_p^*, \theta^*, w^*(t))$. The peak value $p(x_p^*) = P^*$ is achieved by following the trajectory $x(t \mid x_0^*, \theta^*, w^*(t))$ until time $t=t^*$. Measures $ (\mu_0, \mu_p, \mu)$ may be defined from this optimal tuple such that the measures satisfy constraints
\eqref{eq:peak_meas_un_flow}-\eqref{eq:peak_meas_un_init}. The initial measure and peak measure may be set to $\mu_0 = \delta_{x=x_0^*}$ and $\mu_p =  \delta_{t=t^* }\otimes \delta_{x=x_p^*} \otimes \delta_{\theta = \theta^*}$ based on the optimal tuple. The measure $\mu \in \Mp{[0, T] \times X \times \Theta \times W}$ may be defined as the unique occupation measure satisfying,
\begin{equation}
    \inp{\tilde{v}}{\mu} =  \int_{t=0}^{t^*} \tilde{v}(t, x(t \mid x_0^*, \theta^*, w^*(t)), \theta^*, w^*(t)) dt,
\end{equation}
for all test functions $\tilde{v} \in C([0, T ] \times X \times \Theta \times W)$.
% supported on the graph $(t, x(t \mid x_0^*, \theta^*, w^*(t)), \theta^*, w^*(t))$ between times $t\in[0, t^*]$. 
The measures $(\mu_0, \mu_p, \mu)$ satisfy constraints \eqref{eq:peak_meas_un_flow}-\eqref{eq:peak_meas_un_init}, so $p^* \geq P^*$ when $N_s = 1$. 
% If $P^*$ is achieved multiple times, then the individual optima may be expressed as tuples (similar to section III-A of \cite{miller2020recovery}). Convex combinations of measures $(\mu_0, \mu_p, \mu)$ for each optimal point will form valid measure solution to \eqref{eq:peak_meas}.


Optimal trajectories arising from a  system with $N_s > 1$ may be described in a tuple as $(x_0^*, t^*, x_p^*, \theta^*, w^*(t), S^*(t))$, where $S^*(t)$ is the sequence of switches undergone between times $t \in [0, t^*]$. The measures $\mu_0$ and $\mu_p$ may remain the same as in the non-switched case. Switching occupation measures $\mu_k$ may be set to the unique occupation measure supported on the graph $(t, x(t \mid x_0^*, \theta^*, w^*(t)), \theta^*, w^*(t))$ between times $t\in[0, t^*]$ when $S(t) = k$. These occupation measures satisfy constraints \eqref{eq:peak_meas_un_flow} and \eqref{eq:peak_meas_un_occ}, proving that there exists a feasible solution to \eqref{eq:peak_meas_un_flow}-\eqref{eq:peak_meas_un_init} with objective $P^*$ for the case of switching.
\end{proof}
% \vspace{-0.5cm}


% When $p(x)$ is locally Lipschitz and all spaces are compact, the solution $p^*$ from \eqref{eq:peak_meas_un} is approximately equal to $P^*$ from \eqref{eq:peak_traj} by Theorem 2.1 of \cite{lewis1980relaxation}.


% The LMI formulation of \eqref{eq:peak_meas_un} is available at \urg{TODO: Add in the LMI}.

\subsection{Continuous-Time Function Program}
Dual variables $v(t,x,\theta) \in C^1([0,  T] \times X \times \Theta)$ and $\gamma \in \R$ can be defined to find the Lagrangian of \eqref{eq:peak_meas_un}. 
% In addition to $v(t,x,w)$ and $\gamma$ from \eqref{eq:peak_cont} on constraints \eqref{eq:peak_meas_un_flow} and \eqref{eq:peak_meas_un_prob}, functions $\zeta_{k \ell}$ are required on constraints  \eqref{eq:peak_meas_un_abscont} for each $(k, \ell)$. 
% The Lagrangian is:
\begin{align}
    \scL &= \inp{p(x)}{\mu_p} + \inp{v(t,x,\theta)}{\delta_0 \otimes\mu_0 + \textstyle\sum_{k} \pi^{tx\theta}_\# \Lie_{f_{k}}^\dagger \mu_{k}} \nonumber\\
    &+ \inp{v(t,x,\theta)}{- \mu_p} + \gamma(1 - \inp{1}{\mu_0}). \nonumber
\end{align}
% The projection pushforward ensures that the auxiliary function $v(t, x, \theta)$ is not a function of $w$.
% %     L &= \inp{p(x)}{\mu_p} + \inp{v(t,x,w)}{\delta_0 \otimes\mu_0 + \textstyle\sum_{k} \Lie_{f_{0k}}^\dagger \mu_{k}} \nonumber\\
%     &+ \inp{v(t,x,w)}{\textstyle\sum_{k\ell}(f_{k \ell} \cdot \nabla_x)^\dagger \sigma_{k \ell} - \mu_p} \nonumber\\
%     &+ \gamma(\inp{1}{\mu_0} - 1) + \textstyle\sum_i \lambda_i (\inp{h_i(d)}{\textstyle\sum_{k} \mu_{k}} - e_i)\\
%     &+ \textstyle\sum_{k \ell} \inp{\zeta_{k \ell}(t, x, w, d)}{\mu_k - \sigma_{k \ell} - \hat{\sigma}_{k \ell} }. \nonumber
The resulting dual program in $(v, \gamma)$ is,
\begin{subequations}
\label{eq:peak_cont_un}
\begin{align}
    d^* = & \ \min_{\gamma \in \R} \quad \gamma \label{eq:peak_cont_un_obj}\\
    & \forall (x, \theta) \in X_0 \times  \Theta: \nonumber \\
    & \quad {\gamma} \geq {v(0, x, \theta)}  &   \label{eq:peak_cont_un_init}\\
    & \forall (t, x, \theta, w) \in [0, T] \times X_k \times  \Theta \times W: \quad \forall k \nonumber \\
    & \quad \Lie_{f_{k}} v(t, x, \theta)\leq 0 \label{eq:peak_cont_un_flow}\\
    & \forall (t, x, \theta) \in [0, T] \times X \times  \Theta: \nonumber \\
    & \quad v(t, x, \theta) \geq p(x) \label{eq:peak_cont_un_p}  \\
    &v(t, x, \theta) \in C^1([0, T]\times X \times \Theta) \label{eq:peak_cont_un_v}.
\end{align}
\end{subequations}
\begin{thm}
There is no duality gap between \eqref{eq:peak_meas_un} and \eqref{eq:peak_cont_un} when the set $[0, T] \times X \times \Theta \times W$ is compact.
\label{thm:peak_strong}
\end{thm}
\begin{proof}
Necessary and sufficient conditions for there to be no duality gap between measure and function programs are if all measures are bounded and if the affine map is closed in the weak-* topology (Theorem C.20 of \cite{lasserre2009moments}).
A measure is bounded if all of its finite-degree moments are bounded. Boundedness will hold if the mass of the measure is bounded and the support of the measure is compact. In \eqref{eq:peak_meas_un} $\mu_0$ and $\mu_p$ each have mass 1, and the mass of $\sum_k \mu_k \leq T$ by Liouville's equation. Compactness of $[0, T] \times X \times \Theta \times W$ therefore assures that all measures are bounded. The image of the affine map $(\mu_0, \mu_p, \mu_k) \rightarrow (\delta_0 \otimes \mu_0 + \sum_k \pi_\#^{tx\theta} \Lie_{fk}^\dagger \mu_k - \mu_p,  \mu_0)$  induced by constraints \eqref{eq:peak_meas_un_flow}-\eqref{eq:peak_meas_un_prob} is closed in the weak-* topology. Strong duality therefore holds by closure and boundedness of measures.
\end{proof}
% Strong duality between \eqref{eq:peak_meas_un} and \eqref{eq:peak_cont_un} holds by Theorem C.20 of \cite{lasserre2009moments} just as in Section \ref{sec:peak} when $[0, T] \times X_k \times W \times \Delta$ are compact for all $k$.
% All measures $(\mu_0, \mu_p, \mu_k)$ have bounded moments, and the image of the affine maps in \eqref{eq:peak_cont_un_init}-\eqref{eq:peak_cont_un_p} are closed in the weak-* topology. 
% If the functions $v, \zeta_{k \ell}$ are allowed to be discontinuous then \eqref{eq:peak_cont_un} will produce a bound $d^* = P^*$ matching \eqref{eq:peak_traj}.


The measure $\mu_0$ has $N_x + N_\theta$ variables, and $\mu_p$ has $1 + N_x + N_\theta$ variables. The $N_s$ occupation measures $\mu_k$ each have $1 + N_x +  N_\theta + N_w$ variables. If the switching structure was not taken into account by the methods of section  \ref{sec:switching}, there would be a single occupation measure $\mu$ with $1 + N_x + N_\theta + N_w +  N_s$ variables. The affine uncertainty structure breaks up the large $\mu$ (in terms of the number of variables) into $N_s$ smaller measures $(\mu_k)$.

\subsection{Continuous-Time LMI Relaxation}

\label{sec:lmi_cont}
The compact (Archimedean) basic semialgebraic sets in the uncertain peak estimation setting are
\begin{subequations}
\label{eq:peak_sets}
\begin{align}
    X &= \{x \mid g_i(x)\geq 0 & &\mid \ i = 1, \ldots, N_c\} \\
    X_0 &= \{x \mid  g_{0i}(x)\geq 0 & &\mid \ i = 1, \ldots, N_c^0\}\\
    X^k &= \{x \mid g_{ki}(x)\geq 0 & &\mid \ i = 1, \ldots, N_c^k\} \\
    \Theta &= \{\theta \mid g_{\theta i}(\theta)\geq 0 & &\mid \ i = 1, \ldots, N_c^\theta\}\\
    W &= \{w \mid g_{wi}(w)\geq 0 & &\mid \ i = 1, \ldots, N_c^w\}.
\end{align}
\end{subequations}

The degree of $g_i(x)$ is $d_i$, and other degrees $d_{0i}, \ d_{\theta i}, \ d_{wi}, \ d_{ki}$ are defined on corresponding polynomials. Monomials forming moments may be indexed as  $x^\alpha t^\beta \theta^\gamma w^\eta$ for multi-indices $\alpha \in \N^{N_x}, \ \beta \in \N, \ \gamma \in \N^{N_\theta}, \ \eta \in \N^{N_w}$. Define $y^0 = \{y^0_{\alpha \gamma} \}, \ y^p = \{y^p_{\alpha \beta \gamma}\}$ as the moment sequences for measures $\mu_0$ and $\mu_p$. The moment sequence for the occupation measure $\mu^k$ is $y^k = \{y^k_{\alpha \beta \gamma \eta}\}$ for each switching subsystem $k$. 
% The box-affine disturbance occupation measures $\sigma_{k\ell}, \hat{\sigma}_{k\ell}$ likewise have moment sequences $s^{k\ell} = \{s^{k \ell}_{\alpha \beta \gamma \delta}\}, \ \hat{s}^{k \ell} = \{\hat{s}^{k\ell}_{\alpha \beta \gamma \delta}\}$. 
The Liouville equation \eqref{eq:peak_meas_un_flow} with test function $v(t, x, \theta) = x^\alpha t^\beta \theta^\gamma$ has the form,
\begin{align}
\label{eq:liou_lmi_unc}
    0&= \inp{x^\alpha t^\beta \theta^\gamma}{ {\delta_0 \otimes \mu_0}} - \inp{x^\alpha t^\beta \theta^\gamma}{\mu_p} \\
    &+ \textstyle \sum_k\inp{\Lie_{f_{k}(t, x, \theta, w)}( x^\alpha t^\beta \theta^\gamma)}{\mu_k}. \nonumber
\end{align}
Define the operator $\textrm{Liou}_{\alpha \beta\gamma }(y^0, y^p, y^k)$ as the linear relation between the moment sequences induced by \eqref{eq:liou_lmi_unc} assuming that each $f_k$ is a polynomial vector field. Given a degree $d$,  define the degrees $d_k'$ as $d + \ceil{\textrm{deg}(f_k)/2} - 1$ for each $k$.
% , just as in problem \eqref{eq:peak_lmi}.
The degree-$d$ LMI relaxation of the uncertain peak estimation problem in  \eqref{eq:peak_meas_un} resulting in an upper bound $p^*_d \geq P^*$ is, 
\begin{subequations}
\label{eq:peak_lmi_un}
\begin{align}
    p^*_d = & \textrm{max} \quad \textstyle\sum_{\alpha} p_\alpha y_{\alpha 0 0}^p \label{eq:peak_lmi_un_obj} \\
    & \quad \textrm{Liou}_{\alpha \beta \gamma}(y^0, y^p, y^k) = 0 \quad \textrm{by \eqref{eq:liou_lmi_unc}} & &\forall \abs{\alpha} + \abs{\beta} + \abs{\gamma} \leq 2d   \label{eq:peak_lmi_un_flow}\\
    & y^0_0 = 1 \\
    & \M_d(y^0), \M_d(y^p), \forall k: \M_{d'_k}(y^k) \succeq 0 \label{eq:peak_lmi_un_psd} \\
    &\M_{d-2}(t(T-t)y^p) \succeq 0 \label{eq:peak_lmi_un_time}\\
    &\forall k: \M_{d'_k-2}(t(T-t)y^k) \succeq  0 \label{eq:peak_lmi_un_time2}\\
    & \M_{d - d_{0i}}(g_{0i} y^0) \succeq 0  & & \forall i = 1, \ldots, N_c^0  \label{eq:peak_lmi_un_init}  \\
    & \M_{d - d_{\theta i}}(g_{\theta i} y^0), \ \M_{d - d_{\theta i}}(g_{\theta i} y^p) \succeq 0 & & \forall i = 1, \ldots, N_c^\theta\\ 
    &\forall k: \M_{d_k'- d_{\theta i}}(g_{\theta i} y^k) \succeq 0 & & \forall i = 1, \ldots, N_c^\theta \label{eq:peak_lmi_un_init_w} \\
    &\M_{d - d_i}(g_{i} y^p) \succeq 0 & & \forall i = 1, \ldots, N_c\\ 
    &\forall k:  \M_{d_k'- d_{ki}}(g_{ki} y^k) \succeq 0 & & \forall i = 1, \ldots, N_c^k\\ 
    &\forall k: \M_{d - d_{wi}}(g_{wi} y^k) \succeq 0 & & \forall i = 1, \ldots, N_c^w. \label{eq:peak_lmi_un_d}
\end{align}
\end{subequations}

% Many of the constraints and definitions are similar to the standard peak estimation problem in \eqref{eq:peak_lmi}. 
% Constraint \eqref{eq:peak_lmi_un_abscont} enforces the absolute continuity condition $\sigma^{k \ell} + \hat{\sigma}^{k \ell} = \mu^k$ in \eqref{eq:peak_meas_un_abscont}. 
Constraints \eqref{eq:peak_lmi_un_psd}- \eqref{eq:peak_lmi_un_d} are moment and localizing matrix PSD constraints ensuring that there exist representing measures to the moment sequences $(y^0, y^p, y^k)$ supported on the appropriate spaces. The sequence $\{p^*_d\}$ will converge to $p^*$ monotonically from above
as $d\rightarrow \infty$ if all sets in \eqref{eq:peak_sets} are Archimedean \cite{lasserre2009moments}.




  
% Stuff