error_solver.solvers.ErrorSolverPy¶
-
class
error_solver.solvers.
ErrorSolverPy
(equations, partials, combos={}, tol=0.01)[source]¶ A class for solving systems of equations for their propagation errors using Python functions.
Parameters: - equations : list
A list of equation functions.
- partials : list
A list of dictionaries of partial derivative functions.
- combos : dict
A dictionary of equation combinations.
- tol : float
The tolerance used for verifying that values satisfy equations.
Examples
# error_solver_py_ex1.py from error_solver import ErrorSolverPy from math import pi # Define the equation functions def eq0(A, r, **kwargs): return A - pi * r**2 def eq0_A(A, r, **kwargs): return 1 def eq0_r(A, r, **kwargs): return -2*pi*r def eq1(V, A, h, **kwargs): return V - A * h def eq1_V(V, A, h, **kwargs): return 1 def eq1_A(V, A, h, **kwargs): return -h def eq1_h(V, A, h, **kwargs): return -A EQUATIONS = [eq0, eq1] PARTIALS = [{'A': eq0_A, 'r': eq0_r}, {'V': eq1_V, 'A': eq1_A, 'h': eq1_h}] # Solve the equations by some means and assemble the values in a dictionary values = { 'h': 12, 'r': 5, 'A': 78.54, 'V': 942.48 } # Define the known error tolerances errors = { 'h': 0.05, 'r': 0.05 } solver = ErrorSolverPy(EQUATIONS, PARTIALS) solver.solve(values, errors) # value error pct_error is_calc # var # A 78.539816 1.570796 2.000000 True # V 942.477796 22.776547 2.416667 True # h 12.000000 0.050000 0.416667 False # r 5.000000 0.050000 1.000000 False
In lieu of defining the equation methods manually, the
ErrorSolver
class may be used to automatically calculate the partial derivatives from an input system of equations and write methods to a Python module for use byErrorSolverPy
. This can be done as follows:# error_solver_py_ex2.py from error_solver import ErrorSolver # Define the equations EQUATIONS = [ 'A = pi * r**2', 'V = A * h', ] # Generate a Python module containing the equations and derived # partial derivative functions solver = ErrorSolver(EQUATIONS) solver.write_python('cylinder_error.py') # Import the generated module and initialize `ErrorSolverPy` with it from . import cylinder_error from error_solver import ErrorSolverPy solver = ErrorSolverPy.from_module(cylinder_error)
Methods
check
(self, values, errors[, combo])Checks that the input parameters are correct to carry out a solution. equation_vars
(self[, combo])Returns a set of all variables in the equations. from_module
(module, \*\*kwargs)Initializes an object from an imported Error Solver Python module. get_equations
(self[, combo])Returns a list of equations for the specified combination. get_partials
(self[, combo])Returns a list of partial derivatives for the specified combination. jacobian
(self, values, errors[, combo])Returns the Jacobian matrix for the system of equations. solve
(self, values, errors[, const, combo, …])Solves for the propagation errors of the system of equations and returns a Data Frame of the results. used_vars
(self, values, errors[, combo])Returns a lists of (1) variables present in both the equations and input values dictionary and (2) variables present in both the equations and input errors dictionary.