petab.calculate

Functions performing various calculations.

Functions

calculate_chi2(measurement_dfs, ...[, ...])

Calculate the chi2 value.

calculate_chi2_for_table_from_residuals(...)

Compute chi2 value for a single residual table.

calculate_llh(measurement_dfs, ...)

Calculate total log likelihood.

calculate_llh_for_table(measurement_df, ...)

Calculate log-likelihood for one set of tables.

calculate_residuals(measurement_dfs, ...[, ...])

Calculate residuals.

calculate_residuals_for_table(...[, ...])

Calculate residuals for a single measurement table.

calculate_single_llh(measurement, ...)

Calculate a single log likelihood.

evaluate_noise_formula(measurement, ...)

Fill in parameters for measurement and evaluate noise_formula.

get_symbolic_noise_formulas(observable_df)

Sympify noise formulas.

petab.calculate.calculate_chi2(measurement_dfs: List[DataFrame] | DataFrame, simulation_dfs: List[DataFrame] | DataFrame, observable_dfs: List[DataFrame] | DataFrame, parameter_dfs: List[DataFrame] | DataFrame, normalize: bool = True, scale: bool = True) float[source]

Calculate the chi2 value.

Parameters:
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

  • normalize – Whether to normalize residuals by the noise standard deviation terms.

  • scale – Whether to calculate residuals of scaled values.

Returns:

The aggregated chi2 value.

petab.calculate.calculate_chi2_for_table_from_residuals(residual_df: DataFrame) float[source]

Compute chi2 value for a single residual table.

petab.calculate.calculate_llh(measurement_dfs: List[DataFrame] | DataFrame, simulation_dfs: List[DataFrame] | DataFrame, observable_dfs: List[DataFrame] | DataFrame, parameter_dfs: List[DataFrame] | DataFrame) float[source]

Calculate total log likelihood.

Parameters:
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

Returns:

The log-likelihood.

petab.calculate.calculate_llh_for_table(measurement_df: DataFrame, simulation_df: DataFrame, observable_df: DataFrame, parameter_df: DataFrame) float[source]

Calculate log-likelihood for one set of tables. For the arguments, see calculate_llh.

petab.calculate.calculate_residuals(measurement_dfs: List[DataFrame] | DataFrame, simulation_dfs: List[DataFrame] | DataFrame, observable_dfs: List[DataFrame] | DataFrame, parameter_dfs: List[DataFrame] | DataFrame, normalize: bool = True, scale: bool = True) List[DataFrame][source]

Calculate residuals.

Parameters:
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

  • normalize – Whether to normalize residuals by the noise standard deviation terms.

  • scale – Whether to calculate residuals of scaled values.

Returns:

List of DataFrames in the same structure as measurement_dfs with a field residual instead of measurement.

petab.calculate.calculate_residuals_for_table(measurement_df: DataFrame, simulation_df: DataFrame, observable_df: DataFrame, parameter_df: DataFrame, normalize: bool = True, scale: bool = True) DataFrame[source]

Calculate residuals for a single measurement table. For the arguments, see calculate_residuals.

petab.calculate.calculate_single_llh(measurement: float, simulation: float, scale: str, noise_distribution: str, noise_value: float) float[source]

Calculate a single log likelihood.

Parameters:
  • measurement – The measurement value.

  • simulation – The simulated value.

  • scale – The scale on which the noise model is to be applied.

  • noise_distribution – The noise distribution.

  • noise_value – The considered noise models possess a single noise parameter, e.g. the normal standard deviation.

Returns:

The computed likelihood for the given values.

petab.calculate.evaluate_noise_formula(measurement: Series, noise_formulas: Dict[str, Expr], parameter_df: DataFrame, simulation: Number) float[source]

Fill in parameters for measurement and evaluate noise_formula.

Parameters:
  • measurement – A measurement table row.

  • noise_formulas – The noise formulas as computed by get_symbolic_noise_formulas.

  • parameter_df – The parameter table.

  • simulation – The simulation corresponding to the measurement, scaled.

Returns:

The noise value.

petab.calculate.get_symbolic_noise_formulas(observable_df) Dict[str, Expr][source]

Sympify noise formulas.

Parameters:

observable_df – The observable table.

Returns:

{noise_formula}.

Return type:

Dictionary of {observable_id}