src.pydasa.analysis.scenario#

This module provides the Sensitivity class for performing sensitivity analysis on dimensional coefficients derived from dimensional analysis in PyDASA.

IMPORTANT
  • Based on the theory from H. Görtler, Dimensionalanalyse: Eine Theoririe der physikalischen Dimensionen mit Anwendungen

Classes#

Sensitivity

Performs sensitivity analysis on dimensional coefficients in PyDASA to determine which variables have the most significant impact on the system behavior.

Module Contents#

class src.pydasa.analysis.scenario.Sensitivity#

Bases: pydasa.core.basic.Foundation

Performs sensitivity analysis on dimensional coefficients in PyDASA to determine which variables have the most significant impact on the system behavior.

Inherits from:
  • Foundation: basic class for validation of symbols and frameworks and allow to use the attributes name, description, idx, sym, alias, fwk, and cat.

name#

User-friendly name of the sensitivity analysis.

Type:

str

Return type:

str

description#

Brief summary of the sensitivity analysis.

Type:

str

idx#

Index/precedence of the sensitivity analysis.

Type:

int

Return type:

int

sym#

Symbol representation (LaTeX or alphanumeric).

Type:

str

Return type:

str

alias#

Python-compatible alias for use in code.

Type:

str

Return type:

Optional[str]

fwk#

Frameworks context (PHYSICAL, COMPUTATION, SOFTWARE, CUSTOM).

Type:

str

Return type:

str

_cat: str = 'SYM'#

Category of the sensitivity analysis (SYM, NUM).

_pi_expr: str | None = None#

LaTeX expression to analyze.

_sym_func: sympy.Expr | None = None#

Sympy expression of the sensitivity (symbolic form).

_exe_func: Callable | Dict[str, Callable] | None = None#

Executable function(s) for numerical evaluation (compiled from symbolic form).

_variables: Dict[str, pydasa.elements.parameter.Variable]#

Variable symbols in the expression.

_var_names: List[str] = []#

List of variable names extracted from the expression (ordered).

_schema: pydasa.dimensional.vaschy.Schema#

Dimensional framework schema for FDU management.

_coefficient: pydasa.dimensional.buckingham.Coefficient | None = None#

Specifications of the dimensionless coefficient to analyse.

_symbols: Dict[sympy.Symbol, sympy.Symbol]#

Python symbols for the variables.

_aliases: Dict[str, sympy.Symbol]#

Variable aliases for use in code.

_latex_to_py: Dict[str, str]#

Mapping from LaTeX symbols to Python-compatible names.

_py_to_latex: Dict[str, str]#

Mapping from Python-compatible names to LaTeX symbols.

_var_bounds: List[List[float]] = []#

Min/max bounds for each variable.

_var_values: Dict[str, float]#

Values for symbolic analysis.

_var_domains: numpy.ndarray | None = None#

Sample domain (inputs) for numerical analysis.

_var_ranges: numpy.ndarray | None = None#

Sample value range (results) for numerical analysis.

_experiments: int = -1#

Number of experiments/samples for analysis.

_results: Dict[str, Any]#

Analysis results.

_validate_sym_expr(val)#

Confirm that the input symbolic expression is a SymPy expression.

Parameters:

val (Any) – Possible expression/value to validate.

Raises:

ValueError – If value is not a valid SymPy expression.

Return type:

None

_validate_exec_func(val)#

Confirm executable function is type Callable or dict of Callable.

Parameters:

val (Any) – Possible executable function/value to validate.

Raises:

ValueError – If value is not a callable or dict of callables.

Return type:

None

_validate_analysis_ready()#

Confirm if the sensitivity analysis is ready to be performed.

Raises:
  • ValueError – If the variables are missing.

  • ValueError – If the python-compatible variables are missing.

  • ValueError – If the symbolic expression is missing.

Return type:

None

set_coefficient(coef)#

Configure the sensitivity analysis from a coefficient.

Parameters:

coef (Coefficient) – Dimensionless coefficient to analyze.

Raises:

ValueError – If the coefficient doesn’t have a valid expression.

Return type:

None

_parse_expression(expr)#

Parse the LaTeX expression into a valid SymPy function.

Parameters:

expr (str) – LaTeX expression to parse.

Raises:
  • ValueError – If the expression cannot be parsed.

  • TypeError – If parsed result is not a valid SymPy expression.

