MPoL-dev / MPoL

A flexible Python platform for Regularized Maximum Likelihood imaging
https://mpol-dev.github.io/MPoL/
MIT License
33 stars 11 forks source link

`log_likelihood` loss incorrect and other loss names misleading #237

Closed iancze closed 4 months ago

iancze commented 8 months ago

Describe the bug

The mpol.losses.log_likelihood calculates the likelihood as

Screenshot 2023-12-21 at 11 21 08 AM

When it should actually be closer to

Screenshot 2023-12-21 at 11 22 27 AM

(e.g., Deep Learning: Foundations and Concepts, Eqn 2.66).

There is at least one error in the missing $$\sum_i \ln \sigma_i^2$$ (I think there may still be factors of 2 that remain slightly different from the complex-valued calculations in MPoL vs. the text, which assumes real only), and the source code is missing the negative sign.

This must have been a case of me being more tired than normal, since I think I've implemented this correctly in other codebases. This also implies the mpol.losses.log_likelihood_gridded routine is also incorrect, since it calls mpol.losses.log_likelihood.

Morover, other loss functions in mpol.losses are incorrectly named for the quantity they actually calculate.

Suggested fix

Additional context Recommend that we stay away from the nll name entirely, since it appears to be inconsistently defined in the broader ML context. Sometimes it is the negative log likelihood (i.e. negative of Eqn 2.66) but more often than not it some averaged or normalized factor that does not include the contribution from the weights. These factors matter when building RML workflows and can make it very tricky to intercompare results from different sized datasets.

Downstream updates When fixed, @briannazawadzki @jeffjennings will need to update their calls to mpol.losses.nll_gridded -> mpol.losses.reduced_chi_squared_gridded.