-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from kiudee/38_priors
Support changing the Gaussian process prior parameters using the CLI
- Loading branch information
Showing
7 changed files
with
243 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
import numpy as np | ||
from numpy.testing import assert_almost_equal | ||
from pytest import approx, raises | ||
|
||
from tune.priors import roundflat | ||
from tune.priors import create_priors, make_invgamma_prior, roundflat | ||
|
||
|
||
def test_roundflat(): | ||
assert_almost_equal(roundflat(0.3), 0.0, decimal=0.1) | ||
|
||
assert roundflat(0.3) == approx(0.0, abs=1e-6) | ||
assert roundflat(0.0) == -np.inf | ||
assert roundflat(-1.0) == -np.inf | ||
|
||
|
||
def test_make_invgamma_prior(): | ||
prior = make_invgamma_prior() | ||
assert prior.kwds["a"] == approx(8.919240823584246) | ||
assert prior.kwds["scale"] == approx(1.7290248731437994) | ||
|
||
with raises(ValueError): | ||
make_invgamma_prior(lower_bound=-1e-10) | ||
with raises(ValueError): | ||
make_invgamma_prior(upper_bound=-1e-10) | ||
with raises(ValueError): | ||
make_invgamma_prior(lower_bound=0.5, upper_bound=0.1) | ||
|
||
|
||
def test_create_priors(): | ||
priors = create_priors(n_parameters=3) | ||
assert len(priors) == 5 | ||
assert priors[0](2.0) == approx(-1.536140897416146) | ||
assert priors[1](2.0) == approx(-23.620792572134874) | ||
assert priors[2](2.0) == approx(-23.620792572134874) | ||
assert priors[3](2.0) == approx(-23.620792572134874) | ||
assert priors[4](2.0) == approx(-10262570.41553909) | ||
|
||
with raises(ValueError): | ||
create_priors(n_parameters=3, signal_scale=0.0) | ||
with raises(ValueError): | ||
create_priors(n_parameters=3, noise_scale=0.0) |
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