Skip to content

Commit e52206e

Browse files
committed
simplify init_hybrid_paramrs
1 parent 948c892 commit e52206e

4 files changed

Lines changed: 13 additions & 31 deletions

File tree

src/HybridSolver.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ function CommonSolve.solve(prob::AbstractHybridProblem, solver::HybridPosteriorS
193193
n_site, n_batch = get_hybridproblem_n_site_and_batch(prob; scenario)
194194
hpints = HybridProblemInterpreters(prob; scenario)
195195
ϕq = get_hybridproblem_ϕq(prob; scenario)
196-
(; ϕ, transPMs_batch, interpreters, get_transPMs, get_ca_int_PMs) = init_hybrid_params(
197-
get_hybridproblem_θP(prob; scenario), pt.θM, cor_ends, ϕg0, hpints;
198-
transP, transM, ϕunc0 = ϕq)
196+
(; ϕ, interpreters) = init_hybrid_params(ϕg0, ϕq)
199197
int_ϕq = interpreters.ϕq
200198
int_ϕg_ϕq = interpreters.ϕg_ϕq
201199
transMs = StackedArray(transM, n_batch)
@@ -233,7 +231,7 @@ function CommonSolve.solve(prob::AbstractHybridProblem, solver::HybridPosteriorS
233231

234232
priors_θP_mean, priors_θMs_mean = construct_priors_θ_mean(
235233
prob, ϕ0_dev.ϕg, keys(pt.θM), pt.θP, θmean_quant, g_dev, transM, transP;
236-
scenario, get_ca_int_PMs, gdevs, pbm_covars)
234+
scenario, gdevs, pbm_covars)
237235

238236
loss_elbo = get_loss_elbo(
239237
g_dev, transP, transMs, f_dev, py;
@@ -349,8 +347,7 @@ function compute_elbo_components(
349347
g, ϕg0 = get_hybridproblem_MLapplicator(prob; scenario)
350348
ϕq = get_hybridproblem_ϕq(prob; scenario)
351349
(; transP, transM) = get_hybridproblem_transforms(prob; scenario)
352-
(; ϕ, transPMs_batch, interpreters, get_transPMs, get_ca_int_PMs) = init_hybrid_params(
353-
θP, θM, cor_ends, ϕg0, n_batch; transP, transM, ϕunc0 = ϕq)
350+
(; ϕ, interpreters) = init_hybrid_params(ϕg0, ϕq)
354351
if gdev isa MLDataDevices.AbstractGPUDevice
355352
ϕ0_dev = gdev(ϕ)
356353
g_dev = gdev(g) # zygote fails if gdev is a CPUDevice, although should be non-op
@@ -371,7 +368,7 @@ function compute_elbo_components(
371368
py = get_hybridproblem_neg_logden_obs(prob; scenario)
372369
priors_θ_mean = construct_priors_θ_mean(
373370
prob, ϕ0_dev.ϕg, keys(θM), θP, θmean_quant, g_dev, transM;
374-
scenario, get_ca_int_PMs, gdev, cdev, pbm_covars)
371+
scenario, gdev, cdev, pbm_covars)
375372
neg_elbo_gtf_components(
376373
rng, ϕ0_dev, g_dev, transPMs_batch, f, py, xM, xP, y_o, y_unc, i_sites, interpreters;
377374
solver.n_MC, solver.n_MC_cap, cor_ends, priors_θ_mean)
@@ -382,7 +379,7 @@ In order to let mean of θ stay close to initial point parameter estimates
382379
construct a prior on mean θ to a Normal around initial prediction.
383380
"""
384381
function construct_priors_θ_mean(prob, ϕg, keysθM, θP, θmean_quant, g_dev, transM, transP;
385-
scenario::Val{scen}, get_ca_int_PMs, gdevs, pbm_covars,
382+
scenario::Val{scen}, gdevs, pbm_covars,
386383
) where {scen}
387384
iszero(θmean_quant) ? ([],[]) :
388385
begin

src/elbo.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ function sample_posterior(rng, prob::AbstractHybridProblem, xM::AbstractMatrix;
392392
pbm_covar_indices = get_pbm_covar_indices(par_templates.θP, pbm_covars)
393393
hpints = HybridProblemInterpreters(prob; scenario)
394394
# TODO remove par_templates from init_hybrid_params - might not get updated θP
395-
(; ϕ, transPMs_batch, interpreters, get_transPMs) = init_hybrid_params(
396-
get_hybridproblem_θP(prob; scenario), par_templates.θM, cor_ends, ϕg0, hpints;
397-
transP, transM, ϕunc0=ϕq)
395+
(; ϕ, interpreters) = init_hybrid_params(ϕg0, ϕq)
398396
int_ϕg_ϕq = interpreters.ϕg_ϕq
399397
int_ϕq = interpreters.ϕq
400398
transMs = StackedArray(transM, n_batch)

src/init_hybrid_params.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,14 @@ Returns a NamedTuple of
2222
because this direction is used much more often.
2323
- `ϕunc0` initial uncertainty parameters, ComponentVector with format of `init_hybrid_ϕunc.`
2424
"""
25-
function init_hybrid_params(θP::AbstractVector{FT}, θM::AbstractVector{FT},
26-
cor_ends::NamedTuple, ϕg::AbstractVector{FT}, hpints::HybridProblemInterpreters;
27-
transP = elementwise(identity), transM = elementwise(identity),
28-
ϕunc0 = init_hybrid_ϕunc(cor_ends, zero(FT))) where {FT}
29-
ϕq = ϕunc0
30-
n_ϕg = length(ϕg)
25+
function init_hybrid_params(ϕg::AbstractVector{FT}, ϕq::AbstractVector{FT}) where {FT}
3126
ϕ = CA.ComponentVector(; ϕg, ϕq)
3227
interpreters = map(get_concrete,
3328
(;
3429
ϕg_ϕq = ComponentArrayInterpreter(ϕ),
35-
PMs = get_int_PMst_batch(hpints),
3630
ϕq = ComponentArrayInterpreter(ϕq)
3731
))
38-
get_transPMs = transPMs_batch = Val(Symbol("deprecated , use stack_ca_int(intPMs)"))
39-
get_ca_int_PMs = Val(Symbol("deprecated , use get_int_PMst_site(HybridProblemInterpreters(prob; scenario))"))
40-
(; ϕ, transPMs_batch, interpreters, get_transPMs, get_ca_int_PMs)
32+
(; ϕ, interpreters)
4133
end
4234

4335
function init_hybrid_params_old(θP::AbstractVector{FT}, θM::AbstractVector{FT},

test/test_elbo.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,14 @@ test_scenario = (scenario) -> begin
7474
ϕq0 = init_hybrid_ϕq(par_templates.θP, par_templates.θM, transP, cor_ends)
7575
# ϕunc0 = init_hybrid_ϕunc(cor_ends, zero(FT))
7676
# ϕq0 = CP.update_μP_by_θP(ϕunc0, θP_true, transP)
77-
hpints = HybridProblemInterpreters(probc; scenario)
78-
(; ϕ, transPMs_batch, interpreters, get_transPMs, get_ca_int_PMs) = init_hybrid_params(
79-
θP_true, θMs_true[:, 1], cor_ends, ϕg0, hpints; transP, transM, ϕunc0 = ϕq0)
77+
(; ϕ, interpreters) = init_hybrid_params(ϕg0, ϕq0)
8078
int_ϕq = interpreters.ϕq
8179
int_ϕg_ϕq = interpreters.ϕg_ϕq
82-
83-
# @descend_code_warntype init_hybrid_params(θP_true, θMs_true[:, 1], cor_ends, ϕg0, n_batch; transP, transM)
84-
# @descend_code_warntype CA.ComponentVector(nt)
8580
ϕ_ini = ϕ
86-
transform_tools = nothing # TODO remove
87-
# transform_tools = @inferred CP.setup_transform_ζ(
88-
# transP, transM, get_int_PMst_batch(hpints))
89-
int_PMs = get_int_PMst_batch(hpints)
81+
# transform_tools = nothing # TODO remove
82+
# # transform_tools = @inferred CP.setup_transform_ζ(
83+
# # transP, transM, get_int_PMst_batch(hpints))
84+
# int_PMs = get_int_PMst_batch(hpints)
9085

9186
if ggdev isa MLDataDevices.AbstractGPUDevice
9287
scenario_flux = Val((CP._val_value(scenario)..., :use_Flux, :use_gpu))

0 commit comments

Comments
 (0)