# Anomaly Detection in Autonomous Deep-Space Navigation via Filter Bank Gating Networks
## 3 Materials and Methods
### Cost Function Definition and Solution Derivation  
The cost function that defines this optimal filter weighting scheme is defined in Equation (5). This equation uses the following notation: \(N\) is the number of filters in the filter bank, \(\vec{p}_{k}\) is the vector of \(N\) filter weightings at the \(k\)th weightings update epoch, \(M\) is the number of measurements included in each weightings update batch, \(\vec{W}\) is a symmetric positive definite weighting matrix that controls how strictly the previous filter weights are enforced, \(\lambda\) is a Lagrange multiplier that enforces the constraint that the filter weightings sum to unity, and \(\vec{1}_{N}\) is an \(N\)-dimensional vector where all entries are one. \[\mathcal{J}(\vec{p}_{k},\lambda;M) =\left(\sum_{i=1}^{N}\sum_{j=(k-1)M+1}^{kM}\frac{1}{2}p_{k,i}^{2} \vec{z}_{i,j}^{T}\Big{[}R_{ij}+\hat{H}_{ij}\hat{P}_{ij}\hat{H}_{i,j}^{T}\Big{]} ^{-1}\vec{z}_{i,j}\right) \tag{5}\] \[+\frac{1}{2}(\vec{p}_{k}-\vec{p}_{k-1})^{T}\vec{W}^{-1}(\vec{p}_ {k}-\vec{p}_{k-1})+\lambda\Big{(}\vec{1}_{N}^{T}\vec{p}_{k}-1\Big{)}\] \[\vec{z}_{i,j} =\vec{y}_{j}-h_{i,j}(t_{j},\vec{x}_{i,j})\] \[\vec{p}_{k} =\left[ \begin{array}{cccc}p_{k,1}&p_{k,2}&\cdots&p_{k,N}\end{array}  \right]^{T}\] \[\hat{H}_{i,j} =\left.\frac{dh_{i,j}(t,\vec{x})}{d\vec{x}}\right|_{(t_{j},\vec{x }_{i,j})}\] \[\vec{p}_{0} =\left(\frac{1}{N}\right)\vec{1}_{N}\]  
This first term in this cost function is designed to penalize filters that generate anomalous predicted measurement residuals using a \(\chi^{2}\) statistical metric. The second term ensures memory is retained within this gating network so that new weights do not differ from a priori weights by too much (where \"too much\" is quantified by \(\vec{W}\)). Finally, the third term in this cost function is a constraint that ensures that the weights from each filter in the bank sum to unity. It is worth noting, that this constraint does not preclude weights from becoming negative; however, the cost function's design should prevent this from occurring. For instance, the first term uses the square of the updated weights on the \(\chi^{2}\) met rics, so making the weights negative is not beneficial. In fact, this would increase the cost, because any negative weight implies the other weights must be larger (to ensure that the constraint is met), which would increase the weighted-\(\chi^{2}\) term. Furthermore, the memory term disadvantages negative weights, as long as the a priori weights are positive. This cost function may be written in tensor form as shown in Equation (6). \[\mathcal{J}(\vec{p}_{k},\lambda;M) =\frac{1}{2}\vec{p}_{k}^{T}G_{k}\vec{p}_{k}+\frac{1}{2}(\vec{p}_ {k}-\vec{p}_{k-1})^{T}\tilde{W}^{-1}(\vec{p}_{k}-\vec{p}_{k-1})+\lambda\Big{(} \vec{\mathrm{T}}_{N}^{T}\vec{p}_{k}-1\Big{)} \tag{6}\] \[G_{k} =\left[ \begin{array}{cccc}G_{k,1}&0&\cdots&0\\ 0&G_{k,2}&\cdots&0\\ \vdots&\vdots&\cdots&\vdots\\ 0&0&\cdots&G_{k,N}\end{array} \right]\] \[G_{k,i} =\sum_{j=(k-1)M+1}^{kM}G_{k,ij}\] \[G_{k,ij} =\vec{z}_{i,j}^{T}\Big{[}R_{i,j}+\tilde{H}_{ij}\tilde{P}_{i,j} \tilde{H}_{ij}^{T}\Big{]}^{-1}\vec{z}_{i,j}\]  
The solution that minimizes this cost function must satisfy the necessary conditions for optimality as defined in Equation (7). \[\vec{\mathcal{J}}_{p} =\left.\frac{d\mathcal{J}(\vec{p},\lambda;M)}{d\vec{p}}\right|_{( \vec{p}_{k},\lambda;M)}=G_{k}\vec{p}_{k}+\tilde{W}^{-1}(\vec{p}_{k}-\vec{p}_{ k-1})+\lambda\vec{\mathrm{I}}_{N}=\vec{0} \tag{7}\] \[\mathcal{J}_{\lambda} =\left.\frac{d\mathcal{J}(\vec{p},\lambda;M)}{d\lambda}\right|_{( \vec{p}_{k},\lambda;M)}=\vec{\mathrm{I}}_{N}^{T}\vec{p}_{k}-1=0\]  
Simplifying these conditions results in the solution that is defined in Equation (8).