forked from huawei-noah/HEBO
-
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.
- Loading branch information
Showing
32 changed files
with
1,829 additions
and
35 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
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,42 @@ | ||
# Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved. | ||
|
||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT license. | ||
|
||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
# PARTICULAR PURPOSE. See the MIT License for more details. | ||
|
||
from typing import Tuple | ||
import torch | ||
|
||
from mcbo.acq_funcs.lcb import LCB | ||
from mcbo.models.gp.rand_decomposition_gp import RandDecompositionGP | ||
|
||
|
||
class AddLCB(LCB): | ||
def __init__(self, beta: float = 1.96): | ||
super().__init__(beta) | ||
|
||
def evaluate(self, | ||
x: torch.Tensor, | ||
model: RandDecompositionGP, | ||
**kwargs | ||
) -> torch.Tensor: | ||
val = 0 | ||
for clique in model.graph: | ||
val += self.partial_evaluate(x, model, clique, **kwargs) | ||
|
||
return val | ||
|
||
def partial_evaluate(self, | ||
x: torch.Tensor, | ||
model: RandDecompositionGP, | ||
clique: Tuple[int], | ||
**kwargs | ||
) -> torch.Tensor: | ||
mean, var = model.partial_predict(x, clique) | ||
mean = mean.flatten() | ||
std = var.clamp_min(1e-9).sqrt().flatten() | ||
|
||
return mean - self.beta * std |
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
Oops, something went wrong.