ADFWI.fwi.misfit

ADFWI.fwi.misfit.base

class ADFWI.fwi.misfit.base.Misfit[source]

Bases: object

Abstract base class for Misfit functions.

This class serves as a template for creating specific misfit functions used in inversion problems.

abstract forward()[source]

Abstract method for computing the forward misfit.

This method must be implemented by subclasses to compute the forward misfit based on specific data and models.

Returns:

result – The computed misfit value.

Return type:

float

ADFWI.fwi.misfit.L1

class ADFWI.fwi.misfit.L1.Misfit_waveform_L1(dt=1)[source]

Bases: Misfit

Waveform L1-norm difference misfit (Tarantola, 1984).

This class computes the L1-norm misfit between the observed and synthetic waveforms. The L1-norm is calculated as the sum of the absolute differences between corresponding points in the observed and synthetic waveforms.

Parameters:

dt (float, optional) – Time sampling interval (default is 1).

forward(obs: Tensor, syn: Tensor) Tensor[source]

Compute the L1-norm waveform misfit between observed and synthetic data.

The L1-norm is computed as the sum of absolute residuals, weighted by the time sampling interval dt.

Parameters:
  • obs (torch.Tensor) – The observed waveform, typically with shape (batch, channels, time).

  • syn (torch.Tensor) – The synthetic waveform, typically with shape (batch, channels, time).

Returns:

The L1-norm misfit loss between the observed and synthetic waveforms.

Return type:

torch.Tensor

ADFWI.fwi.misfit.L2

class ADFWI.fwi.misfit.L2.Misfit_waveform_L2(dt=1)[source]

Bases: Misfit

Waveform L2-norm difference misfit (Tarantola, 1984).

This class computes the L2-norm misfit between the observed and synthetic waveforms. The L2-norm is calculated as the square root of the sum of squared residuals between corresponding points in the observed and synthetic waveforms.

Parameters:

dt (float, optional) – Time sampling interval (default is 1).

forward(obs: Tensor, syn: Tensor) Tensor[source]

Compute the L2-norm waveform misfit between observed and synthetic data.

The L2-norm is computed as the square root of the sum of squared residuals, weighted by the time sampling interval dt.

Parameters:
  • obs (torch.Tensor) – The observed waveform, typically with shape (batch, channels, time).

  • syn (torch.Tensor) – The synthetic waveform, typically with shape (batch, channels, time).

Returns:

The L2-norm misfit loss between the observed and synthetic waveforms.

Return type:

torch.Tensor

ADFWI.fwi.misfit.SmoothL1

class ADFWI.fwi.misfit.SmoothL1.Misfit_waveform_smoothL1(dt=1)[source]

Bases: Misfit

Smoothed L1 misfit function (Ross Girshick, 2015, International conference on computer vision) https://pytorch.org/docs/stable/generated/torch.nn.SmoothL1Loss.html

Parameters:

dt (float): Time interval between samples, default is 1.

Methods:

forward(obs, syn):

Computes the smoothed L1 loss between observed and synthetic waveforms.

Args:

obs (Tensor): The observed waveform of shape [num_time_steps, num_shots*num_receivers_per_shot]. syn (Tensor): The synthetic waveform of shape [num_time_steps, num_shots*num_receivers_per_shot].

Returns:

Tensor: The computed smoothed L1 loss value.

forward(obs, syn)[source]

Compute the smoothed L1 loss between the observed and synthetic waveforms.

Args:

obs (Tensor): The observed waveform. syn (Tensor): The synthetic waveform.

Returns:

Tensor: The computed smoothed L1 loss.

ADFWI.fwi.misfit.Envelope

class ADFWI.fwi.misfit.Envelope.Misfit_envelope(dt: float = 1, p: float = 1.5, instaneous_phase: bool = False, norm: str = 'L2')[source]

Bases: Misfit

Compute the envelope misfit for initial velocity model estimation.

This class computes the misfit between observed and synthetic waveforms based on their envelope or instantaneous phase. It is used for estimating the initial velocity model in seismic inversion.

References

Wu et al., 2014; Yuan et al., 2015

Parameters:
  • dt (float, optional) – Time sampling interval (default is 1).

  • p (float, optional) – Norm order for envelope difference (default is 1.5).

  • instaneous_phase (bool, optional) – If True, use instantaneous phase for misfit (default is False).

  • norm (str, optional) – Norm type (“L1” or “L2”) for final loss calculation (default is “L2”).

