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

I612 toy inputs issue #1505

Merged
merged 10 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
Empty file modified pints/tests/test_abc_rejection.py
100644 → 100755
Empty file.
Empty file modified pints/tests/test_abc_smc.py
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions pints/tests/test_toy_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def test_gaussian_logpdf(self):
self.assertRaises(
ValueError, pints.toy.GaussianLogPDF, [1, 2, 3], [1, 2, 3, 4])

# Bad calls to function
f = pints.toy.GaussianLogPDF([1, 2, 3], [1, 1, 1])
self.assertRaises(ValueError, f.__call__, [1, 2])
chonlei marked this conversation as resolved.
Show resolved Hide resolved
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])

def test_sampling_and_kl_divergence(self):
# Test GaussianLogPDF.kl_divergence() and .sample().

Expand Down
5 changes: 5 additions & 0 deletions pints/tests/test_toy_high_dimensional_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def test_high_dimensional_log_pdf(self):
self.assertRaises(
ValueError, pints.toy.HighDimensionalGaussianLogPDF, 11, -0.11)

# Bad calls to function
f = pints.toy.HighDimensionalGaussianLogPDF(3)
self.assertRaises(ValueError, f.__call__, [1, 2])
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])

def test_sensitivities(self):
# tests that sensitivities are correct

Expand Down
5 changes: 5 additions & 0 deletions pints/tests/test_toy_multimodal_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def test_basic(self):
[1, 1], [1.5, 1.5], [3, 0], [0, 3.5]
])

# Bad calls to function
f = pints.toy.MultimodalGaussianLogPDF([[1, 1, 1]])
self.assertRaises(ValueError, f.__call__, [1, 2])
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])

def test_bad_constructors(self):
# Tests bad Constructors.

Expand Down
5 changes: 5 additions & 0 deletions pints/tests/test_toy_parabolic_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def test_parabolic_error(self):
self.assertAlmostEqual(dfx[1], 0)
self.assertAlmostEqual(dfx[2], -0.4)

# Bad calls to function
f = pints.toy.ParabolicError([1, 1, 1])
self.assertRaises(ValueError, f.__call__, [1, 2])
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions pints/tests/test_toy_twisted_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def test_twisted_gaussian_logpdf(self):
self.assertRaises(ValueError, pints.toy.TwistedGaussianLogPDF, 1)
self.assertRaises(ValueError, pints.toy.TwistedGaussianLogPDF, b=-1)

# Bad calls to function
f = pints.toy.TwistedGaussianLogPDF(3)
self.assertRaises(ValueError, f.__call__, [1, 2])
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])

def test_sampling_and_kl_divergence(self):
# Test TwistedGaussianLogPDF.kl_divergence() and .sample().

Expand Down
4 changes: 3 additions & 1 deletion pints/toy/_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import scipy.stats

from . import ToyLogPDF
from .. import vector


class GaussianLogPDF(ToyLogPDF):
Expand Down Expand Up @@ -58,7 +59,8 @@ def __init__(self, mean=[0, 0], sigma=[1, 1]):
self._sigma_inv = np.linalg.inv(self._sigma)

def __call__(self, x):
return self._phi.logpdf(x)
y = vector(x).reshape(self._n_parameters)
return self._phi.logpdf(y)

def distance(self, samples):
"""
Expand Down
4 changes: 3 additions & 1 deletion pints/toy/_high_dimensional_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import scipy.stats

from . import ToyLogPDF
from .. import vector


class HighDimensionalGaussianLogPDF(ToyLogPDF):
Expand Down Expand Up @@ -61,7 +62,8 @@ def __init__(self, dimension=20, rho=0.5):
self._var = scipy.stats.multivariate_normal(self._mean, self._cov)

def __call__(self, x):
return self._var.logpdf(x)
y = vector(x).reshape(self._n_parameters)
return self._var.logpdf(y)

def distance(self, samples):
"""
Expand Down
3 changes: 2 additions & 1 deletion pints/toy/_multimodal_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def __init__(self, modes=None, covariances=None):
np.linalg.inv(self._covs[i]) for i, mode in enumerate(self._modes)]

def __call__(self, x):
f = np.sum([var.pdf(x) for var in self._vars])
y = pints.vector(x).reshape(self._n_parameters)
f = np.sum([var.pdf(y) for var in self._vars])
return -np.inf if f == 0 else np.log(f)

def distance(self, samples):
Expand Down
3 changes: 2 additions & 1 deletion pints/toy/_parabola.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, c=[0, 0]):
self._n = len(self._c)

def __call__(self, x):
return np.sum((self._c - x)**2)
y = pints.vector(x).reshape(self._n)
return np.sum((self._c - y)**2)

def evaluateS1(self, x):
""" See :meth:`pints.ErrorMeasure.evaluateS1()`. """
Expand Down
1 change: 1 addition & 0 deletions pints/toy/_twisted_gaussian_banana.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __call__(self, x):
y = np.array(x, copy=True, dtype='float')
y[0] = float(y[0]) / np.sqrt(self._V)
y[1] += self._b * ((x[0] ** 2) - self._V)
y = y.reshape(self._n_parameters)
chonlei marked this conversation as resolved.
Show resolved Hide resolved
return self._phi.logpdf(y)

def distance(self, samples):
Expand Down
Loading