Beispiel #1
0
def test_calculate_llh(models):  # pylint: disable=W0621
    """Test calculate.calculate_llh."""
    for i_model, model in enumerate(models):
        print(f"Model {i_model}")
        (measurement_df, observable_df, parameter_df, simulation_df, _, _,
         expected_llh) = model
        llh = calculate_llh(measurement_df, simulation_df, observable_df,
                            parameter_df)
        assert llh == pytest.approx(expected_llh) or expected_llh is None
Beispiel #2
0
def petab_llh(pp, sim):
    """Computes the llh based on the simulation data frame

    :param pp: petab problem
    :type pp: petab.Problem

    :param sim: simulation data frame
    :type sim: pd.DataFrame

    :return: the llh as calculated by petab

    """
    return petab.calculate_llh(pp.measurement_df, sim, pp.observable_df,
                               pp.parameter_df)
# write files

write_problem(test_id=test_id,
              parameter_df=parameter_df,
              condition_dfs=[condition_df],
              observable_dfs=[observable_df],
              measurement_dfs=[measurement_df])

# solutions ------------------------------------------------------------------

simulation_df = measurement_df.copy(deep=True).rename(
    columns={MEASUREMENT: SIMULATION})
simulation_df[SIMULATION] = [
    analytical_a(10, 1, 0, 0.8, 0.6),
    analytical_b(10, 1, 0, 0.8, 0.6),
    analytical_a(10, 1, 0, 0.8, 0.6) + analytical_b(10, 1, 0, 0.8, 0.6)
]

chi2 = petab.calculate_chi2(measurement_df, simulation_df, observable_df,
                            parameter_df)

llh = petab.calculate_llh(measurement_df, simulation_df, observable_df,
                          parameter_df)
print(llh)
# write files

write_solution(test_id=test_id,
               chi2=chi2,
               llh=llh,
               simulation_dfs=[simulation_df])