nifty8.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 (nifty8.field.Field or nifty8.multi_field.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(likelihood_energy, samples, terminal_colors=True, return_values=False)[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:
  • likelihood_energy (LikelihoodEnergyOperator) – Likelihood energy of which the normalized residuals shall be computed.

  • samples (SampleListBase) – List of samples.

  • terminal_colors (bool, optional) – Setting this to false disables terminal colors. This may be useful if the output of minisanity is written to a file. Default: True

  • return_values (bool, optional) – If true, in addition to the table in string format, minisanity will return the computed values as a dictionary. Default: False.

Returns:

  • printable_table (string)

  • values (dictionary) – Only returned if return_values is True

Note

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