bella-companion 0.0.6__py3-none-any.whl → 0.0.8__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.

Files changed (27) hide show
  1. bella_companion/cli.py +21 -9
  2. bella_companion/fbd_empirical/__init__.py +4 -0
  3. bella_companion/fbd_empirical/notbooks.ipynb +85 -274
  4. bella_companion/fbd_empirical/run_beast.py +46 -32
  5. bella_companion/fbd_empirical/summarize_logs.py +15 -32
  6. bella_companion/simulations/__init__.py +8 -1
  7. bella_companion/simulations/figures/epi_skyline_results.py +2 -2
  8. bella_companion/simulations/figures/explain/pdp.py +21 -27
  9. bella_companion/simulations/figures/explain/shap.py +1 -1
  10. bella_companion/simulations/figures/fbd_2traits_results.py +1 -1
  11. bella_companion/simulations/figures/fbd_no_traits_results.py +2 -2
  12. bella_companion/simulations/figures/scenarios.py +2 -2
  13. bella_companion/simulations/generate_data.py +4 -2
  14. bella_companion/simulations/metrics.py +62 -0
  15. bella_companion/simulations/scenarios/epi_multitype.py +1 -1
  16. bella_companion/simulations/scenarios/fbd_2traits.py +1 -4
  17. bella_companion/simulations/summarize_logs.py +3 -4
  18. bella_companion/utils/__init__.py +7 -11
  19. bella_companion/utils/beast.py +2 -2
  20. {bella_companion-0.0.6.dist-info → bella_companion-0.0.8.dist-info}/METADATA +2 -2
  21. bella_companion-0.0.8.dist-info/RECORD +42 -0
  22. bella_companion/fbd_empirical/figure.py +0 -37
  23. bella_companion/fbd_empirical/params.json +0 -11
  24. bella_companion-0.0.6.dist-info/RECORD +0 -42
  25. /bella_companion/{utils/plots.py → simulations/figures/utils.py} +0 -0
  26. {bella_companion-0.0.6.dist-info → bella_companion-0.0.8.dist-info}/WHEEL +0 -0
  27. {bella_companion-0.0.6.dist-info → bella_companion-0.0.8.dist-info}/entry_points.txt +0 -0
@@ -1,3 +1,4 @@
1
+ import json
1
2
  import os
2
3
  from pathlib import Path
3
4
 
@@ -7,48 +8,61 @@ from phylogenie import load_newick
7
8
  from phylogenie.utils import get_node_depths
8
9
  from tqdm import tqdm
9
10
 
10
- import src.config as cfg
11
- from src.utils import run_sbatch
11
+ from bella_companion.utils import submit_job
12
12
 
13
13
  THIS_DIR = Path(__file__).parent
14
- AADD LAYERS RANGE
15
14
 
16
- def main():
17
- output_dir = cfg.BEAST_OUTPUTS_DIR / "fbd-empirical"
15
+
16
+ def run_beast():
17
+ base_output_dir = Path(os.environ["BELLA_BEAST_OUTPUT_DIR"])
18
+ output_dir = base_output_dir / "fbd-empirical"
18
19
  os.makedirs(output_dir, exist_ok=True)
19
20
 
20
- tree_file = THIS_DIR / "data" / "trees.nwk"
21
- change_times_file = THIS_DIR / "data" / "change_times.csv"
22
- sampling_change_times_file = THIS_DIR / "data" / "sampling_change_times.csv"
21
+ data_dir = THIS_DIR / "data"
22
+ tree_file = data_dir / "trees.nwk"
23
+ change_times_file = data_dir / "change_times.csv"
23
24
 
25
+ trees = load_newick(str(tree_file))
26
+ assert isinstance(trees, list)
24
27
  change_times = (
25
28
  pl.read_csv(change_times_file, has_header=False).to_series().to_numpy()
26
29
  )
27
- time_predictor = " ".join(
28
- list(map(str, np.repeat(np.insert(change_times, 0, 0), 4)))
29
- )
30
+ time_predictor = " ".join(list(map(str, np.repeat([0, *change_times], 4))))
30
31
  body_mass_predictor = " ".join(["0", "1", "2", "3"] * (len(change_times) + 1))
31
32
 
32
- trees = load_newick(str(tree_file))
33
- assert isinstance(trees, list)
33
+ job_ids = {}
34
34
  for i, tree in enumerate(tqdm(trees)):
35
35
  process_length = max(get_node_depths(tree).values())