forward(obs: Tensor, syn: Tensor) Tensor[source]

Compute the misfit between observed and synthetic waveforms.

This function calculates the misfit between the observed and synthetic waveforms either using their envelopes or instantaneous phases, depending on the chosen option.

Parameters:
  • obs (torch.Tensor) – Observed waveform [batch, trace, time].

  • syn (torch.Tensor) – Synthetic waveform [batch, trace, time].

Returns:

Envelope or phase difference loss computed between the observed and synthetic waveforms.

Return type:

torch.Tensor

ADFWI.fwi.misfit.GlobalCorrelation

class ADFWI.fwi.misfit.GlobalCorrelation.Misfit_global_correlation(dt=1)[source]

Bases: Misfit

Global correlation misfit function.

This class computes the global correlation misfit between observed and synthetic waveforms, focusing on their correlation structure across traces.

Parameters:

dt (float, optional) – Time sampling interval (default is 1).

forward(obs: Tensor, syn: Tensor) Tensor[source]

Compute the global correlation misfit between observed and synthetic waveforms.

This function calculates the correlation between each pair of observed and synthetic waveforms across all traces and computes the global misfit.

Parameters:
  • obs (torch.Tensor) – Observed waveform with shape (batch, channels, traces).

  • syn (torch.Tensor) – Synthetic waveform with shape (batch, channels, traces).

Returns:

Correlation-based misfit loss computed between the observed and synthetic waveforms.

Return type:

torch.Tensor

ADFWI.fwi.misfit.StudentT

class ADFWI.fwi.misfit.StudentT.Misfit_waveform_studentT(s=1, sigma=1, dt=1)[source]

Bases: Misfit

Student T Loss (Alvaro et al., 2023; Guo et al., 2023) for waveform misfit calculation.

This loss function uses the Student’s T-distribution to provide robustness against outliers in the waveform difference.

References:

param s:

The number of degrees of freedom (usually 1 or 2). Default is 1.

type s:

float, optional

param sigma:

The scale parameter controlling the spread of the distribution. Default is 1.

type sigma:

float, optional

param dt:

Time interval between samples. Default is 1.

type dt:

float, optional

param obs:

The observed waveform with shape [num_shots, num_time_steps, num_receivers].

type obs:

torch.Tensor

param syn:

The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

type syn:

torch.Tensor

returns:

The computed robust T loss.

rtype:

torch.Tensor

forward(obs, syn)[source]

Compute the robust T loss between the observed and synthetic waveforms.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed robust T loss.

Return type:

torch.Tensor

ADFWI.fwi.misfit.SoftDTW

class ADFWI.fwi.misfit.SoftDTW.Misfit_sdtw(gamma: float | None = 1, sparse_sampling: int | None = 1, dt: float | None = 1)[source]

Bases: Misfit

Soft-DTW misfit function, calculates the soft Dynamic Time Warping (DTW) divergence.

Origin:

https://github.com/toinsson/pysdtw

Soft-DTW divergence:

https://tslearn.readthedocs.io/en/stable/gen_modules/metrics/tslearn.metrics.SoftDTWLossPyTorch.html Mathieu Blondel, Arthur Mensch & Jean-Philippe Vert. “Differentiable divergences between time series,” International Conference on Artificial Intelligence and Statistics, 2021.

param gamma:

Regularization parameter. It should be strictly positive. Lower values lead to less smoothing (closer to true DTW). Default is 1.

type gamma:

float, optional

param sparse_sampling:

Down-sampling the signal for accelerating inversion. Default is 1 (no down-sampling).

type sparse_sampling:

int, optional

param dt:

Time interval between samples. Default is 1.

type dt:

float, optional

param obs:

The observed waveform with shape [num_shots, num_time_steps, num_receivers].

type obs:

torch.Tensor

param syn:

The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

type syn:

torch.Tensor

returns:

The computed soft-DTW loss.

rtype:

torch.Tensor

forward(obs, syn)[source]

Compute the soft-DTW divergence between the observed and synthetic waveforms.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed soft-DTW loss.

Return type:

torch.Tensor

ADFWI.fwi.misfit.Wasserstein_sinkhorn

