Estimators

Overview

Coming Soon!

Interface

This module contains a base class for argument estimators, which should inherit from this class and supply a concrete implementation.

Authors:

  • Philipp Schuette

class pyzeal.algorithms.estimators.argument_estimator.ArgumentEstimator(*args, **kwargs)[source]

Interface for argument estimators. calcMoment us implemented here, while the concrete method of evaluation is determined by overriding calcMomentAlongLine.

abstract property cache: EstimatorCache

Returns the cache used by this argument estimator.

Returns:

Cache used by this argument estimator.

calcMoment(order, reRan, imRan, context)[source]

Calculate the order-th moment of the logarithmic derivative of the target function context.f along the boundary of the rectangle specified by reRan x imRan. The concrete method by which the integral of the logarithm derivative gets calculated is determined by overriding calcMomentAlongLine.

Parameters:
  • order (int) – Order of the moment to be calculated.

  • reRan (Tuple[float, float]) – Interval describing the real part of the rectangle

  • imRan (Tuple[float, float]) – Interval describing the imaginary part of the rectangle

  • context (RootContext) – RootContext containing the necessary information.

Returns:

complexorder-th moment of the logarithmic derivative of context.f along the boundary of the specified rectangle.

abstract calcMomentAlongLine(order, zStart, zEnd, context)[source]

Calculate the order-th moment of the logarithmic derivative of the target function context.f along the line given by zStart and zEnd.

Parameters:
  • order (int) – Order of the moment to calculate

  • zStart (complex) – Starting point of the line

  • zEnd (complex) – End point of the line

  • context (RootContext) – RootContext containing the necessary information.

Returns:

complex – The moment as calculated along the given line.

genFuncArr(zStart, zEnd, context, size)[source]

TODO.

Return type:

Tuple[ndarray[Any, dtype[complex128]], ndarray[Any, dtype[complex128]]]

Quadrature Estimator

This module provides an argument estimator based on numerical integration using Romberg quadrature.

Authors:

  • Philipp Schuette

class pyzeal.algorithms.estimators.quad_estimator.QuadratureEstimator(*, cache)[source]

This class implements an argument estimator using numerical quadrature to integrate the logarithmic derivative.

__init__(*, cache)[source]

Initialize a QuadratureEstimator.

Parameters:

cache (EstimatorCache) – Cache to store intermediate values in.

property cache: EstimatorCache

Returns the cache used by this argument estimator.

Returns:

Cache used by this argument estimator.

calcMomentAlongLine(order, zStart, zEnd, context)[source]

Calculate the order-th moment of the logarithmic derivative along the line given by zStart and zEnd.

Parameters:
  • order (int) – Moment to compute

  • zStart (complex) – Start z-value

  • zEnd (complex) – End z-value

  • context (RootContext) – RootContext containing the necessary information

Raises:

ValueError – An error is raised when no derivative is supplied, as the QuadratureEstimator does not support derivative-free argument estimation.

Returns:

complex – The moment as calculated along the given line.

static mergeArrays(oldArrays, newArrays)[source]

TODO.

Return type:

Tuple[ndarray[Any, dtype[complex128]], ndarray[Any, dtype[complex128]]]

Summation Estimator

This module provides a simple argument estimator based on summation of incremental changes in the phase of the argument.

Authors:

  • Philipp Schuette

class pyzeal.algorithms.estimators.sum_estimator.SummationEstimator(*, numPts, deltaPhi, maxPrecision, cache)[source]

Class implementation of a simple argument estimator.

It is based on discretizing the path of integration and summing the change of argument between these points to compute the integral of the logarithmic derivative.

__init__(*, numPts, deltaPhi, maxPrecision, cache)[source]

Initialize a SummationEstimator with given settings.

Parameters:
  • numPts (int) – Number of points used for estimation.

  • deltaPhi (float) – Threshold for argument change. When the change in argument between two points exceeds this, it will be further refined.

  • maxPrecision (float) – Maximum precision for refinement

  • cache (EstimatorCache) – Cache to store intermediate computation results.

property cache: EstimatorCache

Returns the cache used by this argument estimator.

Returns:

Cache used by this argument estimator.

calcMomentAlongLine(order, zStart, zEnd, context)[source]

The result of this method coincides exactly with the integral of the logarithmic derivative as long as the increments remain below the threshold of \(\pi\). It can be proven that local function information is not sufficient to verify this condition in general.

