scico.diagnostics#

Diagnostic information for iterative solvers.

Classes

IterationStats(fields[, ident, display, ...])

Display and record iterative algorithms statistics.

class scico.diagnostics.IterationStats(fields, ident=None, display=False, period=1, shift_cycles=True, overwrite=True, colsep=2)[source]#

Bases: object

Display and record iterative algorithms statistics.

Display and record statistics related to convergence of iterative algorithms.

The fields parameter represents an OrderedDict (to ensure that field order is retained) specifying field names for each value to be inserted and a corresponding format string for when it is displayed. When inserted values are printed in tabular form, the field lengths are taken as the maxima of the header string lengths and the field lengths embedded in the format strings (if specified). For best results, the field lengths should be manually specified based on knowledge of the ranges of values that may be encountered. For example, for a ‘%e’ format string, the specified field length should be at least the precision (e.g. ‘%.2e’ specifies a precision of 2 places) plus 6 when only positive values may encountered, and plus 7 when negative values may be encountered.

Parameters:
  • fields (OrderedDict) – A dictionary associating field names with format strings for displaying the corresponding values.

  • ident (Optional[dict]) – A dictionary associating field names. with corresponding valid identifiers for use within the namedtuple used to record results. Defaults to None.

  • display (bool) – Flag indicating whether results should be printed to stdout. Defaults to False.

  • period (int) – Only display one result in every cycle of length period.

  • shift_cycles (bool) – If True, apply an offset to the iteration count so that display cycles end at 0, period - 1, etc. Otherwise, cycles end at period, 2 * period, etc.

  • overwrite (bool) – If True, display all results, but each one overwrites the next, except for one result per cycle.

  • colsep (int) – Number of spaces seperating fields in displayed tables. Defaults to 2.

Raises:

TypeError – If the fields parameter is not a dict.

insert(values)[source]#

Insert a list of values for a single iteration.

Parameters:

values (Union[List, Tuple]) – Statistics for a single iteration.

end()[source]#

Mark end of iterations.

This method should be called at the end of a set of iterations. Its only function is to ensure that the displayed output is left in an appropriate state when overwriting is active with a display period other than unity.

history(transpose=False)[source]#

Retrieve record of all inserted iterations.

Parameters:

transpose (bool) – Flag indicating whether results should be returned in “transposed” form, i.e. as a namedtuple of lists rather than a list of namedtuples. Default: False.

Returns:

list of namedtuple or namedtuple of lists – Record of all inserted iterations.