prtools.sserror#

sserror(data, est, mask=None, gain_bias_invariant=False, ghat=None)[source]#

Compute the normalized sum squared error between two arrays.

The error between measured data \(\tilde{s}\) and estimated data \(\hat{s}\) is computed as the gain invariant error metric

\[\Phi = \frac{1}{K}\sum_k \frac{\sum_{x,y} w(x,y,k)\left[\alpha_k\hat{s}(x,y,k) - \tilde{s}(x,y,k)\right]^2}{\sum_{x,y} w(x,y,k)\tilde{s}^2(x,y,k)}\]

for \(k = 1, 2, ... K\) independent measurements, where \(w\) is a weighting function given by mask and each \(\alpha_k\) is chosen to minimize the error. The result is independent of any relative scaling (gain) difference between the inputs.

If gain_bias_invariant is True, the gain and bias invariant error metric is computed instead

\[\Phi = \frac{1}{K}\sum_k \frac{\sum_{x,y} w(x,y,k)\left[\alpha_k\hat{g}(x,y,k) - \tilde{g}(x,y,k)\right]^2}{\sum_{x,y} w(x,y,k)\tilde{s}^2(x,y,k)}\]

where \(\hat{g}\) and \(\tilde{g}\) are \(\hat{s}\) and \(\tilde{s}\) with their weighted means subtracted and each \(\alpha_k\) is chosen to minimize the error. The result is independent of any relative scaling (gain) and offset (bias) differences between the inputs.

Parameters:
  • data (array_like) – Ideal or measured data with shape (M, N) or (K, M, N)

  • est (array_like) – Estimated or modeled data with the same shape as data

  • mask (array_like, optional) – Weighting function \(w\) applied to the inputs. Entries equal to 1 (or True) are fully included in the error computation and entries equal to 0 (or False) are ignored. Intermediate values partially weight the corresponding elements. Mask must either have the same shape as the inputs or be broadcastable to the same shape. If None (default), all elements are equally weighted.

  • gain_bias_invariant (bool, optional) – If True, the error is computed to be independent of any gain or bias differences between the inputs. If False (default), the error is computed to be independent of any gain differences between the inputs.

  • ghat (array_like, optional) – Precomputed bias-subtracted estimate \(\hat{g}\). Only used if gain_bias_invariant is True. If None (default), \(\hat{g}\) is computed from est.

Returns:

error – Normalized sum squared error

Return type:

float

References

[1] S. Thurman and J. Fienup, “Phase retrieval with signal bias”, J. Opt. Soc. Am. A/Vol. 26, No. 4 (2009)

[2] A. Jurling and J. Fienup, “Applications of algorithmic differentiation to phase retrieval algorithms”, J. Opt. Soc. Am. A/Vol. 31, No. 7 (2014)