class ADFWI.fwi.misfit.Wasserstein_sinkhorn.Misfit_wasserstein_sinkhorn(dt: float | None = 1, p: float | None = 2, blur: float | None = 1, scaling: float | None = 0.5, sparse_sampling: int | None = 1, loss_method: str | None = 'sinkhorn')[source]

Bases: Misfit

Compute the Wasserstein Sinkhorn misfit for observed and synthetic waveforms.

This class computes the misfit between observed and synthetic waveforms using the Sinkhorn approximation of the Wasserstein distance. It is used to measure the similarity between time-series signals with regularization.

References

Parameters:
  • dt (float, optional) – Time sampling interval (default is 1).

  • p (float, optional) – Order of the Wasserstein distance (default is 2).

  • blur (float, optional) – Regularization parameter for Sinkhorn divergence (default is 1).

  • scaling (float, optional) – Scaling factor for the loss function (default is 0.5).

  • sparse_sampling (int, optional) – Down-sampling factor for accelerating inversion (default is 1).

  • loss_method (str, optional) – Method used for Sinkhorn loss calculation. Options are ‘sinkhorn’ or ‘exact’ (default is ‘sinkhorn’).

forward(obs, syn)[source]

Compute the Wasserstein Sinkhorn loss between observed and synthetic waveforms.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed Wasserstein Sinkhorn loss.

Return type:

torch.Tensor

ADFWI.fwi.misfit.Normalized_Integration_method

class ADFWI.fwi.misfit.Normalized_Integration_method.Misfit_NIM(p=1, trans_type='linear', theta=1, dt=1)[source]

Bases: Function

Normalized Integration Method (NIM), computes misfit between cumulative distributions of transformed signals.

Parameters:
  • p (int, optional) – Norm degree, default is 2.

  • trans_type (str, optional) – Type of non-negative transform, default is ‘linear’.

  • theta (float, optional) – Parameter for non-negative transform, default is 1.

  • dt (float, optional) – Time sampling interval.

Notes

NIM is equivalent to the Wasserstein-1 distance when p=1.

static backward(ctx, grad_output)[source]

Backward pass to compute the gradients of the misfit with respect to the inputs.

Parameters:

grad_output (Tensor) – The gradient of the loss with respect to the output.

Returns:

Gradients of the inputs.

Return type:

Tuple

static forward(ctx, syn, obs, p=2, trans_type='linear', theta=1.0)[source]

Forward pass to compute the misfit between transformed synthetic and observed signals.

Parameters:
  • syn (Tensor) – Synthetic signal data.

  • obs (Tensor) – Observed signal data.

  • p (int, optional) – Norm degree, default is 2.

  • trans_type (str, optional) – Type of non-negative transform, default is ‘linear’.

  • theta (float, optional) – Parameter for non-negative transform, default is 1.

Returns:

Computed misfit value.

Return type:

Tensor

ADFWI.fwi.misfit.Normalized_Integration_method.trace_max_normalize(x, time_dim=0)[source]

Normalize each trace by its maximum value along the specified dimension. The value of each trace will be in the range [-1, 1] after the processing. Note that the channel should be 1.

Parameters:
  • x (Tensor) – Input tensor.

  • time_dim (int, optional) – Dimension for time steps (default is 0).

Returns:

Normalized tensor.

Return type:

Tensor

ADFWI.fwi.misfit.Normalized_Integration_method.trace_sum_normalize(x, time_dim=0)[source]

Normalize each trace by its sum along the specified dimension.

Parameters:
  • x (Tensor) – Input tensor.

  • time_dim (int, optional) – Dimension for time steps (default is 0).

Returns:

Normalized tensor.

Return type:

Tensor

ADFWI.fwi.misfit.Normalized_Integration_method.transform(f, g, trans_type, theta)[source]

Apply a transformation to make f and g non-negative.

Parameters:
  • f (Tensor) – Seismic data, shape [num_time_steps, num_shots*num_receivers_per_shot].

  • g (Tensor) – Seismic data, shape [num_time_steps, num_shots*num_receivers_per_shot].

  • trans_type (str) – Transformation type (‘linear’, ‘abs’, ‘square’, ‘exp’, ‘softplus’).

  • theta (float) – Scalar parameter for transformation.

