Skip to content

Commit 34e9b31

Browse files
authored
Merge pull request #1723 from pints-team/1406-1407-code
Code updates
2 parents 5873cd8 + 9221e3d commit 34e9b31

71 files changed

Lines changed: 300 additions & 345 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pints/_abc/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ class ABCSampler(pints.Loggable, pints.TunableMethod):
1616
:class:`pints.TunableMethod` interfaces.
1717
"""
1818

19+
@classmethod
1920
def name(self):
20-
"""
21-
Returns this method's full name.
22-
"""
21+
""" Returns this method's full name. """
2322
raise NotImplementedError
2423

2524
def ask(self):

pints/_abc/_abc_rejection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, log_prior):
4646
self._xs = None
4747
self._ready_for_tell = False
4848

49+
@classmethod
4950
def name(self):
5051
""" See :meth:`pints.ABCSampler.name()`. """
5152
return 'Rejection ABC'

pints/_abc/_abc_smc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(self, log_prior, perturbation_kernel=None,
106106
raise ValueError('Provided perturbation kernel must be an instance'
107107
' of pints.LogPrior')
108108

109+
@classmethod
109110
def name(self):
110111
""" See :meth:`pints.ABCSampler.name()`. """
111112
return 'ABC-SMC'

pints/_boundaries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class RectangularBoundaries(Boundaries):
129129
The corresponding upper boundaries
130130
"""
131131
def __init__(self, lower, upper):
132-
super(RectangularBoundaries, self).__init__()
132+
super().__init__()
133133

134134
# Convert to shape (n,) vectors, copy to ensure they remain unchanged
135135
self._lower = pints.vector(lower)
@@ -205,7 +205,7 @@ class LogPDFBoundaries(Boundaries):
205205
within bounds. Anything _above_ the threshold counts as within bounds.
206206
"""
207207
def __init__(self, log_pdf, threshold=-np.inf):
208-
super(LogPDFBoundaries, self).__init__()
208+
super().__init__()
209209

210210
# Check log pdf
211211
if not isinstance(log_pdf, pints.LogPDF):

pints/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ForwardModel(object):
2020
"""
2121

2222
def __init__(self):
23-
super(ForwardModel, self).__init__()
23+
super().__init__()
2424

2525
def n_parameters(self):
2626
"""
@@ -67,7 +67,7 @@ class ForwardModelS1(ForwardModel):
6767
"""
6868

6969
def __init__(self):
70-
super(ForwardModelS1, self).__init__()
70+
super().__init__()
7171

7272
def simulateS1(self, parameters, times):
7373
"""

pints/_error_measures.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ProblemErrorMeasure(ErrorMeasure):
5454
:class:`multi-output<pints.MultiOutputProblem>` problems.
5555
"""
5656
def __init__(self, problem):
57-
super(ProblemErrorMeasure, self).__init__()
57+
super().__init__()
5858
self._problem = problem
5959
self._times = problem.times()
6060
self._values = problem.values()
@@ -96,7 +96,7 @@ class MeanSquaredError(ProblemErrorMeasure):
9696
9797
"""
9898
def __init__(self, problem, weights=None):
99-
super(MeanSquaredError, self).__init__(problem)
99+
super().__init__(problem)
100100
self._ninv = 1.0 / np.prod(self._values.shape)
101101

102102
if weights is None:
@@ -147,7 +147,7 @@ class NormalisedRootMeanSquaredError(ProblemErrorMeasure):
147147
A :class:`pints.SingleOutputProblem`.
148148
"""
149149
def __init__(self, problem):
150-
super(NormalisedRootMeanSquaredError, self).__init__(problem)
150+
super().__init__(problem)
151151

152152
if not isinstance(problem, pints.SingleOutputProblem):
153153
raise ValueError(
@@ -174,7 +174,7 @@ class ProbabilityBasedError(ErrorMeasure):
174174
The LogPDF to base this error on.
175175
"""
176176
def __init__(self, log_pdf):
177-
super(ProbabilityBasedError, self).__init__()
177+
super().__init__()
178178
if not isinstance(log_pdf, pints.LogPDF):
179179
raise ValueError(
180180
'Given log_pdf must be an instance of pints.LogPDF.')
@@ -216,7 +216,7 @@ class RootMeanSquaredError(ProblemErrorMeasure):
216216
A :class:`pints.SingleOutputProblem`.
217217
"""
218218
def __init__(self, problem):
219-
super(RootMeanSquaredError, self).__init__(problem)
219+
super().__init__(problem)
220220

221221
if not isinstance(problem, pints.SingleOutputProblem):
222222
raise ValueError(
@@ -271,7 +271,7 @@ class SumOfErrors(ErrorMeasure):
271271
272272
"""
273273
def __init__(self, error_measures, weights=None):
274-
super(SumOfErrors, self).__init__()
274+
super().__init__()
275275

276276
# Check input arguments
277277
if len(error_measures) < 1:
@@ -360,7 +360,7 @@ class SumOfSquaresError(ProblemErrorMeasure):
360360
361361
"""
362362
def __init__(self, problem, weights=None):
363-
super(SumOfSquaresError, self).__init__(problem)
363+
super().__init__(problem)
364364

365365
if weights is None:
366366
weights = [1] * self._n_outputs

pints/_evaluation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def __init__(
193193
max_tasks_per_worker=500,
194194
n_numpy_threads=1,
195195
args=None):
196-
super(ParallelEvaluator, self).__init__(function, args)
196+
super().__init__(function, args)
197197

198198
# Determine number of workers
199199
if n_workers is None:
@@ -437,7 +437,7 @@ class MultiSequentialEvaluator(Evaluator):
437437
``f(x, *args)``.
438438
"""
439439
def __init__(self, functions, args=None):
440-
super(MultiSequentialEvaluator, self).__init__(functions[0], args)
440+
super().__init__(functions[0], args)
441441

442442
# Check functions
443443
for function in functions:
@@ -473,7 +473,7 @@ class SequentialEvaluator(Evaluator):
473473
specified, ``f`` will be called as ``f(x, *args)``.
474474
"""
475475
def __init__(self, function, args=None):
476-
super(SequentialEvaluator, self).__init__(function, args)
476+
super().__init__(function, args)
477477

478478
def _evaluate(self, positions):
479479
scores = [0] * len(positions)
@@ -530,7 +530,7 @@ class _Worker(multiprocessing.Process):
530530
def __init__(
531531
self, function, args, tasks, results, max_tasks, max_threads,
532532
errors, error):
533-
super(_Worker, self).__init__()
533+
super().__init__()
534534
self.daemon = True
535535
self._function = function
536536
self._args = args

pints/_log_likelihoods.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class AR1LogLikelihood(pints.ProblemLogLikelihood):
6969
"""
7070

7171
def __init__(self, problem):
72-
super(AR1LogLikelihood, self).__init__(problem)
72+
super().__init__(problem)
7373

7474
# Get number of times, number of outputs
7575
self._nt = len(self._times) - 1
@@ -149,7 +149,7 @@ class ARMA11LogLikelihood(pints.ProblemLogLikelihood):
149149
"""
150150

151151
def __init__(self, problem):
152-
super(ARMA11LogLikelihood, self).__init__(problem)
152+
super().__init__(problem)
153153

154154
# Get number of times, number of outputs
155155
self._nt = len(self._times) - 2
@@ -205,7 +205,7 @@ class CauchyLogLikelihood(pints.ProblemLogLikelihood):
205205
"""
206206

207207
def __init__(self, problem):
208-
super(CauchyLogLikelihood, self).__init__(problem)
208+
super().__init__(problem)
209209

210210
# Get number of times, number of outputs
211211
self._nt = len(self._times)
@@ -326,7 +326,7 @@ class CensoredGaussianLogLikelihood(pints.ProblemLogLikelihood):
326326
"""
327327

328328
def __init__(self, problem, lower=None, upper=None):
329-
super(CensoredGaussianLogLikelihood, self).__init__(problem)
329+
super().__init__(problem)
330330

331331
# Get number of times, number of outputs
332332
self._nt = len(self._times)
@@ -617,8 +617,7 @@ class ConstantAndMultiplicativeGaussianLogLikelihood(
617617
"""
618618

619619
def __init__(self, problem):
620-
super(ConstantAndMultiplicativeGaussianLogLikelihood, self).__init__(
621-
problem)
620+
super().__init__(problem)
622621

623622
# Get number of times and number of noise parameters
624623
self._nt = len(self._times)
@@ -819,8 +818,7 @@ class GaussianIntegratedLogUniformLogLikelihood(pints.ProblemLogLikelihood):
819818
"""
820819

821820
def __init__(self, problem):
822-
super(GaussianIntegratedLogUniformLogLikelihood,
823-
self).__init__(problem)
821+
super().__init__(problem)
824822

825823
# Get number of times, number of outputs
826824
self._nt = len(self._times)
@@ -908,7 +906,7 @@ class GaussianIntegratedUniformLogLikelihood(pints.ProblemLogLikelihood):
908906
"""
909907

910908
def __init__(self, problem, lower, upper):
911-
super(GaussianIntegratedUniformLogLikelihood, self).__init__(problem)
909+
super().__init__(problem)
912910

913911
# Get number of times, number of outputs
914912
self._nt = len(self._times)
@@ -1012,7 +1010,7 @@ class GaussianKnownSigmaLogLikelihood(pints.ProblemLogLikelihood):
10121010
"""
10131011

10141012
def __init__(self, problem, sigma):
1015-
super(GaussianKnownSigmaLogLikelihood, self).__init__(problem)
1013+
super().__init__(problem)
10161014

10171015
# Store counts
10181016
self._no = problem.n_outputs()
@@ -1110,7 +1108,7 @@ class GaussianLogLikelihood(pints.ProblemLogLikelihood):
11101108
"""
11111109

11121110
def __init__(self, problem):
1113-
super(GaussianLogLikelihood, self).__init__(problem)
1111+
super().__init__(problem)
11141112

11151113
# Get number of times, number of outputs
11161114
self._nt = len(self._times)
@@ -1169,7 +1167,7 @@ def __init__(self, problem, sigma):
11691167
warnings.warn(
11701168
'The class `pints.KnownNoiseLogLikelihood` is deprecated.'
11711169
' Please use `pints.GaussianKnownSigmaLogLikelihood` instead.')
1172-
super(KnownNoiseLogLikelihood, self).__init__(problem, sigma)
1170+
super().__init__(problem, sigma)
11731171

11741172

11751173
class LogNormalLogLikelihood(pints.ProblemLogLikelihood):
@@ -1214,7 +1212,7 @@ class LogNormalLogLikelihood(pints.ProblemLogLikelihood):
12141212
"""
12151213

12161214
def __init__(self, problem, mean_adjust=False):
1217-
super(LogNormalLogLikelihood, self).__init__(problem)
1215+
super().__init__(problem)
12181216

12191217
# Get number of times, number of outputs
12201218
self._nt = len(self._times)
@@ -1352,7 +1350,7 @@ class MultiplicativeGaussianLogLikelihood(pints.ProblemLogLikelihood):
13521350
"""
13531351

13541352
def __init__(self, problem):
1355-
super(MultiplicativeGaussianLogLikelihood, self).__init__(problem)
1353+
super().__init__(problem)
13561354

13571355
# Get number of times and number of outputs
13581356
self._nt = len(self._times)
@@ -1411,13 +1409,11 @@ def __init__(self, log_likelihood):
14111409
if not isinstance(log_likelihood, pints.ProblemLogLikelihood):
14121410
raise ValueError(
14131411
'Given log_likelihood must extend pints.ProblemLogLikelihood')
1414-
1415-
# Call parent constructor
1416-
super(ScaledLogLikelihood, self).__init__(log_likelihood._problem)
1417-
1418-
# Store log-likelihood
14191412
self._log_likelihood = log_likelihood
14201413

1414+
# Call this only after checking log_likelihood type
1415+
super().__init__(log_likelihood._problem)
1416+
14211417
# Pre-calculate parts
14221418
self._f = 1.0 / np.prod(self._values.shape)
14231419

@@ -1465,7 +1461,7 @@ class StudentTLogLikelihood(pints.ProblemLogLikelihood):
14651461
"""
14661462

14671463
def __init__(self, problem):
1468-
super(StudentTLogLikelihood, self).__init__(problem)
1464+
super().__init__(problem)
14691465

14701466
# Get number of times, number of outputs
14711467
self._nt = len(self._times)
@@ -1515,4 +1511,5 @@ def __init__(self, problem):
15151511
warnings.warn(
15161512
'The class `pints.UnknownNoiseLogLikelihood` is deprecated.'
15171513
' Please use `pints.GaussianLogLikelihood` instead.')
1518-
super(UnknownNoiseLogLikelihood, self).__init__(problem)
1514+
super().__init__(problem)
1515+

pints/_log_pdfs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class PooledLogPDF(LogPDF):
182182
pooled=[False, True])
183183
"""
184184
def __init__(self, log_pdfs, pooled):
185-
super(PooledLogPDF, self).__init__()
185+
super().__init__()
186186

187187
# Check input arguments
188188
if len(log_pdfs) < 2:
@@ -329,7 +329,7 @@ class ProblemLogLikelihood(LogPDF):
329329
330330
"""
331331
def __init__(self, problem):
332-
super(ProblemLogLikelihood, self).__init__()
332+
super().__init__()
333333
self._problem = problem
334334
# Cache some problem variables
335335
self._values = problem.values()
@@ -364,7 +364,7 @@ class LogPosterior(LogPDF):
364364
space.
365365
"""
366366
def __init__(self, log_likelihood, log_prior):
367-
super(LogPosterior, self).__init__()
367+
super().__init__()
368368

369369
# Check arguments
370370
if not isinstance(log_prior, LogPrior):
@@ -453,7 +453,7 @@ class SumOfIndependentLogPDFs(LogPDF):
453453
])
454454
"""
455455
def __init__(self, log_likelihoods):
456-
super(SumOfIndependentLogPDFs, self).__init__()
456+
super().__init__()
457457

458458
# Check input arguments
459459
if len(log_likelihoods) < 2:

pints/_log_priors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def __init__(self, mean, standard_deviation):
10531053
warnings.warn(
10541054
'The class `pints.NormalLogPrior` is deprecated.'
10551055
' Please use `pints.GaussianLogPrior` instead.')
1056-
super(NormalLogPrior, self).__init__(mean, standard_deviation)
1056+
super().__init__(mean, standard_deviation)
10571057

10581058

10591059
class StudentTLogPrior(pints.LogPrior):

0 commit comments

Comments
 (0)