Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- [#1724](https://github.com/pints-team/pints/pull/1724) The classes `PooledLogPDF` and `SumOfIndependentLogPDFs` are deprecated, in favour of `PooledLogLikelihood` and `SumOfIndependentLogLikelihoods` respectively.
- [#1508](https://github.com/pints-team/pints/pull/1508) The methods `OptimisationController.max_unchanged_iterations` and `set_max_unchanged_iterations` are deprecated, in favour of `function_tolerance` and `set_function_tolerance` respectively.
### Removed
- [#1731](https://github.com/pints-team/pints/pull/1731) The method `ToyLogPDF.suggested_bounds()` and its implementations have been removed.
### Fixed
- [#1713](https://github.com/pints-team/pints/pull/1713) Fixed Numpy 2.4.1 compatibility issues.
- [#1690](https://github.com/pints-team/pints/pull/1690) Fixed bug in optimisation controller if population size left at `None`.
Expand Down
20 changes: 0 additions & 20 deletions pints/tests/test_toy_annulus_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,6 @@ def test_bad_constructors(self):
self.assertRaises(
ValueError, pints.toy.AnnulusLogPDF, 3, 1, -1)

def test_suggested_bounds(self):
# Tests suggested_bounds() method

f = pints.toy.AnnulusLogPDF()
bounds = f.suggested_bounds()
a_val = 55
self.assertTrue(np.array_equal([[-a_val, -a_val], [a_val, a_val]],
bounds))
r0 = 25
dimensions = 5
sigma = 20
f = pints.toy.AnnulusLogPDF(dimensions=dimensions,
r0=r0,
sigma=sigma)
bounds = f.suggested_bounds()
r0_magnitude = (r0 + sigma) * (5**(1.0 / (dimensions - 1.0)))
self.assertEqual(bounds[0][0], -r0_magnitude)
self.assertEqual(bounds[1][0], r0_magnitude)
self.assertTrue(np.array_equal(np.array(bounds).shape, [2, 5]))

def test_distance_function(self):
# Tests distance function

Expand Down
3 changes: 1 addition & 2 deletions pints/tests/test_toy_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def test_run(self):
model = pints.toy.Hes1Model()
vals = [1, 2, 3]
model.set_initial_conditions(vals)
self.assertTrue(np.array_equal(model.initial_conditions(),
vals))
self.assertTrue(np.array_equal(model.initial_conditions(), vals))


if __name__ == '__main__':
Expand Down
16 changes: 0 additions & 16 deletions pints/tests/test_toy_cone_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ def test_bad_constructors(self):
self.assertRaises(ValueError, f.__call__, [1, 2, 3])
self.assertRaises(ValueError, f.__call__, [1, 2, 3, 4, 5])

def test_bounds(self):
# Tests suggested_bounds()

f = pints.toy.ConeLogPDF()
bounds = f.suggested_bounds()
self.assertTrue(np.array_equal([[-1000, -1000], [1000, 1000]],
bounds))
beta = 3
dimensions = 4
f = pints.toy.ConeLogPDF(beta=beta, dimensions=dimensions)
magnitude = 1000
bounds = np.tile([-magnitude, magnitude], (dimensions, 1))
self.assertEqual(bounds[0][0], -magnitude)
self.assertEqual(bounds[0][1], magnitude)
self.assertTrue(np.array_equal(np.array(bounds).shape, [4, 2]))

def test_sensitivities(self):
# Tests sensitivities

Expand Down
7 changes: 1 addition & 6 deletions pints/tests/test_toy_eight_schools_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_basic(self):

# Default settings
f = pints.toy.EightSchoolsLogPDF()
self.assertEqual(f.n_parameters(), 10)
f1, dp = f.evaluateS1(np.ones(10))
self.assertEqual(f1, f(np.ones(10)))
self.assertAlmostEqual(f1, -43.02226038161451)
Expand Down Expand Up @@ -83,12 +84,6 @@ def test_negative_sd(self):
self.assertEqual(logp, -np.inf)
self.assertTrue(np.array_equal(grad, np.full([1, 10], -np.inf)))

def test_bounds(self):
""" Tests suggested_bounds() """
f = pints.toy.EightSchoolsLogPDF()
bounds = f.suggested_bounds()
self.assertEqual(bounds[0][1], 0)


if __name__ == '__main__':
unittest.main()
5 changes: 1 addition & 4 deletions pints/tests/test_toy_german_credit_hierarchical_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ def test_sensitivities(self):
self.assertAlmostEqual(dp[1], -700.8386959844057, places=6)

def test_givens(self):
# tests whether boundaries are correct and n_parameters
# tests n_parameters
self.assertEqual(326, self.model.n_parameters())
borders = self.model.suggested_bounds()
self.assertEqual(borders[0][0], -100)
self.assertEqual(borders[1][0], 100)


if __name__ == '__main__':
Expand Down
5 changes: 1 addition & 4 deletions pints/tests/test_toy_german_credit_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ def test_sensitivities(self):
self.assertAlmostEqual(dp[1], -160.7785147438439, places=6)

def test_givens(self):
# tests whether boundaries are correct and n_parameters
# tests n_parameters
self.assertEqual(25, self.model.n_parameters())
borders = self.model.suggested_bounds()
self.assertEqual(borders[0][0], -100)
self.assertEqual(borders[1][0], 100)


if __name__ == '__main__':
Expand Down
12 changes: 0 additions & 12 deletions pints/tests/test_toy_high_dimensional_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ def test_high_dimensional_log_pdf(self):
f([1, 2]),
scipy.stats.multivariate_normal.logpdf([1, 2], mean, cov))

# check suggested bounds
f = pints.toy.HighDimensionalGaussianLogPDF(dimension=2)
bounds = f.suggested_bounds()
magnitude = 3 * np.sqrt(2.0)
bounds1 = np.tile([-magnitude, magnitude], (2, 1))
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))

f = pints.toy.HighDimensionalGaussianLogPDF()
bounds = f.suggested_bounds()
self.assertTrue(bounds[0][0], np.sqrt(20) * 3.0)

# Test kl_divergence() errors
n = 1000
d = f.n_parameters()
Expand Down
27 changes: 0 additions & 27 deletions pints/tests/test_toy_multimodal_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,6 @@ def test_sensitivities(self):
self.assertAlmostEqual(dl[1], -0.054933536830093638)
self.assertAlmostEqual(dl[2], -0.39317158556789844)

def test_suggested_bounds(self):
# Tests suggested_bounds().

f = pints.toy.MultimodalGaussianLogPDF()
covariances = [[[5**2, 0.5 * 5 * 3, -0.1 * 5 * 2],
[0.5 * 5 * 3, 3**2, 0.4 * 3 * 2],
[-0.1 * 5 * 2, 0.4 * 3 * 2, 2**2]],
[[5**2, 0.3 * 5 * 6, 0.2 * 5 * 7],
[0.3 * 5 * 6, 6**2, -0.3 * 6 * 7],
[0.2 * 5 * 7, -0.3 * 6 * 7, 7**2]]]
bounds = f.suggested_bounds()
lower = -10
upper = 20
bounds1 = np.tile([lower, upper], (2, 1))
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))