Returns:

  • mu (Tensor) – Transformed f.

  • nu (Tensor) – Transformed g.

  • d (Tensor) – Derivative of transformed f for potential use in gradient-based methods.

ADFWI.fwi.misfit.Weci

class ADFWI.fwi.misfit.Weci.Misfit_weighted_ECI(max_iter=1000, dt=1, p=1.5, instaneous_phase=False)[source]

Bases: Misfit

Weighted envelope misfit and global correlation misfit (Song Chao et al., 2023, IEEE TGRS)

This class computes the weighted combination of the envelope misfit and global correlation misfit functions, where the weight is updated iteratively during optimization. The weight increases as the number of iterations progresses, allowing the inversion to progressively shift focus from the global correlation misfit to the envelope misfit.

Parameters:
  • max_iter (int, optional) – The maximum number of iterations for the weight update. Default is 1000.

  • dt (float, optional) – Time interval between samples. Default is 1.

  • p (float, optional) – The norm order for the envelope difference. Default is 1.5.

  • instaneous_phase (bool, optional) – If True, use instantaneous phase for misfit instead of amplitude. Default is False.

Returns:

The computed weighted loss, combining envelope and global correlation misfits.

Return type:

torch.Tensor

forward(obs, syn)[source]

Compute the weighted misfit between the observed and synthetic waveforms.

The weight is updated in each iteration based on the progress of the optimization.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed weighted loss, combining envelope and global correlation misfits.

Return type:

torch.Tensor

ADFWI.fwi.misfit.Weighted_L1_L2

class ADFWI.fwi.misfit.Weighted_L1_L2.Misfit_weighted_L1_and_L2(dt=1, max_iter=1000)[source]

Bases: Misfit

Weighted combination of L1 and L2 waveform misfit functions.

This class combines the L1 and L2 misfit functions in a weighted manner, with the weight dynamically updated throughout the optimization process based on the current iteration.

Some details can be found in: http://www.sce.carleton.ca/faculty/adler/talks/2013/rahmati-CMBES2013-weighted-L1-L2-pres.pdf

Parameters:
  • dt (float, optional) – Time sampling interval. Default is 1.

  • max_iter (int, optional) – The maximum number of iterations for weight update. Default is 1000.

Returns:

The weighted misfit loss between the observed and synthetic waveforms.

Return type:

torch.Tensor

forward(obs, syn)[source]

Compute the weighted misfit between the observed and synthetic waveforms.

The weight between L1 and L2 is dynamically updated during the optimization process.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed weighted loss combining L1 and L2 misfits.

Return type:

torch.Tensor

ADFWI.fwi.misfit.WDGC

class ADFWI.fwi.misfit.WDGC.Misfit_weighted_DTW_GC(max_iter=1000, gamma: float | None = 1, sparse_sampling: int | None = 1, dt: float | None = 1)[source]

Bases: Misfit

Weighted soft-DTW and global correlation misfit (Song Chao et al., 2023, IEEE TGRS)

This class computes the weighted combination of the soft-DTW and global correlation misfit functions, where the weight is updated iteratively during optimization. The weight increases as the number of iterations progresses, allowing the inversion to progressively shift focus from the global correlation misfit to the soft-DTW misfit.

Parameters:
  • max_iter (int, optional) – The maximum number of iterations for the weight update. Default is 1000.

  • gamma (float, optional) – Regularization parameter for soft-DTW. It should be strictly positive. Lower values lead to less smoothing (closer to true DTW). Default is 1.

  • sparse_sampling (int, optional) – Down-sampling factor for the signals to accelerate inversion. Default is 1 (no down-sampling).

  • dt (float, optional) – Time interval between samples. Default is 1.

Returns:

The computed weighted loss, combining soft-DTW and global correlation misfits.

Return type:

torch.Tensor

forward(obs, syn)[source]

Compute the weighted misfit between the observed and synthetic waveforms.

The weight is updated in each iteration based on the progress of the optimization.

Parameters:
  • obs (torch.Tensor) – The observed waveform with shape [num_shots, num_time_steps, num_receivers].

  • syn (torch.Tensor) – The synthetic waveform with shape [num_shots, num_time_steps, num_receivers].

Returns:

The computed weighted loss, combining soft-DTW and global correlation misfits.

Return type:

torch.Tensor