Parameters:
  • order (int) – Moment to calculate

  • zStart (complex) – Starting point of the line

  • zEnd (complex) – End point of the line

  • context (RootContext) – RootContext containing the necessary information

Raises:

ValueError – An error is raised if the line is not parallel to either the real or imaginary axis.

Returns:

complex – The moment as calculated along the given line.

genPhiArr(order, zStart, zEnd, context)[source]

Calculate an array of complex argument values from the function values of the target function context.f on the complex line [zStart, zEnd]. Zeros of the target function found during this procedure are put into context.container immediately and the complex line is adjusted by translating into direction pos by a small offset. The number of support points on the line is adjusted dynamically.

Parameters:
  • order (int) – The moment which is to be calculated.

  • zStart (complex) – Starting point of the line segment.

  • zEnd (complex) – End point of the line segment.

  • context (RootContext) – Context of the current calculation.

Returns:

Tuple[ndarray[Any, dtype[complex128]], ndarray[Any, dtype[complex128]]] – Points along with estimated change of argument between them.

retrieveCachedHorizontal(order, x1, x2, y, context)[source]

Try to retrieve the moment along a horizontal line from cache, calculating it if necessary.

Parameters:
  • order (int) – Moment to retrieve

  • x1 (float) – Starting point x-value

  • x2 (float) – End point x-value

  • y (float) – y-value of the line

  • context (RootContext) – RootContext containing the necessary information

Returns:

complex – The moment as calculated along the given line.

retrieveCachedVertical(order, y1, y2, x, context)[source]

Try to retrieve the moment along a vertical line from cache, calculating it if necessary.

Parameters:
  • order (int) – Moment to retrieve

  • y1 (float) – Starting point y-value

  • y2 (float) – End point y-value

  • x (float) – x-value of the line

  • context (RootContext) – RootContext containing the necessary information.

Returns:

complex – The moment as calculated along the given line.

storeCache(z, order, start, end, cache, newValue)[source]

Store a new value in cache.

Parameters:
  • z (float) – Real or imaginary part of the line, depending on if the line is horizontal or vertical.

  • order (int) – Order of the moment to be calculated

  • start (float) – Real or imaginary part of the starting point, depending on line orientation

  • end (float) – Real or imaginary part of the starting point, depending on line orientation

  • cache (Dict[Tuple[float, int], Dict[Tuple[float, Union[Literal['start'], Literal['end']]], Tuple[ndarray[Any, dtype[complex128]], ndarray[Any, dtype[complex128]]]]]) – Cache to store the new value in.

  • newValue (Tuple[ndarray[Any, dtype[complex128]], ndarray[Any, dtype[complex128]]]) – New value to store.

Return type:

None

Estimator Caches

This module provides a simple cache to store and retrieve intermediate results during computation.

Authors:

  • Philipp Schuette

class pyzeal.algorithms.estimators.estimator_cache.EstimatorCache[source]

A simple in-memory cache that can store and retrieve total argument changes along horizontal and vertical lines in the complex plane.

__init__()[source]

Initializes a new EstimatorCache.

dirty()[source]

Returns True if the cache contains anything.

Returns:

boolTrue if the cache contains anything.

remove(order, zStart, zEnd)[source]

Remove the total argument change associated with a horizontally or vertically oriented range of complex numbers.

Parameters:
  • order (int) – Order of the moment to remove

  • zStart (complex) – Starting point of the line

  • zEnd (complex) – End point of the line

Return type:

None

reset()[source]

Resets the cache by clearing all stored values and resetting the hit and miss counters.

Return type:

None

retrieve(order, zStart, zEnd)[source]

Retrieve the total argument change associated with a horizontally or vertically oriented range of complex numbers. Returns None if the requested entry is not present.

Parameters:
  • order (int) – Order of the moment to be retrieved

  • zStart (complex) – Starting point of the line

  • zEnd (complex) – End point of the line

Returns:

Optional[complex] – Total argument change if the cache contains a value, else None is returned.

store(order, zStart, zEnd, argument)[source]

Store the total argument change associated with a horizontally or vertically oriented range of complex numbers.

Parameters:
  • order (int) – Order of the moment to be stored

  • zStart (complex) – Starting point of the line

  • zEnd (complex) – End point of the line

  • argument (complex) – Total argument change

Return type:

None