f = pints.toy.MultimodalGaussianLogPDF(
modes=[[1, 2, 3], [3, 4, 5]],
covariances=covariances)
bounds = f.suggested_bounds()
lower = 1 - 4
upper = 5 + 4
bounds1 = np.tile([lower, upper], (3, 1))
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))

def test_distance_function(self):
# Tests distance function which calls kl_divergence().

Expand Down
20 changes: 0 additions & 20 deletions pints/tests/test_toy_neals_funnel_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,6 @@ def test_bespoke(self):
x = np.ones((n, d, 2))
self.assertRaises(ValueError, f.kl_divergence, x)

def test_suggested_bounds(self):
# Tests suggested_bounds().
# default
f = pints.toy.NealsFunnelLogPDF()
bounds = f.suggested_bounds()
magnitude = 30
bounds1 = np.tile([-magnitude, magnitude],
(f._n_parameters, 1))
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))

# non-default
f = pints.toy.NealsFunnelLogPDF(20)
bounds = f.suggested_bounds()
magnitude = 30
bounds1 = np.tile([-magnitude, magnitude],
(f._n_parameters, 1))
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))


if __name__ == '__main__':
unittest.main()
7 changes: 1 addition & 6 deletions pints/tests/test_toy_rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ def test_log_pdf(self):
self.assertEqual(dl[0], float(-6004.0 / 2505.0))
self.assertEqual(dl[1], float(200.0 / 501.0))

# suggested bounds and distance measure
bounds = f.suggested_bounds()
bounds = [[-2, 4], [-1, 12]]
bounds = np.transpose(bounds).tolist()
self.assertTrue(np.array_equal(bounds, f.suggested_bounds()))