36
- for model in ["hidden-relu", "hidden-tanh"]:
37
- command = " ".join(
38
- [
39
- cfg.RUN_BEAST,
40
- f'-D treeFile={tree_file},treeIndex={i},typeTraitFile={THIS_DIR / "data" / "body_mass.csv"},changeTimesFile={change_times_file},samplingChangeTimesFile={sampling_change_times_file},processLength={process_length},timePredictor="{time_predictor}",bodyMassPredictor="{body_mass_predictor}"',
41
- f"-DF {THIS_DIR / 'params.json'}",
42
- f"-prefix {output_dir / model}",
43
- str(cfg.BEAST_CONFIGS_DIR / "fbd-empirical" / f"{model}.xml"),
44
- ]
45
- )
46
- run_sbatch(
47
- command,
48
- cfg.SBATCH_LOGS_DIR / "fbd-empirical" / model / str(i),
49
- mem_per_cpu="12000",
50
- )
51
-
52
-
53
- if __name__ == "__main__":
54
- main()
36
+ command = " ".join(
37
+ [
38
+ os.environ["BELLA_RUN_BEAST_CMD"],
39
+ f"-D types=0,1,2,3",
40
+ f'-D startTypePriorProbs="0.25 0.25 0.25 0.25"',
41
+ f"-D birthRateUpper=10",
42
+ f"-D deathRateUpper=10",
43
+ f"-D samplingRateUpper=10",
44
+ f'-D samplingRateInit="5 5 5 5 5 5 5"',
45
+ f"-D migrationRateUpper=10",
46
+ f'-D migrationRateInit="5 0 0 5 5 0 0 5 5 0 0 5"',
47
+ f'-D nodes="16 8"',
48
+ f'-D layersRange="0,1,2"',
49
+ f"-D treeFile={tree_file}",
50
+ f"-D treeIndex={i}",
51
+ f"-D changeTimesFile={change_times_file}",
52
+ f"-D samplingChangeTimesFile={data_dir / 'sampling_change_times.csv'}",
53
+ f"-D typeTraitFile={data_dir / 'body_mass.csv'}",
54
+ f"-D processLength={process_length}",
55
+ f'-D timePredictor="{time_predictor}"',
56
+ f'-D bodyMassPredictor="{body_mass_predictor}"',
57
+ f"-prefix {output_dir}{os.sep}",
58
+ str(Path(os.environ["BELLA_BEAST_CONFIGS_DIR"]) / "fbd-empirical.xml"),
59
+ ]
60
+ )
61
+ job_ids[i] = submit_job(
62
+ command,
63
+ Path(os.environ["BELLA_SBATCH_LOG_DIR"]) / "fbd-empirical" / str(i),
64
+ mem_per_cpu="12000",
65
+ )
66
+
67
+ with open(base_output_dir / "fbd_empirical_job_ids.json", "w") as f:
68
+ json.dump(job_ids, f)
@@ -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 src.config import BEAST_LOGS_SUMMARIES_DIR, BEAST_OUTPUTS_DIR
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 main():
15
- summaries_dir = os.path.join(BEAST_LOGS_SUMMARIES_DIR, "fbd-empirical")
16
- os.makedirs(summaries_dir, exist_ok=True)
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
- logs_summary, weights = summarize_logs(
33
- logs_dir,
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}Ratei{i}_{s}"
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 states
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
- logs_summary.write_csv(os.path.join(summaries_dir, f"MLP.csv"))
46
- joblib.dump(weights, os.path.join(summaries_dir, "weights.pkl"))
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__ = ["generate_data", "generate_figures", "run_beast", "summarize_logs"]
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.scenarios.epi_skyline import REPRODUCTION_NUMBERS
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 feature.is_binary for feature in features.values()):
49
- for (feature_name, feature), feature_pdvalues in zip(
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 = "red" if feature.is_relevant else "gray"
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=feature_name
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(feature.is_binary for feature in features.values()):
71
+ if any(f.is_binary for f in features.values()):
74
72
  data: list[float] = []
75
- grid_labels: list[int] = []
76
- feature_labels: list[str] = []
77
- for (feature_name, feature), feature_pdvalues in zip(
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
- grid_labels.extend([i] * len(feature_pdvalues[i]))
84
- feature_labels.extend([feature_name] * len(feature_pdvalues[i]))
85
- sns.violinplot(
86
- x=grid_labels,
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
- plt.xlabel("Feature value") # pyright: ignore
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="red" if feature.is_relevant else "gray",
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.scenarios.fbd_no_traits import RATES
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"]) / "targets"
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=os.path.join(base_output_dir, scenario_name),
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 summarize_logs as _summarize_logs
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 = _summarize_logs(
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 = summarize_weights(logs_dir)
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 summarize_log, summarize_logs, summarize_weights
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
- "summarize_logs",
16
- "summarize_weights",
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
  ]
@@ -36,7 +36,7 @@ def summarize_log(
36
36
  return summary
37
37
 
38
38
 
39
- def summarize_logs(
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 summarize_weights(
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.6
3
+ Version: 0.0.8
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.28,<3.0.0)
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=Oa5R9absmc9zYGb5bPdf_3o6cjoenxLcS5Sgp1uBpzM,2522
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.8.dist-info/METADATA,sha256=e7ZtRd2kPoER6o1m6zSZtLplX7dOox3WLqlZlH45og0,576
40
+ bella_companion-0.0.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
41
+ bella_companion-0.0.8.dist-info/entry_points.txt,sha256=rSeKoAhmjnQqAYFcXBv0gAM2ViJfJe0D8_dD-fWrXeg,50
42
+ bella_companion-0.0.8.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,11 +0,0 @@
1
- {
2
- "types": "0,1,2,3",
3
- "startTypePriorProbs": "0.25 0.25 0.25 0.25",
4
- "birthRateUpper": 2,
5
- "deathRateUpper": 2,
6
- "samplingRateUpper": 10,
7
- "samplingRateInit": "5 5 5 5 5 5 5",
8
- "migrationRateUpper": 10,
9
- "migrationRateInit": "0.5 0 0 0.5 0.5 0 0 0.5 0.5 0 0 0.5",
10
- "nodes": "16 8"
11
- }