Skip to content

Commit e7edebf

Browse files
authored
petab.calculate: compare all common columns (#347)
For computing residuals, ... from measurement + simulation tables, we need to match the corresponding rows. Previously, this was done using a subset of PEtab measurement table columns and checking whether all values in these columns match. This changes it to using the full set of overlapping columns, not only the known measurement columns. With that, the same functions can be used for PEtab v2 measurement/simulation tables.
1 parent cc33da2 commit e7edebf

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

petab/v1/calculate.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ def calculate_residuals_for_table(
106106
)
107107
residual_df[RESIDUAL] = residual_df[RESIDUAL].astype("float64")
108108
# matching columns
109-
compared_cols = set(MEASUREMENT_DF_COLS)
110-
compared_cols -= {MEASUREMENT}
111-
compared_cols &= set(measurement_df.columns)
112-
compared_cols &= set(simulation_df.columns)
109+
compared_cols = set(measurement_df.columns) & set(simulation_df.columns)
113110

114111
# compute noise formulas for observables
115112
noise_formulas = get_symbolic_noise_formulas(observable_df)
@@ -127,6 +124,16 @@ def calculate_residuals_for_table(
127124
raise ValueError(
128125
f"Could not find simulation for measurement {row}."
129126
)
127+
# if we have multiple matches, check that the rows are all identical
128+
elif (
129+
mask.sum() > 1
130+
and simulation_df.loc[mask].drop_duplicates().shape[0] > 1
131+
):
132+
raise ValueError(
133+
f"Multiple different simulations found for measurement "
134+
f"{row}:\n{simulation_df.loc[mask]}"
135+
)
136+
130137
simulation = simulation_df.loc[mask][SIMULATION].iloc[0]
131138
if scale:
132139
# apply scaling
@@ -343,10 +350,7 @@ def calculate_llh_for_table(
343350
llhs = []
344351

345352
# matching columns
346-
compared_cols = set(MEASUREMENT_DF_COLS)
347-
compared_cols -= {MEASUREMENT}
348-
compared_cols &= set(measurement_df.columns)
349-
compared_cols &= set(simulation_df.columns)
353+
compared_cols = set(measurement_df.columns) & set(simulation_df.columns)
350354

351355
# compute noise formulas for observables
352356
noise_formulas = get_symbolic_noise_formulas(observable_df)

0 commit comments

Comments
 (0)