ptyrad.core.losses#

Loss functions and soft regularizations calculated using forward simulations against experimental measurements

Functions

get_objp_contrast(model, indices)

Calculate the contrast from objp zsum imgage for Hypertune purpose

Classes

CombinedLoss(loss_params[, device])

Computes the combined loss for ptychographic reconstruction, incorporating multiple loss components.

class ptyrad.core.losses.CombinedLoss(loss_params, device='cuda')[source]#

Bases: Module

Computes the combined loss for ptychographic reconstruction, incorporating multiple loss components.

This class implements various loss functions that are combined to optimize the reconstruction in ptychography. The loss components include losses based on Gaussian and Poisson statistics, PACBED loss, sparsity regularization, and similarity between different object modes.

Parameters:
  • loss_params (dict) – A dictionary containing the configuration and weights for each of the loss components.

  • device (str, optional) – The device on which the computations will be performed, e.g., ‘cuda’. Defaults to ‘cuda’.

get_loss_single(model_DP, measured_DP)[source]#

Computes the loss based on Gaussian statistics of the diffraction patterns.

get_loss_poissn(model_DP, measured_DP)[source]#

Computes the loss based on Poisson statistics of the diffraction patterns.

get_loss_pacbed(model_DP, measured_DP)[source]#

Computes the PACBED loss by comparing averaged diffraction patterns.

get_loss_sparse(objp_patches, omode_occu)[source]#

Computes the sparsity regularization loss on object phase patches.

get_loss_simlar(obja_patches, objp_patches, omode_occu)[source]#

Computes the similarity loss between different object modes.

forward(model_DP, measured_DP, obja_patches, objp_patches, omode_occu)[source]#

Combines all the loss components and returns the total loss and individual losses.

ptyrad.core.losses.get_objp_contrast(model, indices)[source]#

Calculate the contrast from objp zsum imgage for Hypertune purpose