Skip to content

Commit

Permalink
Merge pull request #76 from ACEsuit/blr_committee_warning
Browse files Browse the repository at this point in the history
exception for committees without SVD.
  • Loading branch information
wcwitt authored Mar 27, 2024
2 parents d38a436 + cb92321 commit 6c3a892
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/bayesianlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Perform Bayesian linear regression, possibly with automatic relevance determinat
### output settings
- `verbose::Bool = true`
- `committee_size::Int = 0`: if nonzero, sample from the posterior and include a committee in the results.
- `committee_size::Int = 0`: if nonzero, sample from the posterior and include a committee in the results (presently, `factorization = :svd` required for committees)
- `ret_covar::Bool = false`: whether to supply the covariance matrix in the results.
### solver settings
Expand All @@ -203,6 +203,11 @@ function bayesian_linear_regression(A, Y;
optimizer = :LBFGS,
tol::AbstractFloat = 1e-3,
max_iter::Int = 1000)

if (committee_size>0 && factorization != :svd)
error("At present, only the SVD factorization can produce committees.")
end

if (ard_threshold == 0.0) && (factorization == :cholesky)
return bayesian_fit(A, Y;
variance_c_floor = sig_0_floor * sig_0_floor,
Expand Down
4 changes: 4 additions & 0 deletions test/test_bayesianlinear.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ACEfit
using ACEfit.BayesianLinear
using LinearAlgebra
using Test

Expand All @@ -23,3 +24,6 @@ for n in 1:committee_size
end
covar_approx .= covar_approx / committee_size
@test maximum(abs.(covar_approx - covar)) < 0.01

@info("Test error from invalid committee request.")
@test_throws ErrorException("At present, only the SVD factorization can produce committees.") BayesianLinear.bayesian_linear_regression(X, Y; committee_size=committee_size, factorization=:cholesky)

0 comments on commit 6c3a892

Please sign in to comment.