Skip to content

Commit

Permalink
Changed SBR test to also test for coefficient values
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelbue committed Feb 12, 2024
1 parent b2579bb commit a13ce82
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/test_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,18 @@ def test_sbr_bad_parameters(params):
SBR(**params)


def test_sbr_fit(data_lorenz):
x, t = data_lorenz
opt = SBR(num_warmup=10, num_samples=10)
sindy = SINDy(optimizer=opt).fit(x=x, t=t)
assert hasattr(sindy.optimizer, "mcmc_")

def test_sbr_accurate():
# It's really hard to tune SBR to get desired shrinkage
# This just tests that SBR fits "close" to unregularized regression
x = np.tile(np.eye(2), 4).reshape((-1, 2))
y = np.tile([[1], [1e-1]], 4).reshape((-1, 1))
opt = SBR(num_warmup=50, num_samples=50).fit(x, y)
result = opt.coef_
unregularized = np.array([[1, 1e-1]])
np.testing.assert_allclose(result, unregularized, atol=1e-3)
assert hasattr(opt, "mcmc_")
expected_names = ["beta", "c_sq", "lambda", "sigma", "tau"]
result_names = sindy.optimizer.mcmc_.get_samples().keys()
result_names = opt.mcmc_.get_samples().keys()
assert all(expected in result_names for expected in expected_names)


Expand Down

0 comments on commit a13ce82

Please sign in to comment.