fiddy package
Subpackages
Submodules
fiddy.analysis module
- class fiddy.analysis.Analysis(method: Callable[[DirectionalDerivative], Any] = None)
Bases:
object
- abstract method(directional_derivative: DirectionalDerivative) Any
- class fiddy.analysis.AnalysisResult(method_id: str, value: Any, metadata: Dict[str, Any] = <factory>)
Bases:
object
- class fiddy.analysis.ApproximateCentral
Bases:
Analysis
Uses the first valid forward and backward directional derivative computers.
- id = 'approximate_central'
- method(directional_derivative: DirectionalDerivative) None
fiddy.constants module
- class fiddy.constants.MethodId(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
-
Finite different method IDs.
- BACKWARD = 'backward'
- CENTRAL = 'central'
- FORWARD = 'forward'
- RICHARDSON = 'richardson'
- class fiddy.constants.Type
Bases:
object
Type annotation variables.
- DERIVATIVE_FUNCTION
alias of
Callable
[[ndarray
[Any
,dtype
[float64
]]],ndarray
[Any
,dtype
[ndarray
[Any
,dtype
[float64
]]]]]
- DIRECTIONAL_DERIVATIVE_FUNCTION
alias of
Callable
[[ndarray
[Any
,dtype
[float64
]]],ndarray
[Any
,dtype
[float64
]]]
- SCALAR
alias of
float64
- SIZE
alias of
float64
fiddy.derivative module
- class fiddy.derivative.Derivative(directional_derivatives: List[DirectionalDerivative], autorun: bool = True)
Bases:
object
Handle all aspects of derivative computation.
The general sequence is: 1. define derivatives to be computed 2. compute derivatives (possibly with multiple methods) 3. analyze derivatives (e.g. compute “consistency” between multiple methods) 4. check derivatives (e.g. ensure sufficient “consistency”)
- directional_derivatives
A list of directional derivative objects.
- expected_derivative
The expected derivative.
- analysis_results
A list of analysis result objects.
- success_checker
The method to determine whether the derivative was successfully computed.
- success
Whether the derivative was successfully computed.
- property df
- property df_full
- property dict
- hide_columns = ['pending_computers', 'computers', 'analyses', 'success_checker', 'expected_result', 'fast', 'autorun']
- property series
- property value
- fiddy.derivative.get_derivative(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]], point: ndarray[Any, dtype[float64]], sizes: List[float64], method_ids: List[str | MethodId], success_checker: Success, *args, analysis_classes: List[Analysis] = None, relative_sizes: bool = False, directions: List[ndarray[Any, dtype[float64]]] | Dict[str, ndarray[Any, dtype[float64]]] = None, direction_ids: List[str] = None, direction_indices: List[int] = None, custom_methods: Dict[str, Callable] = None, expected_result: List[float64] = None, **kwargs)
Get a derivative.
- Parameters:
sizes – The step sizes.
direction_ids – The IDs of the directions.
directions – List: The directions to step along. Dictionary: keys are direction IDs, values are directions.
relative_sizes – If True, sizes are scaled by the point, otherwise not.
fiddy.derivative_check module
- class fiddy.derivative_check.DerivativeCheck(derivative: Derivative, expectation: ndarray[Any, dtype[ndarray[Any, dtype[float64]]]], point: ndarray[Any, dtype[float64]])
Bases:
ABC
Check whether a derivative is correct.
- Parameters:
derivative – The test derivative.
expectation – The expected derivative.
point – The point where the test derivative was computed.
output_indices – The derivative can be a multi-dimensional object that has dimensions associated with the multiple outputs of a function, and dimensions associated with the derivative of these multiple outputs with respect to multiple directions.
- abstract method(*args, **kwargs)
- class fiddy.derivative_check.DerivativeCheckResult(method_id: str, directional_derivative_check_results: List[fiddy.derivative_check.DirectionalDerivativeCheckResult], test: numpy.ndarray[Any, numpy.dtype[numpy.ndarray[Any, numpy.dtype[numpy.float64]]]], expectation: numpy.ndarray[Any, numpy.dtype[numpy.ndarray[Any, numpy.dtype[numpy.float64]]]], success: bool, output: Dict[str, Any] = None)
Bases:
object
- property df
- directional_derivative_check_results: List[DirectionalDerivativeCheckResult]
The results from checking individual directions.
- class fiddy.derivative_check.DirectionalDerivativeCheckResult(direction_id: str, method_id: str, test: numpy.ndarray[Any, numpy.dtype[numpy.float64]], expectation: numpy.ndarray[Any, numpy.dtype[numpy.float64]], success: bool, output: Dict[str, Any] = None)
Bases:
object
fiddy.directional_derivative module
- class fiddy.directional_derivative.Computer(point: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], direction: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], size: numpy.float64, method: Union[Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]], fiddy.constants.MethodId], function: Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]], autorun: bool = True, completed: bool = False, results: List[fiddy.directional_derivative.ComputerResult] = <factory>, relative_size: bool = False)
Bases:
object
- get_size()
- results: List[ComputerResult]
- size: float64
- class fiddy.directional_derivative.ComputerResult(method_id: str, value: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], metadata: Dict[str, Any] = <factory>)
Bases:
object
- class fiddy.directional_derivative.DefaultBackward(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]])
Bases:
TwoPointSlopeDirectionalDirection
The backward difference derivative.
- get_points(point, direction, size)
Compute the two points used by the method.
:param See
__call__()
.:- Returns:
The points at which the function will be evaluated.
- class fiddy.directional_derivative.DefaultCentral(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]])
Bases:
TwoPointSlopeDirectionalDirection
The central difference derivative.
- get_points(point, direction, size)
Compute the two points used by the method.
:param See
__call__()
.:- Returns:
The points at which the function will be evaluated.
- class fiddy.directional_derivative.DefaultForward(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]])
Bases:
TwoPointSlopeDirectionalDirection
The forward difference derivative.
- get_points(point, direction, size)
Compute the two points used by the method.
:param See
__call__()
.:- Returns:
The points at which the function will be evaluated.
- class fiddy.directional_derivative.DefaultRichardson(*args, **kwargs)
Bases:
DirectionalDerivativeBase
The Richardson extrapolation method.
Based on https://doi.org/10.48550/arXiv.2110.04335
Given some step size h and some order n, terms are computed as
\[A_{i,j} = \mathrm{Central\,Difference}\left(\mathrm{step\,size}= \frac{h}{2^{i-1}} \right)\]if j = 1, and
\[A_{i,j} = \frac{4^{j-1} A_{i,j-1} - A_{i-1,j-1}}{4^{j-1} - 1}\]otherwise.
The derivative is given by A at i=n, j=n.
Some basic caching is used, which is reset when a new derivative is requested.
- compute(points: ndarray[Any, dtype[float64]], size: float64, direction: ndarray[Any, dtype[float64]])
Compute the directional derivative.
- Parameters:
use. (The points to) –
- Returns:
The directional derivative.
- get_points(point, direction, size)
Compute the two points used by the method.
:param See
__call__()
.:- Returns:
The points at which the function will be evaluated.
- get_term(i, j, **kwargs)
- order = 4
- reset_cache()
- class fiddy.directional_derivative.DirectionalDerivative(id: str, direction: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], pending_computers: List[fiddy.directional_derivative.Computer], computers: List[fiddy.directional_derivative.Computer], analyses: List[Callable[[ForwardRef('DirectionalDerivative')], Any]], success_checker: Callable[[ForwardRef('DirectionalDerivative')], bool] = <function DirectionalDerivative.<lambda> at 0x7fcab8521da0>, expected_result: fiddy.directional_derivative.ExpectedDirectionalDerivative = None, success: bool = False, value: numpy.float64 = None, completed: bool = False, fast: bool = False, autorun: bool = True)
Bases:
object
- analyses: List[Callable[[DirectionalDerivative], Any]]
- check_success()
- expected_result: ExpectedDirectionalDerivative = None
- get_analysis_results()
- get_computer_results()
- iterate()
- run_analyses()
- run_next_computer()
- success_checker()
- value: float64 = None
- class fiddy.directional_derivative.DirectionalDerivativeBase(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]])
Bases:
ABC
Base class for default implementations of directional derivatives.
- function
The function.
- abstract compute(points: List[ndarray[Any, dtype[float64]]])
Compute the directional derivative.
- Parameters:
use. (The points to) –
- Returns:
The directional derivative.
- class fiddy.directional_derivative.ExpectedDirectionalDerivative(point: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], direction: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], size: numpy.float64, method: Union[Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]], fiddy.constants.MethodId], function: Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]], autorun: bool = True, completed: bool = False, results: List[fiddy.directional_derivative.ComputerResult] = <factory>, relative_size: bool = False)
Bases:
Computer
- size: float64 = None
- class fiddy.directional_derivative.TwoPointSlopeDirectionalDirection(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]])
Bases:
DirectionalDerivativeBase
Derivatives that are similar to a simple (y1-y0)/h slope function.
- fiddy.directional_derivative.get_directions(point: ndarray[Any, dtype[float64]] = None, directions: List[ndarray[Any, dtype[float64]]] | Dict[str, ndarray[Any, dtype[float64]]] = None, ids: List[str] = None, indices: List[int] = None) Tuple[str, ndarray[Any, dtype[float64]]]
Get directions from minimal information.
- Parameters:
point – The standard basis of this point may be used as directions.
directions – The direction vectors.
ids – The direction IDs.
indices – The indices of the standard basis to use as directions.
- Returns:
Direction IDs, and (2) directions.
fiddy.function module
- class fiddy.function.CachedFunction(function: Callable[[ndarray[Any, dtype[float64]]], ndarray[Any, dtype[float64]]], ram_cache: bool = False, **kwargs)
Bases:
Function
Wrapper for functions to enable caching.
Cached data may persist, but can be removed by calling CachedFunction.delete_cache().
- function
The function.
- ram_cache_path
The path to the RAM cache, if requested.
- delete_cache()
fiddy.numpy module
- fiddy.numpy.fiddy_array(a)
fiddy.step module
Methods related to moving along a finite difference direction.
fiddy.success module
- class fiddy.success.Consistency(computer_parser: Callable[[Computer], float | None] = None, analysis_parser: Callable[[Analysis], float | None] = None, rtol: float = 0.2, atol: float = 1e-15, equal_nan: bool = True)
Bases:
Success
- method(directional_derivative: DirectionalDerivative) [<class 'bool'>, <class 'float'>]