Skip to content

Commit 98831cd

Browse files
committed
docu strings of Lux
1 parent 53dc257 commit 98831cd

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ docs/src/**/*_files/libs
1414
docs/src/**/*.html
1515
docs/src/**/*.ipynb
1616
docs/src/**/*Manifest.toml
17+
docs/src_stash/*.ipynb

ext/HybridVariationalInferenceLuxExt.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ using Random
77
using StatsFuns: logistic
88

99

10-
10+
# AbstractModelApplicator that stores a Lux.StatefulLuxLayer, so that
11+
# it can be applied with given inputs and parameters
12+
# The `int_ϕ` ComponentArrayInterpreter, attaches the correct axes to the
13+
# supplied parameters, that do not need to keep the Axis information
1114
struct LuxApplicator{MT, IT} <: AbstractModelApplicator
1215
stateful_layer::MT
1316
int_ϕ::IT
@@ -24,7 +27,7 @@ function HVI.construct_ChainsApplicator(rng::AbstractRNG, m::Chain, float_type=F
2427
end
2528

2629
function HVI.apply_model(app::LuxApplicator, x, ϕ)
27-
ϕc = app.int_ϕ(ϕ)
30+
ϕc = app.int_ϕ(CA.getdata(ϕ))
2831
app.stateful_layer(x, ϕc)
2932
end
3033

src/HybridSolver.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function CommonSolve.solve(prob::AbstractHybridProblem, solver::HybridPointSolve
5454
# Zygote.gradient(ϕ0_dev -> loss_gf(ϕ0_dev, data1...)[1], ϕ0_dev)
5555
optf = Optimization.OptimizationFunction((ϕ, data) -> loss_gf(ϕ, data...)[1],
5656
Optimization.AutoZygote())
57+
# use CA.getdata(ϕ0_dev), i.e. the plain vector to avoid recompiling for specific CA
58+
# loss_gf re-attaches the axes
5759
optprob = OptimizationProblem(optf, CA.getdata(ϕ0_dev), train_loader_dev)
5860
res = Optimization.solve(optprob, solver.alg; kwargs...)
5961
ϕ = intϕ(res.u)

src/ModelApplicator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ a tuple with two components:
1111
- The applicator
1212
- a sample parameter vector (type depends on the used ML-framework)
1313
14-
Implemented are
15-
- `construct_SimpleChainsApplicator`
16-
- `construct_FluxApplicator`
17-
- `construct_LuxApplicator`
14+
Implemented overloads of `construct_ChainsApplicator` for layers of
15+
- `SimpleChains.SimpleChain`
16+
- `Flux.Chain`
17+
- `Lux.Chain`
1818
"""
1919
abstract type AbstractModelApplicator end
2020

src/gf.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ Create a loss function for given
138138
- transM: transforamtion of parameters at unconstrained space
139139
- f(θMs, θP): mechanistic model
140140
- intϕ: interpreter attaching axis with components ϕg and ϕP
141-
- intP: interpreter attaching axis to ζP = ϕP with components used by f
142-
- kwargs: additional keyword arguments passed to gf, such as gdev or pbm_covars
141+
- intP: interpreter attaching axis to ζP = ϕP with components used by f,
142+
The default, uses `intϕ(ϕ)` as a template
143+
- kwargs: additional keyword arguments passed to `gf`, such as `gdev` or `pbm_covars`
143144
144145
The loss function `loss_gf(ϕ, xM, xP, y_o, y_unc, i_sites)` takes
145146
- parameter vector ϕ
146147
- xM: matrix of covariate, sites in the batch are in columns
147148
- xP: iteration of drivers for each site
148149
- y_o: matrix of observations, sites in columns
149150
- y_unc: vector of uncertainty information for each observation
151+
Currently, hardcoes squared error loss of `(y_pred .- y_o) ./ σ`,
152+
with `σ = exp.(y_unc ./ 2)`.
150153
- i_sites: index of sites in the batch
151154
152155
and returns a NamedTuple of

0 commit comments

Comments
 (0)