Skip to content

Commit 7c86fca

Browse files
committed
rhat now checks that there are two chains. Fixes #533.
1 parent 46c1ae6 commit 7c86fca

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

pints/_diagnostics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ def rhat(chains, warm_up=0.0):
210210
' [0,1].')
211211
if chains.shape[0] < 2:
212212
raise ValueError('Number of chains needs to be 2 or higher')
213-
if chains.shape[1] < 1:
214-
raise ValueError(
215-
'Number of samples per chain after warm-up and chain splitting is '
216-
f'{n}. Method needs at least 1 sample per chain.')
217213

218214
# Get number of samples
219215
n = chains.shape[1]
216+
if n < 2:
217+
raise ValueError(
218+
'Number of samples per chain after warm-up and chain splitting is '
219+
f'{n}. Method needs at least 2 samples per chain.')
220+
220221

221222
# Exclude warm-up
222223
chains = chains[:, int(n * warm_up):]

pints/tests/test_diagnostics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ def test_bad_rhat_inputs(self):
137137

138138
# Pass only a single chain
139139
chains = np.empty(shape=(1, 5))
140-
self.assertRaisesRegex(ValueError, '2 or higher', pints.rhat, chains)
140+
self.assertRaisesRegex(
141+
ValueError, '2 or higher', pints.rhat, chains)
142+
143+
# Pass only a single sample
144+
chains = np.empty(shape=(5, 1))
145+
self.assertRaisesRegex(
146+
ValueError, 'at least 2 samples', pints.rhat, chains)
141147

142148
# Pass bad warm-up arguments
143149
chains = np.empty(shape=(2, 4))

0 commit comments

Comments
 (0)