Skip to content

Commit

Permalink
Merge pull request #1497 from pints-team/issue-1496-deprecation-warni…
Browse files Browse the repository at this point in the history
…ng-uniform-prior

#1496 replace np.product by np.prod everywhere
  • Loading branch information
DavAug authored Oct 9, 2023
2 parents d8cec9b + 1ba17cb commit b07f75e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All notable changes to this project will be documented in this file.
- [#1424](https://github.com/pints-team/pints/pull/1424) Removed the `TriangleWaveTransform` class previously used in some optimisers.

### Fixed
- [#1497](https://github.com/pints-team/pints/pull/1497) Fixed deprecation warning of `np.product` globally in pints.
- [#1457](https://github.com/pints-team/pints/pull/1457) Fixed typo in deprecation warning for `UnknownNoiseLikelihood`.
- [#1455](https://github.com/pints-team/pints/pull/1455) The `s` and `inv_s` properties of `ScalingTransformation` have been replaced with private properties `_s` and `_inv_s`.
- [#1450](https://github.com/pints-team/pints/pull/1450) Made `TransformedBoundaries` consistent with `Boundaries` by removing `range()` and adding `sample()`.
Expand Down
2 changes: 1 addition & 1 deletion pints/_error_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MeanSquaredError(ProblemErrorMeasure):
"""
def __init__(self, problem, weights=None):
super(MeanSquaredError, self).__init__(problem)
self._ninv = 1.0 / np.product(self._values.shape)
self._ninv = 1.0 / np.prod(self._values.shape)

if weights is None:
weights = [1] * self._n_outputs
Expand Down
2 changes: 1 addition & 1 deletion pints/_log_likelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def __init__(self, log_likelihood):
self._log_likelihood = log_likelihood

# Pre-calculate parts
self._f = 1.0 / np.product(self._values.shape)
self._f = 1.0 / np.prod(self._values.shape)

def __call__(self, x):
return self._f * self._log_likelihood(x)
Expand Down
2 changes: 1 addition & 1 deletion pints/_log_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def __init__(self, lower_or_boundaries, upper=None):
# Use normalised value (1/area) for rectangular boundaries,
# otherwise just use 1.
if isinstance(self._boundaries, pints.RectangularBoundaries):
self._value = -np.log(np.product(self._boundaries.range()))
self._value = -np.log(np.prod(self._boundaries.range()))
else:
self._value = 1

Expand Down
6 changes: 3 additions & 3 deletions pints/_mcmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, x0, sigma0=None):
self._sigma0 = np.diag(0.01 * self._sigma0)
else:
self._sigma0 = np.array(sigma0, copy=True)
if np.product(self._sigma0.shape) == self._n_parameters:
if np.prod(self._sigma0.shape) == self._n_parameters:
# Convert from 1d array
self._sigma0 = self._sigma0.reshape((self._n_parameters,))
self._sigma0 = np.diag(self._sigma0)
Expand Down Expand Up @@ -192,7 +192,7 @@ def __init__(self, chains, x0, sigma0=None):
self._sigma0 = np.diag(0.01 * self._sigma0)
else:
self._sigma0 = np.array(sigma0, copy=True)
if np.product(self._sigma0.shape) == self._n_parameters:
if np.prod(self._sigma0.shape) == self._n_parameters:
# Convert from 1d array
self._sigma0 = self._sigma0.reshape((self._n_parameters,))
self._sigma0 = np.diag(self._sigma0)
Expand Down Expand Up @@ -352,7 +352,7 @@ def __init__(
else:
n_parameters = log_pdf[0].n_parameters()
# Make sure sigma0 is a (covariance) matrix
if np.product(sigma0.shape) == n_parameters:
if np.prod(sigma0.shape) == n_parameters:
# Convert from 1d array
sigma0 = sigma0.reshape((n_parameters,))
sigma0 = np.diag(sigma0)
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ def __init__(self, function, dimension, x, y):
self.d = dimension
self.x = x
self.y = y
self.n = 1 / np.product(y.shape) # Total number of points in data
self.n = 1 / np.prod(y.shape) # Total number of points in data

def n_parameters(self):
return self.d
Expand Down
4 changes: 2 additions & 2 deletions pints/tests/test_log_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ def test_uniform_prior(self):
self.assertEqual(p([10, 10]), m)
self.assertEqual(p([5, 20]), m)

w = -np.log(np.product(upper - lower))
w = -np.log(np.prod(upper - lower))
self.assertEqual(p([1, 2]), w)
self.assertEqual(p([1, 5]), w)
self.assertEqual(p([1, 20 - 1e-14]), w)
Expand Down Expand Up @@ -1110,7 +1110,7 @@ def test_uniform_prior(self):
self.assertEqual(p([10, 10]), m)
self.assertEqual(p([5, 20]), m)

w = -np.log(np.product(upper - lower))
w = -np.log(np.prod(upper - lower))
self.assertEqual(p([1, 2]), w)
self.assertEqual(p([1, 5]), w)
self.assertEqual(p([1, 20 - 1e-14]), w)
Expand Down

0 comments on commit b07f75e

Please sign in to comment.