Skip to content

Add default regularization #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions src/ensemble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ dataset on which the ensembler should be trained on.
This function currently assumes that `sol.t` matches the time points of all measurements
in `data_ensem`!
"""
function ensemble_weights(sol::EnsembleSolution, data_ensem)
function ensemble_weights(sol::EnsembleSolution, data_ensem; rank = Int(round(length(last(first(data_ensem).second))/2)))
obs = first.(data_ensem)
predictions = reduce(vcat, reduce(hcat,[sol[i][s] for i in 1:length(sol)]) for s in obs)
data = reduce(vcat, [data_ensem[i][2] isa Tuple ? data_ensem[i][2][2] : data_ensem[i][2] for i in 1:length(data_ensem)])
weights = predictions \ data
F = svd(data)
# Truncate SVD
U, S, V = F.U[:, 1:rank], F.S[1:rank], F.V[:, 1:rank]
weights = (((data*V)*Diagonal(1 ./ S)) * U')
end

function bayesian_ensemble(probs, ps, datas;
Expand All @@ -46,4 +49,4 @@ function bayesian_ensemble(probs, ps, datas;
@info "$(length(all_probs)) total models"

enprob = EnsembleProblem(all_probs)
end
end