Return type:

None

analyze_symbolically(vals)#

Perform the symbolic sensitivity analysis for the coefficient.

Parameters:

vals (Dict[str, float]) – Dictionary mapping variable names to values.

Returns:

Sensitivity results for each variable.

Return type:

Dict[str, float]

analyze_numerically(vals, bounds, iters=-1)#

Perform the numerical sensitivity analysis for the coefficient.

Parameters:
  • vals (List[str]) – List of variable names to analyze.

  • bounds (List[List[float]]) – Bounds for each variable [min, max].

  • iters (int, optional) – Number of iterations to use. Defaults to -1.

Returns:

Detailed sensitivity analysis results.

Return type:

Dict[str, Any]

property cat: str#

Get the analysis category.

Returns:

Category (SYM, NUM).

Return type:

str

property pi_expr: str | None#

Get the coefficient expression to analyze.

Returns:

LaTeX expression.

Return type:

Optional[str]

property sym_func: sympy.Expr | None#

Get the symbolic expression.

Returns:

SymPy symbolic expression.

Return type:

Optional[sp.Expr]

property exe_func: Callable | Dict[str, Callable] | None#

Get the executable function.

Returns:

Executable function for numerical evaluation.

Return type:

Optional[Union[Callable, Dict[str, Callable]]]

property variables: Dict[str, pydasa.elements.parameter.Variable]#

Get the coefficient’s variable dictionary.

Returns:

Variables dictionary.

Return type:

Dict[str, Variable]

property schema: pydasa.dimensional.vaschy.Schema#

Get the dimensional schema.

Returns:

Current dimensional schema.

Return type:

Schema

property symbols: Dict[sympy.Symbol, sympy.Symbol]#

Get the Python symbols for the variables.

Returns:

Dictionary mapping variable names to sympy symbols.

Return type:

Dict[sp.Symbol, sp.Symbol]

property aliases: Dict[str, sympy.Symbol]#

Get the Python aliases for the variables.

Returns:

Python-compatible variable names.

Return type:

Dict[str, sp.Symbol]

property var_names: List[str]#

Get the list of variable names extracted from the expression.

Returns:

Ordered list of variable names.

Return type:

List[str]

property coefficient: pydasa.dimensional.buckingham.Coefficient | None#

Get the dimensionless coefficient specification.

Returns:

Coefficient specification.

Return type:

Optional[Coefficient]

property latex_to_py: Dict[str, str]#

Get the mapping from LaTeX symbols to Python compatible names.

Returns:

LaTeX to Python symbol mapping.

Return type:

Dict[str, str]

property py_to_latex: Dict[str, str]#

Get the mapping from Python compatible names to LaTeX symbols.

Returns:

Python to LaTeX symbol mapping.

Return type:

Dict[str, str]

property var_bounds: List[List[float]]#

Get the min/max bounds for each variable.

Returns:

Bounds for each variable.

Return type:

List[List[float]]

property var_values: Dict[str, float]#

Get the values for symbolic analysis.

Returns:

Variable values for symbolic analysis.

Return type:

Dict[str, float]

property var_domains: numpy.ndarray | None#

Get the sample domain for numerical analysis.

Returns:

Sample domain (inputs) or None if not computed.

Return type:

Optional[np.ndarray]

property var_ranges: numpy.ndarray | None#

Get the sample value range for numerical analysis.

Returns:

Sample value range (results) or None if not computed.

Return type:

Optional[np.ndarray]

property results: Dict[str, Any]#

Get the analysis results.

Returns:

Analysis results dictionary.

Return type:

Dict[str, Any]

property experiments: int#

Get the number of experiments for analysis. :returns: Number of experiments. :rtype: int

Return type:

int

clear()#

Reset all attributes to default values.

Resets all sensitivity analysis properties to their initial state.

Return type:

None

to_dict()#

Convert the sensitivity analysis into a valid Python dictionary representation.

Returns:

Dictionary representation of sensitivity analysis.

Return type:

Dict[str, Any]

classmethod from_dict(data)#

Creates a sensitivity analysis instance from dictionary representation.

Parameters:

data (Dict[str, Any]) – Dictionary representation of sensitivity analysis.

Returns:

New sensitivity analysis instance.

Return type:

Sensitivity