forked from pytorch/botorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model Input Standardization Using
TrainingData
(pytorch#477)
Summary: Pull Request resolved: pytorch#477 Different GP models take different kwargs as inputs into their constructors. To standardize the inputs, we create a `TrainingData` dataclass in conjunction with a classmethod `construct_inputs()`. Reviewed By: Balandat Differential Revision: D22395030 fbshipit-source-id: be89da3e2878993d8ba8972e48712762e9c3ccc8
- Loading branch information
1 parent
a153151
commit dc111ba
Showing
8 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
r""" | ||
Containers to standardize inputs into models and acquisition functions. | ||
""" | ||
|
||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
from torch import Tensor | ||
|
||
|
||
@dataclass | ||
class TrainingData: | ||
r"""Standardized struct of model training data.""" | ||
|
||
Xs: List[Tensor] | ||
Ys: List[Tensor] | ||
Yvars: Optional[List[Tensor]] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import torch | ||
from botorch.utils.containers import TrainingData | ||
from botorch.utils.testing import BotorchTestCase | ||
|
||
|
||
class TestConstructContainers(BotorchTestCase): | ||
def test_TrainingData(self): | ||
Xs = torch.tensor([[-1.0, 0.0, 0.0], [0.0, 1.0, 1.0]]) | ||
Ys = torch.tensor([[-1.0, 0.0, 0.0], [0.0, 1.0, 1.0]]) | ||
Yvars = torch.tensor([[-1.0, 0.0, 0.0], [0.0, 1.0, 1.0]]) | ||
|
||
training_data = TrainingData(Xs, Ys) | ||
self.assertTrue(torch.equal(training_data.Xs, Xs)) | ||
self.assertTrue(torch.equal(training_data.Ys, Ys)) | ||
self.assertEqual(training_data.Yvars, None) | ||
|
||
training_data = TrainingData(Xs, Ys, Yvars) | ||
self.assertTrue(torch.equal(training_data.Xs, Xs)) | ||
self.assertTrue(torch.equal(training_data.Ys, Ys)) | ||
self.assertTrue(torch.equal(training_data.Yvars, Yvars)) |