mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-11-17 03:20:04 +01:00
Finish the tests for the losses
This commit is contained in:
1 parent
595e84cd01
commit
f08a77d6da
2 files changed
+80
-10
No files matched your search
+12
-7
@@ -9,7 +9,7 @@ from __future__ import division, print_function, absolute_import
|
||||
import torch as t
|
||||
|
||||
|
||||
__all__ = ['amplitude_mse', 'intensity_mse', 'poisson_ml']
|
||||
__all__ = ['amplitude_mse', 'intensity_mse', 'poisson_nll']
|
||||
|
||||
|
||||
def amplitude_mse(intensities, sim_intensities, mask=None):
|
||||
@@ -85,8 +85,8 @@ def intensity_mse(intensities, sim_intensities, mask=None):
|
||||
|
||||
|
||||
|
||||
def poisson_ml(intensities, sim_intensities, mask=None):
|
||||
""" Returns the Poisson maximum likelihood metric for a simulated dataset's intensities
|
||||
def poisson_nll(intensities, sim_intensities, mask=None):
|
||||
""" Returns the Poisson negative log likelihood for a simulated dataset's intensities
|
||||
|
||||
Calculates the overall Poisson maximum likelihood metric using
|
||||
diffraction intensities - the measured set of detector intensities -
|
||||
@@ -94,6 +94,10 @@ def poisson_ml(intensities, sim_intensities, mask=None):
|
||||
for detectors in a single-photon counting mode, with their output
|
||||
scaled to number of photons
|
||||
|
||||
Note that this calculation ignores the log(intensities!) term in the
|
||||
full expression for Poisson negative log likelihood. This term doesn't
|
||||
change the calculated gradients so isn't worth taking the time to compute
|
||||
|
||||
It can accept intensity and simulated intensity tensors of any shape
|
||||
as long as their shapes match, and the provided mask array can be
|
||||
broadcast correctly along them.
|
||||
@@ -108,11 +112,12 @@ def poisson_ml(intensities, sim_intensities, mask=None):
|
||||
|
||||
"""
|
||||
if mask is None:
|
||||
t.sum(simulated_intensities -
|
||||
intensities * t.log(simulated_intensities)) \
|
||||
/ intensities.view(-1).shape[0]
|
||||
return t.sum(sim_intensities -
|
||||
intensities * t.log(sim_intensities)) \
|
||||
/ intensities.view(-1).shape[0]
|
||||
|
||||
else:
|
||||
masked_intensities = intensities.masked_select(mask)
|
||||
masked_sims = simulated_intensities.masked_select(mask)
|
||||
masked_sims = sim_intensities.masked_select(mask)
|
||||
return t.sum(masked_sims - masked_intensities *
|
||||
t.log(masked_sims)) / masked_intensities.shape[0]
|
||||
Reference in new issue
Block a user