From 371ff20773e5cf020db1ed4d4818ae832b4580b2 Mon Sep 17 00:00:00 2001 From: dilpath <59329744+dilpath@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:49:42 +0100 Subject: [PATCH] add test --- test/analyze/test_analyze.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/analyze/test_analyze.py b/test/analyze/test_analyze.py index f37e601..d465f71 100644 --- a/test/analyze/test_analyze.py +++ b/test/analyze/test_analyze.py @@ -1,5 +1,6 @@ from pathlib import Path +import numpy as np import pytest from petab_select import ( @@ -77,3 +78,17 @@ def test_relative_criterion_values(models: Models) -> None: for criterion_value in criterion_values ] assert test_value == expected_value + + +def test_compute_weights(models: Models) -> None: + """Test ``analyze.compute_weights``.""" + criterion_values = np.array( + models.get_criterion(criterion=Criterion.AIC, relative=True) + ) + expected_weights = ( + np.exp(-0.5 * criterion_values) / np.exp(-0.5 * criterion_values).sum() + ) + test_weights = analyze.compute_weights( + models=models, criterion=Criterion.AIC + ) + np.testing.assert_allclose(test_weights, expected_weights)