## Adaptive Optics

#### Optimal Command

For exposure \(t\), the data write \[y_t = S_t \cdot (w_t - M_t \cdot a_t) + e_t\] where \(S_t\) is the sensor, \(w_t\) is the wavefront, \(a_t\) is the vector of actuator commands, \(M_t\) is the miror response matrix and \(e_t\) accounts for noise and errors.

The best command for \(t+1\) is the one which minimizes the expected value of the residual wavefront given the past data and commands. That is: \[a_{t+1} = \arg\min_{a} \mathrm{E}\left\{\left.\Vert w_{t+1} - M_{t+1} \cdot a\Vert^2\right\vert y_{1}, \ldots, y_{t}, a_{1}, \ldots, a_{t}\right\}\]

Let's denote \(p_{t+1}(w)\) the marginal probability density function of the wavefront \(w_{t+1}\) at time \(t+1\), then: \[a_{t+1} = \arg\min_{a} \int \Vert w - M_{t+1} \cdot a\Vert^2 \, p_{t+1}(w) \, \mathrm{d}w \, .\] Since the expression in the right hand side is quadratic with respect to \(a\), a stationary point verifies the normal equations: \[ M_{t+1}^{\top} \cdot M_{t+1} \cdot a^{+} = M_{t+1}^{\top} \cdot \frac{\int w \, p_{t+1}(w) \, \mathrm{d}w}{\int p_{t+1}(w) \, \mathrm{d}w} \, .\] Taking the minimal norm solution, yields: \[a_{t+1} = M_{t+1}^{\dagger} \cdot \mathrm{E}\left\{w_{t+1} \vert y_{1}, \ldots, y_{t}, a_{1}, \ldots, a_{t}\right\} ,\] which is the generalized inverse \[M_{t+1}^{\dagger} = \left(M_{t+1}^{\top} \cdot M_{t+1}\right)^{-1} \cdot M_{t+1}^{\top} \] of the miror response at time \(t+1\) applied to the expected wavefront (at the same time) given the past data and commands: \[\begin{align}\mathrm{E}\left\{w_{t+1} \vert y_{1}, \ldots, y_{t}, a_{1}, \ldots, a_{t}\right\} &= \frac{\int w \, p_{t+1}(w) \, \mathrm{d}w}{\int p_{t+1}(w) \, \mathrm{d}w} \notag\\ &= \int w \, p_{t+1}(w) \, \mathrm{d}w\notag\end{align}\] where the last expression is for a normalized probability density function.

Hence * finding the best command amounts to estimate the expected value of the wavefront at the time of the correction and given all available information* (the past data and commands).

Note that \(M_{t+1}^{\dagger}\) is also called the *projector*.

#### Marginal PDF

To simplify the notations, we introduce \[z_t = \{y_{1}, \ldots, y_{t}, a_{1}, \ldots, a_{t}\}\] the set of past data and commands.

The joint PDF of the random variables, wavefronts \(w = \{w_{1}, \ldots, w_{t+1}\}\) and measurements \(y = \{y_{1}, \ldots, y_{t}\}\), given the past commands \(a = \{a_{1}, \ldots, a_{t}\}\) writes:\[\begin{align}\mathrm{pdf}(y, w \vert a) &= \mathrm{pdf}(w \vert a) \, \mathrm{pdf}(y \vert a, w) \notag \\ &= \mathrm{pdf}(w) \, \prod_{t'=1}^{t} \mathrm{pdf}(y_{t'}\vert w_{t'}, a_{t'})\end{align}\] where the first equation comes from Bayes' theorem, the simplifications at the second line are due to the independancy of the wavefonts and the commands and because the data noise is independent at different times while the data only depends on the wavefront and commands at the same time.

Assuming Gaussian noise: \[\mathrm{pdf}(y_{t} \vert a_{t}, w_{t}) = \frac{\exp\left(-\frac{1}{2}\,(y_t - S_t \cdot (w_t - M_t \cdot a_t))^{\top}\cdot N_{t}^{-1} \cdot (y_t - S_t \cdot (w_t - M_t \cdot a_t))\right)}{(2\,\pi)^{m/2} \, \vert N_{t} \vert^{1/2}} \, , \] with \(m\) the number of measuments (at a given time) and \(N_t\) the covariance of the noise.