Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement AffinePosteriorTransform #651

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aepsych/acquisition/objective/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ProbitObjective,
)
from .semi_p import SemiPProbabilityObjective, SemiPThresholdObjective
from .multi_outcome import AffinePosteriorTransform

__all__ = [
"AEPsychObjective",
Expand All @@ -25,6 +26,7 @@
"ProbitObjective",
"SemiPProbabilityObjective",
"SemiPThresholdObjective",
"AffinePosteriorTransform"
]

Config.register_module(sys.modules[__name__])
11 changes: 11 additions & 0 deletions aepsych/acquisition/objective/multi_outcome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from botorch.acquisition.objective import ScalarizedPosteriorTransform
from aepsych.config import ConfigurableMixin

class AffinePosteriorTransform(ScalarizedPosteriorTransform, ConfigurableMixin):
pass
3 changes: 1 addition & 2 deletions aepsych/models/model_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def predict_probability(self, x: torch.Tensor, **kwargs) -> torch.Tensor:
def predict_transform(
self,
x: torch.Tensor,
transformed_posterior_cls: Optional[type[TransformedPosterior]] = None,
**transform_kwargs,
**kwargs,
):
pass

Expand Down
16 changes: 16 additions & 0 deletions tests/acquisition/test_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
FloorGumbelObjective,
FloorLogitObjective,
FloorProbitObjective,
AffinePosteriorTransform
)
from parameterized import parameterized
from scipy.stats import gumbel_l, logistic, norm

from aepsych.config import Config
import numpy.testing as npt

objective_pairs = [
(FloorLogitObjective, logistic),
(FloorProbitObjective, norm),
Expand All @@ -42,3 +46,15 @@ def test_floor_links(self, objectives, floor):

our_inverse = our_link.inverse(our_answer)
self.assertTrue(np.allclose(x, our_inverse.numpy()))

class AffinePosteriorTransformTests(unittest.TestCase):
def test_from_config(self):
config_str = """
[AffinePosteriorTransform]
weights = [1, -1]
offset = 0
"""
config = Config(config_str=config_str)
apt = AffinePosteriorTransform.from_config(config=config)
npt.assert_array_equal(apt.weights, torch.tensor([1., -1.]))
self.assertEqual(apt.offset, 0.0)
Loading