
Submissions are evaluated using negative log likelihood metric.

Let:

- *x* be horizontal location along the well which in the task is replaced by its index 1..300,
- **b^{T}(x)** be the true geological boundary,
- *b_{i}(x)* be a predicted geology realization number *i*,
- **D_T^{-1}(x)**  is an approximation of a diagonal of an idealized covariance matrix.

We can compute a simple misfit vector between  a single prediction and the truth as:

$$
e_{i}(x) = b^{T}(x) - b_{i}(x)
$$

Assuming that each geological predicion defines a center line of a Gausian kernel with varience **D_{T}**
we can define "Gaussian" or exponential misfit **E_{i,G}** as follows  

$$
  E_{i,G} = exp (e_{i}(x) \cdot D_T^{-1}(x) e_{i}(x)),  
$$
where $\cdot$ is the inner product, and **E_{i,G}** are 10 numbers corresponding to the respective predctions. 

Finally, we can write the weighted negative log likelihood loss formula used for the evaluation:

$$
  loss = - log (\sum_{i=0..9} p_i * E_{i,G}),
$$
where *p_i* is the probability of each kernel; 
the realizations are assumed equiprobable: *p_i = 1/10*.

The system returns the mean of the *loss* over the test data.

### Idealized covariance matrix

**D_T^{-1}(x)** is derived by curve-fitting based on the training and test data.
Each part can be represented as:

$$
D_T^{-1}(x) = exp \left( \log(x) a_k + b_k] \right),
$$
where **a_k** (`log_slopes`) and **b_k** (`log_offsets`) are imperical constants depending on the growth mode **k**:
- **k=1** Close prediction with exponential growth of errors, *x = 1..60*
- **k=2** Region with stable errors *x = 61..244*
- **k=3** Region with further growth of errors *x = 245..300*

The constants for *a* and *b* are provided by these arrays:

```python
log_slopes = [1.0406028049510443, 0.0, 7.835345062351012]
log_offsets = [-6.430669850650689, -2.1617411566043896, -45.24876794412965]
```

### References 

For description of the NLL loss see 
1. [NLL concept, Wikipedia](https://en.wikipedia.org/wiki/Negative_log_predictive_density)
2. [Gaussian function (error), Wikipedia](https://en.wikipedia.org/wiki/Gaussian_function)
3. [Discussion of applying this loss to geological boundaries in Alyaev and Elsheikh 2022](https://doi.org/10.1029/2021EA002186) 
4. [The current evaluation-metric code](https://www.kaggle.com/code/alin256/nll-for-1d-geology-metric-v5)

### Output format
#### Columns **1**..**300**
Geology to be predicted (realization 0 out of 10, zero-indexed). 

#### Columns **r_1_pos_1**..**r_1_pos_300** ... **r_9_pos_1**..**r_9_pos_300**
Geology to be predicted (realizations 1 to 9 out of 10, zero-indexed). 

Note: The order of the realizations **0 to 10** does not change the score. 
This includes realization 0 described above.  