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

InverseSensitivity(tolerancing, max_change)

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 Tolerance and each side (negative deviations for minus, positive deviations for plus), the search applies the deviation alone, applies compensators, evaluates the operands and finds the largest deviation for which every operand in max_change changes by at most its allowed amount from the compensated nominal.

Search, per side, with x the deviation magnitude and x0 the magnitude of the current limit on that side (or the larger of the two limits when that side is zero):

  1. Define g(x) = max_k |op_k(x) - op_k(0)| / max_change[k] - 1, so g(0) = -1 and g(x) <= 0 means every operand is within bounds.

  2. Bracket: if g(x0) > 0 the bracket is [0, x0]. Otherwise x doubles from x0 until g(x) > 0. If g is still within bounds at max_factor * x0, the search stops there and the side is reported as capped.

  3. Refine the crossing inside the bracket with Brent’s method (scipy.optimize.brentq), to within xtol = rtol * x0, with at most max_iter iterations.

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_change is empty, names an unknown operand or holds a non-positive value, if max_factor is 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) and capped_minus, capped_plus (True when the search stopped at max_factor times 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 nominal from 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:

tuple