Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pints/_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def effective_sample_size_single_parameter(x):
rho = autocorrelation(x)
T = _autocorrelate_negative(rho)
n = len(x)
ess = n / (1 + 2 * np.sum(rho[0:T]))
ess = n / (1 + 2 * np.sum(rho[1:T]))
return ess


Expand Down
14 changes: 10 additions & 4 deletions pints/tests/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ def test_effective_sample_size_single_parameter(self):
# For case with negative elements in x
x = np.array([1, 2, 3, 4, -1, -1])
y = pints._diagnostics.effective_sample_size_single_parameter(x)
self.assertAlmostEqual(y, 1.75076, 5)
self.assertAlmostEqual(y, 4.20437956, 5)

# Case with positive elements only in x
x = np.array([1, 2, 3, 4, 1, 1])
self.assertAlmostEqual(
pints._diagnostics.effective_sample_size_single_parameter(x),
1.846154, 6)
4.8, 6)

# IID normal draws: ESS should be approximately equal to sample size n
rng = np.random.default_rng(0)
x_iid = rng.normal(size=20000)
ess_iid = pints._diagnostics.effective_sample_size_single_parameter(x_iid)
self.assertAlmostEqual(ess_iid / 20000, 1.0, delta=0.05)

def test_effective_sample_size(self):
# Tests ess for a matrix of parameters
Expand All @@ -59,8 +65,8 @@ def test_effective_sample_size(self):
x = np.transpose(np.array([[1.0, 1.1, 1.4, 1.3, 1.3],
[1.0, 2.0, 3.0, 4.0, 5.0]]))
y = pints._diagnostics.effective_sample_size(x)
self.assertAlmostEqual(y[0], 1.439232, 6)
self.assertAlmostEqual(y[1], 1.315789, 6)
self.assertAlmostEqual(y[0], 3.391959798994974, 6)
self.assertAlmostEqual(y[1], 2.7777777777777777, 6)

# Bad calls
self.assertRaisesRegex(
Expand Down