# Distance measure
x = np.ones((100, 3))
self.assertRaises(ValueError, f.distance, x)
x = np.ones((100, 3, 2))
Expand Down
7 changes: 1 addition & 6 deletions pints/tests/test_toy_simple_egg_box_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ def test_sampling_and_divergence(self):
x = np.ones((n, 2, 2))
self.assertRaises(ValueError, log_pdf1.kl_divergence, x)

def test_sensitivity_bounds_distance(self):
def test_sensitivity_and_distance(self):
# Tests :meth:`SimpleEggBoxLogPDF.evaluateS1()`,
# :meth:`SimpleEggBoxLogPDF.suggested_bounds()` and
# :meth:`SimpleEggBoxLogPDF.distance()`

f = pints.toy.SimpleEggBoxLogPDF()
Expand All @@ -81,8 +80,6 @@ def test_sensitivity_bounds_distance(self):
self.assertAlmostEqual(l, -13.781024134434123)
self.assertAlmostEqual(dl[0], -1.5)
self.assertAlmostEqual(dl[1], 2.9999991)
self.assertTrue(np.array_equal(f.suggested_bounds(),
[[-16.0, -16.0], [16.0, 16.0]]))
samples = f.sample(100)
self.assertTrue(f.kl_divergence(samples) > 0)
self.assertEqual(f.kl_divergence(samples), f.distance(samples))
Expand All @@ -93,8 +90,6 @@ def test_sensitivity_bounds_distance(self):
self.assertAlmostEqual(l, -46.269777289511559)
self.assertAlmostEqual(dl[0], -4.6662126879796366)
self.assertAlmostEqual(dl[1], -2.6666666666666639)
self.assertTrue(np.array_equal(f.suggested_bounds(),
[[-30.0, -30.0], [30.0, 30.0]]))
samples = f.sample(100)
self.assertTrue(f.kl_divergence(samples) > 0)
self.assertEqual(f.kl_divergence(samples), f.distance(samples))
Expand Down
7 changes: 0 additions & 7 deletions pints/tests/test_toy_twisted_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ def test_sampling_and_kl_divergence(self):
x = np.ones((n, d, 2))
self.assertRaises(ValueError, log_pdf1.kl_divergence, x)

# Test suggested bounds
f = pints.toy.TwistedGaussianLogPDF()
bounds = f.suggested_bounds()
bounds1 = [[-50, 50], [-100, 100]]
bounds1 = np.transpose(bounds1).tolist()
self.assertTrue(np.array_equal(bounds, bounds1))

def test_values_sensitivity(self):
# Tests values of log pdf and sensitivities

Expand Down
13 changes: 1 addition & 12 deletions pints/toy/_annulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def __call__(self, x):
def distance(self, samples):
"""
Calculates a measure of normed distance of samples from exact mean and
covariance matrix assuming uniform prior with bounds given by
:meth:`suggested_bounds`.
covariance matrix.

See :meth:`ToyLogPDF.distance()`.
"""
Expand Down Expand Up @@ -174,16 +173,6 @@ def sigma(self):
"""
return self._sigma

def suggested_bounds(self):
""" See :meth:`ToyLogPDF.suggested_bounds()`. """
# in higher dimensions reduce volume as otherwise gets too wide
r0_magnitude = (self._r0 + self._sigma) * (
5**(1.0 / (self._n_parameters - 1.0))
)
bounds = np.tile([-r0_magnitude, r0_magnitude],
(self._n_parameters, 1))
return np.transpose(bounds).tolist()

def var_normed(self):
"""
Returns the variance of the normed distance from the origin.
Expand Down
9 changes: 1 addition & 8 deletions pints/toy/_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def CDF(self, x):
def distance(self, samples):
"""
Calculates a measure of normed distance of samples from exact mean and
covariance matrix assuming uniform prior with bounds given by
:meth:`suggested_bounds()`.
covariance matrix.

See :meth:`pints.toy.ToyLogPDF.distance()`.
"""
Expand Down Expand Up @@ -137,12 +136,6 @@ def sample(self, n_samples):
x_unit = [r[i] * X_norm[i] / y for i, y in enumerate(lambda_x)]
return np.array(x_unit)

def suggested_bounds(self):
""" See :meth:`ToyLogPDF.suggested_bounds()`. """
magnitude = 1000
bounds = np.tile([-magnitude, magnitude], (self._n_parameters, 1))
return np.transpose(bounds).tolist()

