bella-companion 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bella-companion might be problematic. Click here for more details.
- bella_companion/cli.py +14 -4
- bella_companion/fbd_empirical/__init__.py +2 -1
- bella_companion/fbd_empirical/notbooks.ipynb +85 -274
- bella_companion/fbd_empirical/run_beast.py +6 -6
- bella_companion/fbd_empirical/summarize_logs.py +15 -32
- bella_companion/simulations/__init__.py +8 -1
- bella_companion/simulations/figures/epi_skyline_results.py +2 -2
- bella_companion/simulations/figures/explain/pdp.py +21 -27
- bella_companion/simulations/figures/explain/shap.py +1 -1
- bella_companion/simulations/figures/fbd_2traits_results.py +1 -1
- bella_companion/simulations/figures/fbd_no_traits_results.py +2 -2
- bella_companion/simulations/figures/scenarios.py +2 -2
- bella_companion/simulations/generate_data.py +4 -2
- bella_companion/simulations/metrics.py +62 -0
- bella_companion/simulations/scenarios/epi_multitype.py +1 -1
- bella_companion/simulations/scenarios/fbd_2traits.py +1 -4
- bella_companion/simulations/summarize_logs.py +3 -4
- bella_companion/utils/__init__.py +7 -11
- bella_companion/utils/beast.py +2 -2
- {bella_companion-0.0.7.dist-info → bella_companion-0.0.9.dist-info}/METADATA +2 -2
- bella_companion-0.0.9.dist-info/RECORD +42 -0
- bella_companion/fbd_empirical/figure.py +0 -37
- bella_companion-0.0.7.dist-info/RECORD +0 -42
- /bella_companion/{utils/plots.py → simulations/figures/utils.py} +0 -0
- {bella_companion-0.0.7.dist-info → bella_companion-0.0.9.dist-info}/WHEEL +0 -0
- {bella_companion-0.0.7.dist-info → bella_companion-0.0.9.dist-info}/entry_points.txt +0 -0
|
@@ -38,12 +38,12 @@ def run_beast():
|
|
|
38
38
|
os.environ["BELLA_RUN_BEAST_CMD"],
|
|
39
39
|
f"-D types=0,1,2,3",
|
|
40
40
|
f'-D startTypePriorProbs="0.25 0.25 0.25 0.25"',
|
|
41
|
-
f"-D birthRateUpper=
|
|
42
|
-
f"-D deathRateUpper=
|
|
43
|
-
f"-D samplingRateUpper=
|
|
44
|
-
f'-D samplingRateInit="5 5 5 5 5 5 5"',
|
|
45
|
-
f"-D migrationRateUpper=
|
|
46
|
-
f'-D migrationRateInit="
|
|
41
|
+
f"-D birthRateUpper=5",
|
|
42
|
+
f"-D deathRateUpper=5",
|
|
43
|
+
f"-D samplingRateUpper=5",
|
|
44
|
+
f'-D samplingRateInit="2.5 2.5 2.5 2.5 2.5 2.5 2.5"',
|
|
45
|
+
f"-D migrationRateUpper=5",
|
|
46
|
+
f'-D migrationRateInit="2.5 0 0 2.5 2.5 0 0 2.5 2.5 0 0 2.5"',
|
|
47
47
|
f'-D nodes="16 8"',
|
|
48
48
|
f'-D layersRange="0,1,2"',
|
|
49
49
|
f"-D treeFile={tree_file}",
|
|
@@ -1,50 +1,33 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import os
|
|
3
2
|
from pathlib import Path
|
|
4
3
|
|
|
5
4
|
import joblib
|
|
6
5
|
import polars as pl
|
|
7
6
|
|
|
8
|
-
from
|
|
9
|
-
from src.utils import summarize_logs
|
|
7
|
+
from bella_companion.utils import read_weights_dir, summarize_logs_dir
|
|
10
8
|
|
|
11
9
|
THIS_DIR = Path(__file__).parent
|
|
12
10
|
|
|
13
11
|
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
with open(os.path.join(THIS_DIR, "params", "MLP.json"), "r") as f:
|
|
19
|
-
params = json.load(f)
|
|
20
|
-
hidden_nodes = list(map(int, params["nodes"].split()))[:-1]
|
|
21
|
-
print(hidden_nodes)
|
|
22
|
-
states = params["types"].split(",")
|
|
23
|
-
logs_dir = os.path.join(BEAST_OUTPUTS_DIR, "fbd-empirical", "MLP")
|
|
24
|
-
change_times = (
|
|
25
|
-
pl.read_csv(
|
|
26
|
-
os.path.join(THIS_DIR, "data", "change_times.csv"), has_header=False
|
|
27
|
-
)
|
|
28
|
-
.to_series()
|
|
29
|
-
.to_list()
|
|
12
|
+
def summarize_logs():
|
|
13
|
+
change_times = pl.read_csv(
|
|
14
|
+
Path(THIS_DIR) / "data" / "change_times.csv", has_header=False
|
|
30
15
|
)
|
|
31
16
|
n_time_bins = len(change_times) + 1
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
|
|
18
|
+
logs_dir = Path(os.environ["BELLA_BEAST_OUTPUT_DIR"]) / "fbd-empirical"
|
|
19
|
+
summaries = summarize_logs_dir(
|
|
20
|
+
logs_dir=logs_dir,
|
|
34
21
|
target_columns=[
|
|
35
|
-
f"{rate}
|
|
22
|
+
f"{rate}RateSPi{i}_{s}"
|
|
36
23
|
for rate in ["birth", "death"]
|
|
37
24
|
for i in range(n_time_bins)
|
|
38
|
-
for s in
|
|
25
|
+
for s in ["0", "1", "2", "3"]
|
|
39
26
|
],
|
|
40
|
-
hidden_nodes=hidden_nodes,
|
|
41
|
-
n_features={f"{rate}Rate": 2 for rate in ["birth", "death"]},
|
|
42
|
-
layers_range_start=0,
|
|
43
27
|
)
|
|
28
|
+
weights = read_weights_dir(logs_dir)
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if __name__ == "__main__":
|
|
50
|
-
main()
|
|
30
|
+
summaries_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"], "fbd-empirical")
|
|
31
|
+
os.makedirs(summaries_dir, exist_ok=True)
|
|
32
|
+
summaries.write_csv(summaries_dir / "MLP.csv")
|
|
33
|
+
joblib.dump(weights, summaries_dir / "MLP.weights.pkl")
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
from bella_companion.simulations.generate_data import generate_data
|
|
2
2
|
from bella_companion.simulations.generate_figures import generate_figures
|
|
3
|
+
from bella_companion.simulations.metrics import print_metrics
|
|
3
4
|
from bella_companion.simulations.run_beast import run_beast
|
|
4
5
|
from bella_companion.simulations.summarize_logs import summarize_logs
|
|
5
6
|
|
|
6
|
-
__all__ = [
|
|
7
|
+
__all__ = [
|
|
8
|
+
"generate_data",
|
|
9
|
+
"generate_figures",
|
|
10
|
+
"print_metrics",
|
|
11
|
+
"run_beast",
|
|
12
|
+
"summarize_logs",
|
|
13
|
+
]
|
|
@@ -5,12 +5,12 @@ import matplotlib.pyplot as plt
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import polars as pl
|
|
7
7
|
|
|
8
|
-
from bella_companion.simulations.
|
|
9
|
-
from bella_companion.utils import (
|
|
8
|
+
from bella_companion.simulations.figures.utils import (
|
|
10
9
|
plot_coverage_per_time_bin,
|
|
11
10
|
plot_maes_per_time_bin,
|
|
12
11
|
step,
|
|
13
12
|
)
|
|
13
|
+
from bella_companion.simulations.scenarios.epi_skyline import REPRODUCTION_NUMBERS
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def plot_epi_skyline_results():
|
|
@@ -45,12 +45,10 @@ def plot_partial_dependencies(
|
|
|
45
45
|
np.array(mcmc_pds).T for mcmc_pds in zip(*pdvalues)
|
|
46
46
|
] # shape: (n_features, n_grid_points, n_runs)
|
|
47
47
|
|
|
48
|
-
if any(not
|
|
49
|
-
for (
|
|
50
|
-
features.items(), pdvalues
|
|
51
|
-
):
|
|
48
|
+
if any(not f.is_binary for f in features.values()):
|
|
49
|
+
for (label, feature), feature_pdvalues in zip(features.items(), pdvalues):
|
|
52
50
|
if not feature.is_binary:
|
|
53
|
-
color = "
|
|
51
|
+
color = "#E74C3C" if feature.is_relevant else "gray"
|
|
54
52
|
median = np.median(feature_pdvalues, axis=1)
|
|
55
53
|
lower = np.percentile(feature_pdvalues, 2.5, axis=1)
|
|
56
54
|
high = np.percentile(feature_pdvalues, 100 - 2.5, axis=1)
|
|
@@ -62,7 +60,7 @@ def plot_partial_dependencies(
|
|
|
62
60
|
continuous_grid, mcmc_pds, color=color, alpha=0.2, linewidth=1
|
|
63
61
|
)
|
|
64
62
|
plt.plot( # pyright: ignore
|
|
65
|
-
continuous_grid, median, color=color, label=
|
|
63
|
+
continuous_grid, median, color=color, label=label
|
|
66
64
|
)
|
|
67
65
|
plt.xlabel("Feature value") # pyright: ignore
|
|
68
66
|
plt.ylabel("MLP Output") # pyright: ignore
|
|
@@ -70,32 +68,28 @@ def plot_partial_dependencies(
|
|
|
70
68
|
plt.savefig(output_dir / "PDPs-continuous.svg") # pyright: ignore
|
|
71
69
|
plt.close()
|
|
72
70
|
|
|
73
|
-
if any(
|
|
71
|
+
if any(f.is_binary for f in features.values()):
|
|
74
72
|
data: list[float] = []
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (
|
|
78
|
-
features.items(), pdvalues
|
|
79
|
-
):
|
|
73
|
+
grid: list[int] = []
|
|
74
|
+
labels: list[str] = []
|
|
75
|
+
for (label, feature), feature_pdvalues in zip(features.items(), pdvalues):
|
|
80
76
|
if feature.is_binary:
|
|
81
77
|
for i in [0, 1]:
|
|
82
78
|
data.extend(feature_pdvalues[i])
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
y=data,
|
|
88
|
-
hue=feature_labels,
|
|
89
|
-
split=False,
|
|
90
|
-
cut=0,
|
|
91
|
-
palette={
|
|
92
|
-
feature_name: "red" if feature.is_relevant else "gray"
|
|
93
|
-
for feature_name, feature in features.items()
|
|
94
|
-
if feature.is_binary
|
|
95
|
-
},
|
|
79
|
+
grid.extend([i] * len(feature_pdvalues[i]))
|
|
80
|
+
labels.extend([label] * len(feature_pdvalues[i]))
|
|
81
|
+
|
|
82
|
+
ax = sns.violinplot(
|
|
83
|
+
x=labels, y=data, hue=grid, split=True, cut=0, inner="quartile"
|
|
96
84
|
)
|
|
97
|
-
|
|
85
|
+
ax.get_legend().remove() # pyright: ignore
|
|
86
|
+
|
|
87
|
+
for i, f in enumerate([f for f in features.values() if f.is_binary]):
|
|
88
|
+
color = "#E74C3C" if f.is_relevant else "gray"
|
|
89
|
+
for coll in ax.collections[i * 2 : i * 2 + 2]:
|
|
90
|
+
coll.set_facecolor(color)
|
|
91
|
+
|
|
92
|
+
plt.xlabel("Feature") # pyright: ignore
|
|
98
93
|
plt.ylabel("MLP Output") # pyright: ignore
|
|
99
|
-
plt.legend() # pyright: ignore
|
|
100
94
|
plt.savefig(output_dir / "PDPs-categorical.svg") # pyright: ignore
|
|
101
95
|
plt.close()
|
|
@@ -48,7 +48,7 @@ def plot_shap_features_importance(
|
|
|
48
48
|
y=features_importances[:, i],
|
|
49
49
|
x=[feature_name] * len(features_importances),
|
|
50
50
|
cut=0,
|
|
51
|
-
color="
|
|
51
|
+
color="#E74C3C" if feature.is_relevant else "gray",
|
|
52
52
|
)
|
|
53
53
|
plt.xlabel("Feature") # pyright: ignore
|
|
54
54
|
plt.ylabel("Importance") # pyright: ignore
|
|
@@ -12,6 +12,7 @@ from bella_companion.simulations.figures.explain import (
|
|
|
12
12
|
plot_partial_dependencies,
|
|
13
13
|
plot_shap_features_importance,
|
|
14
14
|
)
|
|
15
|
+
from bella_companion.simulations.figures.utils import step
|
|
15
16
|
from bella_companion.simulations.scenarios.fbd_2traits import (
|
|
16
17
|
FBD_RATE_UPPER,
|
|
17
18
|
N_TIME_BINS,
|
|
@@ -19,7 +20,6 @@ from bella_companion.simulations.scenarios.fbd_2traits import (
|
|
|
19
20
|
SCENARIO,
|
|
20
21
|
STATES,
|
|
21
22
|
)
|
|
22
|
-
from bella_companion.utils import step
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def _plot_predictions(log_summary: pl.DataFrame, output_dir: Path):
|
|
@@ -5,12 +5,12 @@ import matplotlib.pyplot as plt
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import polars as pl
|
|
7
7
|
|
|
8
|
-
from bella_companion.simulations.
|
|
9
|
-
from bella_companion.utils import (
|
|
8
|
+
from bella_companion.simulations.figures.utils import (
|
|
10
9
|
plot_coverage_per_time_bin,
|
|
11
10
|
plot_maes_per_time_bin,
|
|
12
11
|
step,
|
|
13
12
|
)
|
|
13
|
+
from bella_companion.simulations.scenarios.fbd_no_traits import RATES
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def plot_fbd_no_traits_results():
|
|
@@ -4,6 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
import matplotlib.pyplot as plt
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
|
+
from bella_companion.simulations.figures.utils import step
|
|
7
8
|
from bella_companion.simulations.scenarios.epi_multitype import (
|
|
8
9
|
MIGRATION_PREDICTOR,
|
|
9
10
|
MIGRATION_RATES,
|
|
@@ -16,11 +17,10 @@ from bella_companion.simulations.scenarios.fbd_2traits import (
|
|
|
16
17
|
DEATH_RATE_TRAIT1_UNSET,
|
|
17
18
|
)
|
|
18
19
|
from bella_companion.simulations.scenarios.fbd_no_traits import RATES
|
|
19
|
-
from bella_companion.utils import step
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def plot_scenarios():
|
|
23
|
-
output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "
|
|
23
|
+
output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "scenarios"
|
|
24
24
|
os.makedirs(output_dir, exist_ok=True)
|
|
25
25
|
|
|
26
26
|
# -----------
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from pathlib import Path
|
|
2
3
|
|
|
3
4
|
from phylogenie import generate_trees
|
|
4
5
|
|
|
@@ -10,10 +11,10 @@ MAX_TIPS = 500
|
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def generate_data():
|
|
13
|
-
base_output_dir = os.environ["BELLA_SIMULATIONS_DATA_DIR"]
|
|
14
|
+
base_output_dir = Path(os.environ["BELLA_SIMULATIONS_DATA_DIR"])
|
|
14
15
|
for scenario_name, scenario in SCENARIOS.items():
|
|
15
16
|
generate_trees(
|
|
16
|
-
output_dir=
|
|
17
|
+
output_dir=base_output_dir / scenario_name,
|
|
17
18
|
n_trees=N_TREES,
|
|
18
19
|
events=scenario.events,
|
|
19
20
|
init_state=scenario.init_state,
|
|
@@ -22,4 +23,5 @@ def generate_data():
|
|
|
22
23
|
min_tips=MIN_TIPS,
|
|
23
24
|
max_tips=MAX_TIPS,
|
|
24
25
|
seed=42,
|
|
26
|
+
n_jobs=2,
|
|
25
27
|
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from glob import glob
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
import polars as pl
|
|
8
|
+
|
|
9
|
+
from bella_companion.simulations.scenarios import SCENARIOS
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _mae(summary: pl.DataFrame, true_values: dict[str, float]) -> float:
|
|
13
|
+
preds = [float(np.median(summary[f"{target}_median"])) for target in true_values]
|
|
14
|
+
targets = list(true_values.values())
|
|
15
|
+
return float(np.mean([np.abs(np.array(preds) - np.array(targets))]))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _coverage(summary: pl.DataFrame, true_values: dict[str, float]) -> float:
|
|
19
|
+
coverages = [
|
|
20
|
+
(
|
|
21
|
+
(summary[f"{target}_lower"] <= true_values[target])
|
|
22
|
+
& (true_values[target] <= summary[f"{target}_upper"])
|
|
23
|
+
).sum()
|
|
24
|
+
/ len(summary)
|
|
25
|
+
for target in true_values
|
|
26
|
+
]
|
|
27
|
+
return float(np.mean(coverages))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _avg_ci_width(summary: pl.DataFrame, true_values: dict[str, float]) -> float:
|
|
31
|
+
widths = [
|
|
32
|
+
np.median(summary[f"{target}_upper"] - summary[f"{target}_lower"])
|
|
33
|
+
for target in true_values
|
|
34
|
+
]
|
|
35
|
+
return float(np.mean(widths))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def print_metrics():
|
|
39
|
+
metrics = {}
|
|
40
|
+
for name, scenario in SCENARIOS.items():
|
|
41
|
+
summaries_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"]) / name
|
|
42
|
+
summaries = {
|
|
43
|
+
Path(log_summary).stem: pl.read_csv(log_summary)
|
|
44
|
+
for log_summary in glob(str(summaries_dir / "*.csv"))
|
|
45
|
+
}
|
|
46
|
+
metrics[name] = {
|
|
47
|
+
target: {
|
|
48
|
+
model: {
|
|
49
|
+
"MAE": _mae(summary, true_values),
|
|
50
|
+
"coverage": _coverage(summary, true_values),
|
|
51
|
+
"avg_CI_width": _avg_ci_width(summary, true_values),
|
|
52
|
+
}
|
|
53
|
+
for model, summary in summaries.items()
|
|
54
|
+
}
|
|
55
|
+
for target, true_values in scenario.targets.items()
|
|
56
|
+
}
|
|
57
|
+
with open("simulation-metrics.json", "w") as f:
|
|
58
|
+
json.dump(metrics, f)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
print_metrics()
|
|
@@ -54,7 +54,7 @@ SCENARIO = Scenario(
|
|
|
54
54
|
},
|
|
55
55
|
targets={
|
|
56
56
|
"migrationRate": {
|
|
57
|
-
f"migrationRateSP{t1}_to_{t2}": MIGRATION_RATES[i, j]
|
|
57
|
+
f"migrationRateSP{t1}_to_{t2}": float(MIGRATION_RATES[i, j])
|
|
58
58
|
for i, t1 in enumerate(TYPES)
|
|
59
59
|
for j, t2 in enumerate([t for t in TYPES if t != t1])
|
|
60
60
|
}
|
|
@@ -41,10 +41,7 @@ DEATH_RATES = {
|
|
|
41
41
|
"10": DEATH_RATE_TRAIT1_SET,
|
|
42
42
|
"11": DEATH_RATE_TRAIT1_SET,
|
|
43
43
|
}
|
|
44
|
-
RATES = {
|
|
45
|
-
"birth": BIRTH_RATES,
|
|
46
|
-
"death": DEATH_RATES,
|
|
47
|
-
}
|
|
44
|
+
RATES = {"birth": BIRTH_RATES, "death": DEATH_RATES}
|
|
48
45
|
_MIGRATION_RATES = (
|
|
49
46
|
np.array([[1, 1, 0], [1, 0, 1], [1, 0, 1], [0, 1, 1]]) * 0.1
|
|
50
47
|
).tolist()
|
|
@@ -5,8 +5,7 @@ from pathlib import Path
|
|
|
5
5
|
import joblib
|
|
6
6
|
|
|
7
7
|
from bella_companion.simulations.scenarios import SCENARIOS
|
|
8
|
-
from bella_companion.utils import
|
|
9
|
-
from bella_companion.utils import summarize_weights
|
|
8
|
+
from bella_companion.utils import read_weights_dir, summarize_logs_dir
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
def summarize_logs():
|
|
@@ -20,12 +19,12 @@ def summarize_logs():
|
|
|
20
19
|
for model in job_ids[scenario_name]:
|
|
21
20
|
logs_dir = output_dir / scenario_name / model
|
|
22
21
|
print(f"Summarizing {scenario_name} - {model}")
|
|
23
|
-
summary =
|
|
22
|
+
summary = summarize_logs_dir(
|
|
24
23
|
logs_dir,
|
|
25
24
|
target_columns=[c for t in scenario.targets.values() for c in t],
|
|
26
25
|
job_ids=job_ids[scenario_name][model],
|
|
27
26
|
)
|
|
28
27
|
summary.write_csv(summaries_dir / f"{model}.csv")
|
|
29
28
|
if model.startswith("MLP"):
|
|
30
|
-
weights =
|
|
29
|
+
weights = read_weights_dir(logs_dir)
|
|
31
30
|
joblib.dump(weights, summaries_dir / f"{model}.weights.pkl")
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
from bella_companion.utils.beast import
|
|
1
|
+
from bella_companion.utils.beast import (
|
|
2
|
+
read_weights_dir,
|
|
3
|
+
summarize_log,
|
|
4
|
+
summarize_logs_dir,
|
|
5
|
+
)
|
|
2
6
|
from bella_companion.utils.explain import (
|
|
3
7
|
get_median_partial_dependence_values,
|
|
4
8
|
get_median_shap_features_importance,
|
|
5
9
|
)
|
|
6
|
-
from bella_companion.utils.plots import (
|
|
7
|
-
plot_coverage_per_time_bin,
|
|
8
|
-
plot_maes_per_time_bin,
|
|
9
|
-
step,
|
|
10
|
-
)
|
|
11
10
|
from bella_companion.utils.slurm import submit_job
|
|
12
11
|
|
|
13
12
|
__all__ = [
|
|
14
13
|
"summarize_log",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"summarize_logs_dir",
|
|
15
|
+
"read_weights_dir",
|
|
17
16
|
"get_median_partial_dependence_values",
|
|
18
17
|
"get_median_shap_features_importance",
|
|
19
|
-
"plot_coverage_per_time_bin",
|
|
20
|
-
"plot_maes_per_time_bin",
|
|
21
|
-
"step",
|
|
22
18
|
"submit_job",
|
|
23
19
|
]
|
bella_companion/utils/beast.py
CHANGED
|
@@ -36,7 +36,7 @@ def summarize_log(
|
|
|
36
36
|
return summary
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def
|
|
39
|
+
def summarize_logs_dir(
|
|
40
40
|
logs_dir: Path,
|
|
41
41
|
target_columns: list[str],
|
|
42
42
|
burn_in: float = 0.1,
|
|
@@ -59,7 +59,7 @@ def summarize_logs(
|
|
|
59
59
|
return pl.DataFrame(summaries)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
def
|
|
62
|
+
def read_weights_dir(
|
|
63
63
|
logs_dir: Path, n_samples: int = 100, burn_in: float = 0.1
|
|
64
64
|
) -> list[dict[str, list[Weights]]]:
|
|
65
65
|
os.environ["POLARS_MAX_THREADS"] = "1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bella-companion
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
4
4
|
Summary:
|
|
5
5
|
Author: gabriele-marino
|
|
6
6
|
Author-email: gabmarino.8601@gmail.com
|
|
@@ -12,5 +12,5 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
12
12
|
Requires-Dist: arviz (>=0.22.0,<0.23.0)
|
|
13
13
|
Requires-Dist: bella-lumiere (>=0.0.13,<0.0.14)
|
|
14
14
|
Requires-Dist: dotenv (>=0.9.9,<0.10.0)
|
|
15
|
-
Requires-Dist: phylogenie (>=2.1.
|
|
15
|
+
Requires-Dist: phylogenie (>=2.1.29,<3.0.0)
|
|
16
16
|
Requires-Dist: seaborn (>=0.13.2,<0.14.0)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
bella_companion/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
bella_companion/cli.py,sha256=ykq62Qjt9Kk1g0HZZMMA_nAqoG5E7vnWEWGfqDJx3hU,1937
|
|
3
|
+
bella_companion/fbd_empirical/__init__.py,sha256=nQdZfS56ZsU26davkyK4isTqvKjMVw9OniHqjWRt3q0,177
|
|
4
|
+
bella_companion/fbd_empirical/data/body_mass.csv,sha256=-UkKNtm9m3g4PjY3BcfdP6z5nL_I6p9cq6cgZ-bWKI8,30360
|
|
5
|
+
bella_companion/fbd_empirical/data/change_times.csv,sha256=zmc9_z91-XMwKyIoP9v9dVlLcf4MeIHkQiHLjoMriOo,120
|
|
6
|
+
bella_companion/fbd_empirical/data/sampling_change_times.csv,sha256=Gwi9RcMFy89RyvfxKVZ_MoKVRHOZLuwB_3LEaq8asMQ,32
|
|
7
|
+
bella_companion/fbd_empirical/data/trees.nwk,sha256=zhvLvPLZelhMThVmvOENkmi3p2aPAARb8KMdHTm6mss,4645318
|
|
8
|
+
bella_companion/fbd_empirical/notbooks.ipynb,sha256=0ptmZC-_QfXtfCBrrag7NLtupiVn4gdG-oqVCworT_U,81588
|
|
9
|
+
bella_companion/fbd_empirical/run_beast.py,sha256=108c_vcEA1iHxR2wLx-OwyZu0XdYEIHr3Z809FWmuVE,2544
|
|
10
|
+
bella_companion/fbd_empirical/summarize_logs.py,sha256=TBLdW5LWS5ensEQFFQ8hrzJFJ3t0l-Mzu_SNa-Q8D_w,972
|
|
11
|
+
bella_companion/simulations/__init__.py,sha256=ShYRdp1iSjnS_SzcsH-8jbqXz6P1nyRQZqAtPZJCMVE,454
|
|
12
|
+
bella_companion/simulations/features.py,sha256=DZOBpJGlQ0UinqUZYbEtoemZ2eQGVLV_i-DfpW31qJI,104
|
|
13
|
+
bella_companion/simulations/figures/__init__.py,sha256=aBYbJntH4egFmkSSWiVMYDEApXPYxJD7eA3TCPNNegM,658
|
|
14
|
+
bella_companion/simulations/figures/epi_multitype_results.py,sha256=j85WgvN5AyAtX-CalMegr2lwlAZBmzyJxkikBPXRjCc,2629
|
|
15
|
+
bella_companion/simulations/figures/epi_skyline_results.py,sha256=gI5Ha-OIEShcZLmqVuy0W8hJzkrsydQE-Coa65_BFCo,1667
|
|
16
|
+
bella_companion/simulations/figures/explain/__init__.py,sha256=DnmVIWO65nTT5VsWnbS7NyYgKEY_eo4oMCtCY_ML2Vk,260
|
|
17
|
+
bella_companion/simulations/figures/explain/pdp.py,sha256=3n3ssgufW_43pn2hO5V5J_jgcJH3Fpb8stIRtTnlQ8w,3801
|
|
18
|
+
bella_companion/simulations/figures/explain/shap.py,sha256=qRfOMNwkU-hsBy5MHMTfVFAszaPESVOugCKQTVY8Q4Y,1940
|
|
19
|
+
bella_companion/simulations/figures/fbd_2traits_results.py,sha256=JiXrbYkH1HwdJQhTHXj6KhMEXYgQmQ6LmDboAIO1CPA,2728
|
|
20
|
+
bella_companion/simulations/figures/fbd_no_traits_results.py,sha256=fLsgpV3IbLLtxQEFNOL9K4jEEJrG324ziUM0rxIv7_k,1962
|
|
21
|
+
bella_companion/simulations/figures/scenarios.py,sha256=gbMz1TUxxT2RSIq2kQlFioNdgSHk-gQY2OQuf6-7Fww,2817
|
|
22
|
+
bella_companion/simulations/figures/utils.py,sha256=dB_GiJ1HGrZ93cqODz6kB-HeDRPwlm2MkMe9rJZGnfs,3117
|
|
23
|
+
bella_companion/simulations/generate_data.py,sha256=ZFQnusmGWDjRixKOid0l49Aj4qfrI5zxyf1n21wf0p0,768
|
|
24
|
+
bella_companion/simulations/generate_figures.py,sha256=layMgoj3Bfl78Ceb1oE7YirAQ8zhjDyD9IrxDRXf6go,657
|
|
25
|
+
bella_companion/simulations/metrics.py,sha256=TwLgK4Eui4DlG10V9m6zEbmuGfUIli2dE0Ph-gX_6bU,1925
|
|
26
|
+
bella_companion/simulations/run_beast.py,sha256=Sw9wKNe1VlGNvYr-yiYv3LqUYVlcjcMAz_9Pzr-xyL0,3214
|
|
27
|
+
bella_companion/simulations/scenarios/__init__.py,sha256=3Kl1lKcFpfb3vLX64DmSW4XCF5kXU1ZoHtstFH-ZIzU,876
|
|
28
|
+
bella_companion/simulations/scenarios/common.py,sha256=_ddaSuTvEVdttGkXB4HPc2B7IB1F_GBOCW3cVOPZ-ZM,807
|
|
29
|
+
bella_companion/simulations/scenarios/epi_multitype.py,sha256=fTkFeGHxyV_1f2nX3g_Oyr_e6wkorhXEicJjIAgeZKA,2439
|
|
30
|
+
bella_companion/simulations/scenarios/epi_skyline.py,sha256=JqnOVATECxBUqEbkR5lBlMI2O8k4hO6ipR8k9cHUsm0,2365
|
|
31
|
+
bella_companion/simulations/scenarios/fbd_2traits.py,sha256=-amB3NX0GsVgYbFuHH71t93FuXUEnRUyhWf2Qpcpia4,3541
|
|
32
|
+
bella_companion/simulations/scenarios/fbd_no_traits.py,sha256=R6CH0fVeQg-Iesl39pq2uY8ICVEO4VZbvUVUCGwauJU,2520
|
|
33
|
+
bella_companion/simulations/scenarios/scenario.py,sha256=_FRWAyOFbw94lAzd3zCD-1ek4TrssoiXfXRQPShLiIA,620
|
|
34
|
+
bella_companion/simulations/summarize_logs.py,sha256=Shf3Dx9k4lTbmO__MSLw-aIA8a8kTCXhbctBcV6Izug,1216
|
|
35
|
+
bella_companion/utils/__init__.py,sha256=UtMwPK9dWf9NAl0ic8CSsgdW7aSm-5J49OqgvD7UpYw,480
|
|
36
|
+
bella_companion/utils/beast.py,sha256=TBa0cLklX1_tXqoQE4LRYvds7mLg_9fS2-6U6OHENHo,2184
|
|
37
|
+
bella_companion/utils/explain.py,sha256=uP7HPyn2YiykAI69BQV3RooDpC6qKoCLXfp3Uibp4zk,1475
|
|
38
|
+
bella_companion/utils/slurm.py,sha256=v5DaG7YHVyK8KRFptgGDC6I8jxEhyJuMVK9N08pZSAI,1812
|
|
39
|
+
bella_companion-0.0.9.dist-info/METADATA,sha256=SGm-iWd_hwWEA74pd2SQIj2HhVacYElxBKa_NfX4GPg,576
|
|
40
|
+
bella_companion-0.0.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
41
|
+
bella_companion-0.0.9.dist-info/entry_points.txt,sha256=rSeKoAhmjnQqAYFcXBv0gAM2ViJfJe0D8_dD-fWrXeg,50
|
|
42
|
+
bella_companion-0.0.9.dist-info/RECORD,,
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
import polars as pl
|
|
6
|
-
|
|
7
|
-
import src.config as cfg
|
|
8
|
-
from src.utils import set_plt_rcparams
|
|
9
|
-
|
|
10
|
-
THIS_DIR = Path(__file__).parent
|
|
11
|
-
|
|
12
|
-
if __name__ == "__main__":
|
|
13
|
-
with open(os.path.join(THIS_DIR, "params", "MLP.json"), "r") as f:
|
|
14
|
-
params = json.load(f)
|
|
15
|
-
states = params["types"].split(",")
|
|
16
|
-
change_times = (
|
|
17
|
-
pl.read_csv(
|
|
18
|
-
os.path.join(THIS_DIR, "data", "change_times.csv"), has_header=False
|
|
19
|
-
)
|
|
20
|
-
.to_series()
|
|
21
|
-
.to_list()
|
|
22
|
-
)
|
|
23
|
-
n_time_bins = len(change_times) + 1
|
|
24
|
-
|
|
25
|
-
set_plt_rcparams()
|
|
26
|
-
|
|
27
|
-
log_summary = pl.read_csv(
|
|
28
|
-
os.path.join(cfg.BEAST_LOGS_SUMMARIES_DIR, "fbd-empirical", "MLP.csv")
|
|
29
|
-
)
|
|
30
|
-
for s in states:
|
|
31
|
-
estimates: list[float] = [
|
|
32
|
-
log_summary[f"birthRatei{i}_{s}_median"].median()
|
|
33
|
-
for i in range(n_time_bins)
|
|
34
|
-
]
|
|
35
|
-
plt.step(change_times, estimates[:-1], label=rf"$\lambda_{{{s}}}$")
|
|
36
|
-
plt.legend()
|
|
37
|
-
plt.gca().invert_xaxis() # This reverses the x-axis
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
bella_companion/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
bella_companion/cli.py,sha256=2QM1czJxsfQsOX-miE-OeReXtjMHaR7lX9i73zKki1o,1471
|
|
3
|
-
bella_companion/fbd_empirical/__init__.py,sha256=I-G5rD59c1mNBYuoVNSfq59jD6IuwwJBDkNUCLcY7Qo,87
|
|
4
|
-
bella_companion/fbd_empirical/data/body_mass.csv,sha256=-UkKNtm9m3g4PjY3BcfdP6z5nL_I6p9cq6cgZ-bWKI8,30360
|
|
5
|
-
bella_companion/fbd_empirical/data/change_times.csv,sha256=zmc9_z91-XMwKyIoP9v9dVlLcf4MeIHkQiHLjoMriOo,120
|
|
6
|
-
bella_companion/fbd_empirical/data/sampling_change_times.csv,sha256=Gwi9RcMFy89RyvfxKVZ_MoKVRHOZLuwB_3LEaq8asMQ,32
|
|
7
|
-
bella_companion/fbd_empirical/data/trees.nwk,sha256=zhvLvPLZelhMThVmvOENkmi3p2aPAARb8KMdHTm6mss,4645318
|
|
8
|
-
bella_companion/fbd_empirical/figure.py,sha256=4paOXCB1EcxuHzLPxDSleQU2AQ_ndTedtzS1ugiKICs,1018
|
|
9
|
-
bella_companion/fbd_empirical/notbooks.ipynb,sha256=O45kmz0lZENRDFbKXEWPsIKATfF5GVeS5tCYmrGLnqk,83326
|
|
10
|
-
bella_companion/fbd_empirical/run_beast.py,sha256=Y2Mcl7tLer-CIgb5rcpZ0sCq7VL6VUejnbZ9mvkRxkU,2532
|
|
11
|
-
bella_companion/fbd_empirical/summarize_logs.py,sha256=O6rhE606Wa98a8b1KKlLPjUOro1pfyqVTLdQksQMG0g,1439
|
|
12
|
-
bella_companion/simulations/__init__.py,sha256=EBZAcI8skNPKjrA7CjrqH9ea7DTntmydAD0RqsxNUMM,352
|
|
13
|
-
bella_companion/simulations/features.py,sha256=DZOBpJGlQ0UinqUZYbEtoemZ2eQGVLV_i-DfpW31qJI,104
|
|
14
|
-
bella_companion/simulations/figures/__init__.py,sha256=aBYbJntH4egFmkSSWiVMYDEApXPYxJD7eA3TCPNNegM,658
|
|
15
|
-
bella_companion/simulations/figures/epi_multitype_results.py,sha256=j85WgvN5AyAtX-CalMegr2lwlAZBmzyJxkikBPXRjCc,2629
|
|
16
|
-
bella_companion/simulations/figures/epi_skyline_results.py,sha256=Ej1iGHLnLkUohx7oC9gRTLe8T--5WS-JtyViLbxraLA,1647
|
|
17
|
-
bella_companion/simulations/figures/explain/__init__.py,sha256=DnmVIWO65nTT5VsWnbS7NyYgKEY_eo4oMCtCY_ML2Vk,260
|
|
18
|
-
bella_companion/simulations/figures/explain/pdp.py,sha256=bSrH-TZcT2mVZIBXTUeoRvShsX2bIUyhUvgmbzXLIbg,3925
|
|
19
|
-
bella_companion/simulations/figures/explain/shap.py,sha256=tjYX5H3C-IiygG9scXhLgtlCRxEBlsQ2OW5gVWL15kY,1936
|
|
20
|
-
bella_companion/simulations/figures/fbd_2traits_results.py,sha256=YP_ksmh5Sj2WnoxqRuSLt-gd-W7k2lUHs4idAbvbdhw,2708
|
|
21
|
-
bella_companion/simulations/figures/fbd_no_traits_results.py,sha256=O6hx_OZVSHmW0xq9T4q4oz6eskC_xcFZGMEdX8ZilrU,1942
|
|
22
|
-
bella_companion/simulations/figures/scenarios.py,sha256=OKh9_-ZvzNgWsO3-Vd0Aw3ndjVf76i_OuCvsKI-5r2s,2795
|
|
23
|
-
bella_companion/simulations/generate_data.py,sha256=H8OV4ZlTGZB-jXaROTPmOsK3UxRiU-GrX40l-shliw8,728
|
|
24
|
-
bella_companion/simulations/generate_figures.py,sha256=layMgoj3Bfl78Ceb1oE7YirAQ8zhjDyD9IrxDRXf6go,657
|
|
25
|
-
bella_companion/simulations/run_beast.py,sha256=Sw9wKNe1VlGNvYr-yiYv3LqUYVlcjcMAz_9Pzr-xyL0,3214
|
|
26
|
-
bella_companion/simulations/scenarios/__init__.py,sha256=3Kl1lKcFpfb3vLX64DmSW4XCF5kXU1ZoHtstFH-ZIzU,876
|
|
27
|
-
bella_companion/simulations/scenarios/common.py,sha256=_ddaSuTvEVdttGkXB4HPc2B7IB1F_GBOCW3cVOPZ-ZM,807
|
|
28
|
-
bella_companion/simulations/scenarios/epi_multitype.py,sha256=GWGIiqvYwX_FrT_3RXkZKYGDht9nZ7ceHRBKUvXDPnA,2432
|
|
29
|
-
bella_companion/simulations/scenarios/epi_skyline.py,sha256=JqnOVATECxBUqEbkR5lBlMI2O8k4hO6ipR8k9cHUsm0,2365
|
|
30
|
-
bella_companion/simulations/scenarios/fbd_2traits.py,sha256=G24WCAHrWPwvQeElsy4UMl1I9ALFnVQp6wXuc25Ie-g,3552
|
|
31
|
-
bella_companion/simulations/scenarios/fbd_no_traits.py,sha256=R6CH0fVeQg-Iesl39pq2uY8ICVEO4VZbvUVUCGwauJU,2520
|
|
32
|
-
bella_companion/simulations/scenarios/scenario.py,sha256=_FRWAyOFbw94lAzd3zCD-1ek4TrssoiXfXRQPShLiIA,620
|
|
33
|
-
bella_companion/simulations/summarize_logs.py,sha256=5IdzR9IwjeF2LgZmzpuK0rPfYMct2OUgEp0QyUbUS7g,1263
|
|
34
|
-
bella_companion/utils/__init__.py,sha256=bb0-pCjQNwGaUgG2v9htgOLlOMiB1-kdZnSQ_QY2QAo,647
|
|
35
|
-
bella_companion/utils/beast.py,sha256=5Vsv98VTE9HrY56WzUSMECjD_rIPxHTMRMD1ZzmA6wY,2181
|
|
36
|
-
bella_companion/utils/explain.py,sha256=uP7HPyn2YiykAI69BQV3RooDpC6qKoCLXfp3Uibp4zk,1475
|
|
37
|
-
bella_companion/utils/plots.py,sha256=dB_GiJ1HGrZ93cqODz6kB-HeDRPwlm2MkMe9rJZGnfs,3117
|
|
38
|
-
bella_companion/utils/slurm.py,sha256=v5DaG7YHVyK8KRFptgGDC6I8jxEhyJuMVK9N08pZSAI,1812
|
|
39
|
-
bella_companion-0.0.7.dist-info/METADATA,sha256=w-O11B88lzyTN6ENgW_0XTR2UhZEuj6Ar9hxmX_JDWs,576
|
|
40
|
-
bella_companion-0.0.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
41
|
-
bella_companion-0.0.7.dist-info/entry_points.txt,sha256=rSeKoAhmjnQqAYFcXBv0gAM2ViJfJe0D8_dD-fWrXeg,50
|
|
42
|
-
bella_companion-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|