# Machine-Learning Application for a Likelihood Ratio Estimation Problem at LHC
## 2 The Reweighting Problem
### A Least-Squares Approach to Direct Importance Estimation  
Let us first formulate the direct importance estimation problem as a least-squares-function-fitting problem, as described in [4], that can be readily generalized. From this point, the estimate of quantities of data will be indicated with the symbol \(\widehat{\cdot}\). Let us consider two _pdf_s, \(p_{0}\) and \(p_{1}\), and let us suppose that we have \(N_{0}\) independent and identically distributed (i.i.d.) measurements extracted from \(p_{0}\) and \(N_{1}\) i.i.d. measurements extracted from \(p_{1}\) of \(B\) variables: \(\{X_{i,\ j}^{0}\}_{i=1,\ j=1}^{N_{0},\ B}\) and \(\{X_{i,\ j}^{1}\}_{i=1,\ j=1}^{N_{1},\ B}\). We neither know the analytical form of \(p_{0}(\underline{X})\) and \(p_{1}(\underline{X})\), nor their empirical realization, but we are interested in the ratio between them and can estimate it from the two samples of the extracted measurements. Let us call \(w(\underline{X})=\frac{p_{1}(\underline{X})}{p_{0}(\underline{X})}\) the analytical ratio and \(\widehat{w}(\underline{X})=\sum_{f}\alpha_{f}\cdot\phi_{f}(\underline{X})\) its estimate from data, which can be written as a linear combination of arbitrarily chosen functions of data \(\phi_{f}(\underline{X})\) that must satisfy the same properties of \(w(\underline{X})\):  
* \(w(\underline{X})=\frac{p_{1}(\underline{X})}{p_{0}(\underline{X})}>0\)
* \(w(\underline{X})\to+\infty\) if \(\underline{X}\in p_{1}(\underline{X})\)
* \(w(\underline{X})\to 0\) if \(\underline{X}\in p_{0}(\underline{X})\)  
The coefficients \(\underline{a}\) are constants that are chosen in such a way to obtain the best estimate of \(w(\underline{X})\) by minimizing a loss function which depends on them. Now that we have fixed the notation, we can formulate our minimization problem by defining a loss function as the sum of the quadratic differences between the true value \(w(\underline{X})\) and its estimates on data \(\hat{w}(\underline{X})\). Thus, the loss function \(J_{0}\) can be written with the following expression:  
\[ \begin{split} J_{0}(\underline{a})=E_{0}[(\hat{w}(\underline{X})- w(\underline{X}))^{2}]=\int d\underline{X}\;p_{0}(\underline{X})\;(\hat{w}( \underline{X})-w(\underline{X}))^{2}=\\ \int d\underline{X}\;p_{0}(\underline{X})\;\hat{w}(\underline{X}) ^{2}\;+\int d\underline{X}\;p_{0}(\underline{X})\;w(\underline{X})^{2}\;-\;2 \int d\underline{X}\;p_{0}(\underline{X})\;\hat{w}(\underline{X})\cdot w( \underline{X})=\\ =\int d\underline{X}\;p_{0}(\underline{X})\;\hat{w}(\underline{X} )^{2}\;-2\cdot\int d\underline{X}\;p_{1}(\underline{X})\;\hat{w}(\underline{ X})\end{split}  \tag{2}\]  
Since, in the centre line of (2), the second term does not depend on data, it can be ignored and the expression can be written as follows:  
\[J_{0}(\underline{a})=E_{0}[\hat{w}(\underline{X})^{2}-2\cdot w(\underline{X}) \cdot\hat{w}(\underline{X})]=E_{0}[\hat{w}(\underline{X})^{2}]-2\cdot E_{1}[ \hat{w}(\underline{X})] \tag{3}\]  
This loss function has to be minimized with respect to the constants \(\underline{a}\) on data to obtain the best estimate of \(w(\underline{X})\). If \(\hat{w}(\underline{X})\) is intended as the output of a neural network (NN), and the constants \(\underline{a}\) as its weights \(\underline{\theta}\), the loss function \(J_{0}\) can effectively be taken to be a loss function to be minimized by an NN. Since \(\hat{w}(\underline{X})\) is positively defined, a constraint term should be added to the loss function, or \(\hat{w}(\underline{X})\) should be modified with a monotone function and the loss consequently adapted. For example, the choice of log-likelihood ratio estimation offers a straightforward solution to the problem of a non-negative likelihood ratio. With the latter choice, the variable to be estimated becomes \(\ln(w(\underline{X}))\) and, to obtain the desired quantity, the inverse transformation has to be applied to the network output, as described in [5].