def var_normed(self):
"""
Returns the variance of the normed distance from the origin.
Expand Down
6 changes: 0 additions & 6 deletions pints/toy/_eight_schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,3 @@ def n_parameters(self):
""" See :meth:`pints.LogPDF.n_parameters()`. """
return self._n_parameters

def suggested_bounds(self):
""" See :meth:`pints.toy.ToyLogPDF.suggested_bounds()`. """
magnitude = 40
bounds = np.tile([-magnitude, magnitude], (self.n_parameters(), 1))
bounds[1, 0] = 0
return np.transpose(bounds).tolist()
5 changes: 0 additions & 5 deletions pints/toy/_german_credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,3 @@ def evaluateS1(self, beta):
def n_parameters(self):
return self._n_parameters

def suggested_bounds(self):
""" See :meth:`ToyLogPDF.suggested_bounds()`. """
magnitude = 100
bounds = np.tile([-magnitude, magnitude], (self._n_parameters, 1))
return np.transpose(bounds).tolist()
5 changes: 0 additions & 5 deletions pints/toy/_german_credit_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,3 @@ def evaluateS1(self, theta):
def n_parameters(self):
return self._n_parameters

def suggested_bounds(self):
""" See :meth:`ToyLogPDF.suggested_bounds()`. """
magnitude = 100
bounds = np.tile([-magnitude, magnitude], (self._n_parameters, 1))
return np.transpose(bounds).tolist()
7 changes: 0 additions & 7 deletions pints/toy/_high_dimensional_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,3 @@ def sample(self, n_samples):
'Number of samples must be greater than or equal to 1.')
return self._var.rvs(n_samples)

def suggested_bounds(self):
""" See :meth:`pints.toy.ToyLogPDF.suggested_bounds()`. """
# maximum variance in one dimension is n_parameters, so use
# 3 times sqrt of this as prior bounds
magnitude = 3 * np.sqrt(self.n_parameters())
bounds = np.tile([-magnitude, magnitude], (self.n_parameters(), 1))
return np.transpose(bounds).tolist()
10 changes: 0 additions & 10 deletions pints/toy/_multimodal_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,3 @@ def sample(self, n_samples):
samples[i, :] = self._vars[rand_mode].rvs(1)
return samples

def suggested_bounds(self):
""" See :meth:`pints.toy.ToyLogPDF.suggested_bounds()`. """
# make rectangular bounds in each dimension 3X width of range
a_max = np.max(self._modes)
a_min = np.min(self._modes)
a_range = a_max - a_min
lower = a_min - a_range
upper = a_max + a_range
bounds = np.tile([lower, upper], (self._n_parameters, 1))
return np.transpose(bounds).tolist()
7 changes: 0 additions & 7 deletions pints/toy/_neals_funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ def sample(self, n_samples):
samples[i, n - 1] = nu
return samples

def suggested_bounds(self):
""" See :meth:`pints.toy.ToyLogPDF.suggested_bounds()`. """
magnitude = 30
bounds = np.tile([-magnitude, magnitude],
(self._n_parameters, 1))
return np.transpose(bounds).tolist()

def var(self):
"""
Returns the variance of the target distribution in each dimension.
Expand Down
9 changes: 1 addition & 8 deletions pints/toy/_rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class RosenbrockLogPDF(ToyLogPDF):
def __init__(self):
self._f = RosenbrockError()

# assumes uniform prior with bounds given by suggested_bounds
self._true_mean = np.array([0.8693578490590254, 2.599780856590108])
self._true_cov = np.array([[1.805379677045191, 2.702575590274159],
[2.702575590274159, 8.526583078612177]])
Expand All @@ -70,8 +69,7 @@ def __call__(self, x):
def distance(self, samples):
"""
Calculates a measure of normed distance of samples from exact mean and
covariance matrix assuming uniform prior with bounds given
by :meth:`suggested_bounds()`.
covariance matrix.

See :meth:`pints.toy.ToyLogPDF.distance()`.
"""
Expand Down Expand Up @@ -118,8 +116,3 @@ def optimum(self):
"""
return self._f.optimum()

def suggested_bounds(self):
""" See :meth:`pints.toy.ToyLogPDF.suggested_bounds()`. """
# think the following hard bounds are ok
bounds = [[-2, 4], [-1, 12]]
return np.transpose(bounds).tolist()
Loading