Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
janfb committed Dec 2, 2022
1 parent 6fe5062 commit 60b9ec8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 46 deletions.
1 change: 1 addition & 0 deletions sbibm/algorithms/sbi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sbibm.algorithms.sbi.mcabc import run as mcabc
from sbibm.algorithms.sbi.sl import run as sl
from sbibm.algorithms.sbi.smcabc import run as smcabc
from sbibm.algorithms.sbi.snle import run as snle
from sbibm.algorithms.sbi.snpe import run as snpe
Expand Down
4 changes: 2 additions & 2 deletions sbibm/algorithms/sbi/sl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, Optional, Tuple
from typing import Any, Dict, Optional

import torch
import torch.nn as nn
Expand Down Expand Up @@ -95,7 +95,7 @@ def run(
mcmc_method: str = "slice_np",
mcmc_parameters: Dict[str, Any] = {},
diag_eps: float = 0.0,
) -> Tuple[torch.Tensor, int, Optional[torch.Tensor]]:
) -> tuple[torch.Tensor, int, Optional[torch.Tensor]]:
"""Runs (S)NLE from `sbi`
Args:
Expand Down
11 changes: 4 additions & 7 deletions sbibm/algorithms/sbi/snle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import math
from typing import Any, Dict, Optional, Tuple
from typing import Any, Dict, Optional

import torch
from sbi import inference as inference
Expand All @@ -24,14 +24,13 @@ def run(
neural_net: str = "maf",
hidden_features: int = 50,
simulation_batch_size: int = 1000,
# NOTE: why is the training batch size so high?
training_batch_size: int = 10000,
automatic_transforms_enabled: bool = True,
mcmc_method: str = "slice_np_vectorized",
mcmc_parameters: Dict[str, Any] = {
"num_chains": 100,
"thin": 10,
"warmup_steps": 100,
"warmup_steps": 25,
"init_strategy": "sir",
# NOTE: sir kwargs changed: num_candidate_samples = num_batches * batch_size
"init_strategy_parameters": {
Expand All @@ -40,8 +39,8 @@ def run(
},
z_score_x: bool = True,
z_score_theta: bool = True,
max_num_epochs: Optional[int] = 2**31 -1,
) -> Tuple[torch.Tensor, int, Optional[torch.Tensor]]:
max_num_epochs: Optional[int] = 2**31 - 1,
) -> tuple[torch.Tensor, int, Optional[torch.Tensor]]:
"""Runs (S)NLE from `sbi`
Args:
Expand Down Expand Up @@ -109,8 +108,6 @@ def run(

posteriors = []
proposal = prior
# NOTE: why was this hard coded here?
# mcmc_parameters["warmup_steps"] = 25

for r in range(num_rounds):
theta, x = inference.simulate_for_sbi(
Expand Down
6 changes: 3 additions & 3 deletions sbibm/algorithms/sbi/snpe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import math
from typing import Optional, Tuple
from typing import Optional

import torch
from sbi import inference as inference
Expand Down Expand Up @@ -29,8 +29,8 @@ def run(
automatic_transforms_enabled: bool = False,
z_score_x: bool = True,
z_score_theta: bool = True,
max_num_epochs: Optional[int] = 2**31 -1,
) -> Tuple[torch.Tensor, int, Optional[torch.Tensor]]:
max_num_epochs: Optional[int] = 2**31 - 1,
) -> tuple[torch.Tensor, int, Optional[torch.Tensor]]:
"""Runs (S)NPE from `sbi`
Args:
Expand Down
9 changes: 4 additions & 5 deletions sbibm/algorithms/sbi/snre.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import math
from typing import Any, Dict, Optional, Tuple
from typing import Any, Dict, Optional

import torch
from sbi import inference as inference
Expand Down Expand Up @@ -31,7 +31,7 @@ def run(
mcmc_parameters: Dict[str, Any] = {
"num_chains": 100,
"thin": 10,
"warmup_steps": 100,
"warmup_steps": 25,
"init_strategy": "sir",
# NOTE: sir kwargs changed: num_candidate_samples = num_batches * batch_size
"init_strategy_parameters": {
Expand All @@ -41,8 +41,8 @@ def run(
z_score_x: bool = True,
z_score_theta: bool = True,
variant: str = "B",
max_num_epochs: Optional[int] = 2**31 -1,
) -> Tuple[torch.Tensor, int, Optional[torch.Tensor]]:
max_num_epochs: Optional[int] = 2**31 - 1,
) -> tuple[torch.Tensor, int, Optional[torch.Tensor]]:
"""Runs (S)NRE from `sbi`
Args:
Expand Down Expand Up @@ -118,7 +118,6 @@ def run(

posteriors = []
proposal = prior
# mcmc_parameters["warmup_steps"] = 25

for r in range(num_rounds):
theta, x = inference.simulate_for_sbi(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"pandas>=1.0.0",
"pyabc>=0.10.8",
"pyabcranger>=0.0.48",
"sbi==0.20.0",
"sbi>=0.20.0",
"pyro-ppl",
"scikit-learn",
"torch>=1.8.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/algorithms/sbi/test_sbi_run_methods.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

import sbibm
from sbibm.algorithms.sbi import mcabc, smcabc, snle, snpe, snre
from sbibm.algorithms.sbi import mcabc, smcabc, snle, snpe, snre, sl


# a fast test
@pytest.mark.parametrize(
"run_method", (mcabc, smcabc, snle, snpe, snre)
"run_method", (mcabc, smcabc, snle, snpe, snre, sl)
)
@pytest.mark.parametrize("task_name", ("gaussian_linear",))
@pytest.mark.parametrize("num_observation", (1, 3))
Expand Down
26 changes: 0 additions & 26 deletions tests/algorithms/sbi/test_sl_run_methods.py

This file was deleted.

0 comments on commit 60b9ec8

Please sign in to comment.