tolerancing.inverse_sensitivity#
Inverse Sensitivity Module
This module contains the InverseSensitivity class, which computes, for each
tolerance, the largest deviation from nominal on each side that keeps chosen
operands within an allowed change from their compensated nominal values. It is
the inverse of SensitivityAnalysis: instead of reporting the operand change
at given limits, it reports the limits for a given operand change.
Kramer Harrison, 2026
Classes
|
Find the largest tolerance limits that keep operands within bounds. |
- class InverseSensitivity(tolerancing: Tolerancing, max_change: dict[int, float], max_factor: float = 100.0, rtol: float = 0.0001, max_iter: int = 50)[source]#
Find the largest tolerance limits that keep operands within bounds.
For each
Toleranceand each side (negative deviations forminus, positive deviations forplus), the search applies the deviation alone, applies compensators, evaluates the operands and finds the largest deviation for which every operand inmax_changechanges by at most its allowed amount from the compensated nominal.Search, per side, with
xthe deviation magnitude andx0the magnitude of the current limit on that side (or the larger of the two limits when that side is zero):Define
g(x) = max_k |op_k(x) - op_k(0)| / max_change[k] - 1, sog(0) = -1andg(x) <= 0means every operand is within bounds.Bracket: if
g(x0) > 0the bracket is[0, x0]. Otherwisexdoubles fromx0untilg(x) > 0. Ifgis still within bounds atmax_factor * x0, the search stops there and the side is reported as capped.Refine the crossing inside the bracket with Brent’s method (
scipy.optimize.brentq), to withinxtol = rtol * x0, with at mostmax_iteriterations.
The response is not assumed monotonic beyond the bracket: the result is the first crossing found as described, so a response that leaves and re-enters the allowed band between bracket points can yield a smaller or larger limit than the true largest one. Only one tolerance is applied at a time; other tolerances and legacy perturbations stay at nominal.
Legacy perturbations (added with
Tolerancing.add_perturbation) have no deviation limits and are skipped.- Parameters:
tolerancing – The tolerancing system.
max_change – Maps an operand index (in
tolerancing.operands) to the allowed absolute change from the compensated nominal value. Operands not listed are ignored.max_factor – Largest searched deviation, as a multiple of
x0. Defaults to 100.rtol – Search tolerance on the limit, relative to
x0. Defaults to 1e-4.max_iter – Iteration cap for the Brent refinement. Defaults to 50.
- Variables:
tolerancing – The tolerancing system.
max_change – The allowed operand changes.
operand_names – List of operand names in the tolerancing system.
nominal – Operand values at nominal, after compensation, from the last completed run.
- Raises:
ValueError – If there are no operands or tolerances, if
max_changeis empty, names an unknown operand or holds a non-positive value, ifmax_factoris not greater than 1, or if a tolerance has two zero limits.
- apply_limits() None[source]#
Write the inverse limits from the last run into the tolerances.
- Raises:
RuntimeError – If no run has completed.
- get_results() pandas.DataFrame[source]#
Return the results of the last completed run.
- Returns:
One row per tolerance with columns
tolerance,minus,plus(current limits),inverse_minus,inverse_plus(limits found),limiting_minus,limiting_plus(name of the operand that sets each limit, or None when capped) andcapped_minus,capped_plus(True when the search stopped atmax_factortimes the start).- Return type:
pd.DataFrame
- run() None[source]#
Run the inverse sensitivity search for every tolerance.
The tolerancing system is reset to nominal on exit, including when a trial raises an exception or is interrupted. If a run fails, results and
nominalfrom the last completed run remain available and the exception propagates.
- view(figsize: tuple[float, float] | None = None) tuple[Figure, Axes][source]#
Plot current and inverse limits as horizontal bars per tolerance.
- Parameters:
figsize – Figure size in inches. Defaults to a height that grows with the number of tolerances.
- Returns:
The figure and axes of the plot.
- Return type: