nifty7.extra module

assert_allclose(f1, f2, atol=0, rtol=1e-07)[source]
check_linear_operator(op, domain_dtype=<class 'numpy.float64'>, target_dtype=<class 'numpy.float64'>, atol=1e-12, rtol=1e-12, only_r_linear=False)[source]

Checks an operator for algebraic consistency of its capabilities.

Checks whether times(), adjoint_times(), inverse_times() and adjoint_inverse_times() (if in capability list) is implemented consistently. Additionally, it checks whether the operator is linear.

Parameters
  • op (LinearOperator) – Operator which shall be checked.

  • domain_dtype (dtype) – The data type of the random vectors in the operator’s domain. Default is np.float64.

  • target_dtype (dtype) – The data type of the random vectors in the operator’s target. Default is np.float64.

  • atol (float) – Absolute tolerance for the check. If rtol is specified, then satisfying any tolerance will let the check pass. Default: 0.

  • rtol (float) – Relative tolerance for the check. If atol is specified, then satisfying any tolerance will let the check pass. Default: 0.

  • only_r_linear (bool) – set to True if the operator is only R-linear, not C-linear. This will relax the adjointness test accordingly.

check_operator(op, loc, tol=1e-12, ntries=100, perf_check=True, only_r_differentiable=True, metric_sampling=True)[source]

Performs various checks of the implementation of linear and nonlinear operators.

Computes the Jacobian with finite differences and compares it to the implemented Jacobian.

Parameters
  • op (Operator) – Operator which shall be checked.

  • loc (Field or MultiField) – An Field or MultiField instance which has the same domain as op. The location at which the gradient is checked

  • tol (float) – Tolerance for the check.

  • perf_check (Boolean) – Do performance check. May be disabled for very unimportant operators.

  • only_r_differentiable (Boolean) – Jacobians of C-differentiable operators need to be C-linear. Default: True

  • metric_sampling (Boolean) – If op is an EnergyOperator, metric_sampling determines whether the test shall try to sample from the metric or not.

minisanity(data, metric_at_pos, modeldata_operator, mean, samples=None)[source]

Log information about the current fit quality and prior compatibility.

Log a table with fitting information for the likelihood and the prior. Assume that the variables in energy.position.domain are standard-normal distributed a priori. The table contains the reduced chi^2 value, the mean and the number of degrees of freedom for every key of a MultiDomain. If the domain is a DomainTuple, the displayed key is <None>.

If everything is consistent the reduced chi^2 values should be close to one and the mean of the data residuals close to zero. If the reduced chi^2 value in latent space is significantly bigger than one and only one degree of freedom is present, the mean column gives an indication in which direction to change the respective hyper parameters.

Ignore all NaN entries in the target of modeldata_operator and in data. Print reduced chi-square values above 2 and 5 in orange and red, respectively.

Parameters
  • data (Field or MultiField) – Data which is subtracted from the output of model_data.

  • metric_at_pos (function) – Function which takes a Field or MultiField in the domain of mean and returns an endomorphic operator which applies the inverse of the noise covariance in the domain of data.

  • model_data (Operator) – Operator which generates model data.

  • mean (Field or MultiField) – Mean of input of model_data.

  • samples (iterable of Field or MultiField, optional) – Residual samples around mean. Default: no samples.

Note

For computing the reduced chi^2 values and the normalized residuals, the metric at mean is used.