Skip to content

Commit 8e6e08b

Browse files
authored
Merge pull request #26 from EarthyScience/dev
Restructuring usage based on first tutorials
2 parents d8e8c14 + 3ec76da commit 8e6e08b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3602
-576
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ tmp/
1010
**/tmp.svg
1111
dev/intermediate/*
1212
dev/tmp.pdf
13+
docs/src/**/*_files/libs
14+
docs/src/**/*.html
15+
docs/src/**/*.ipynb
16+
docs/src/**/*Manifest.toml

README.md

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,76 @@
1-
# HybridVariationalInference
1+
# HybridVariationalInference HVI
22

33
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://EarthyScience.github.io/HybridVariationalInference.jl/stable/)
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://EarthyScience.github.io/HybridVariationalInference.jl/dev/)
55
[![Build Status](https://github.com/EarthyScience/HybridVariationalInference.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/EarthyScience/HybridVariationalInference.jl/actions/workflows/CI.yml?query=branch%3Amain)
66
[![Coverage](https://codecov.io/gh/EarthyScience/HybridVariationalInference.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/EarthyScience/HybridVariationalInference.jl)
77
[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
88

9-
Extending Variational Inference (VI), an approximate bayesian inversion method,
10-
to hybrid models, i.e. models that combine mechanistic and machine-learning parts.
9+
Estimating uncertainty in hybrid models,
10+
i.e. models that combine mechanistic and machine-learning parts,
11+
by extending Variational Inference (VI), an approximate bayesian inversion method.
12+
13+
## Problem
14+
15+
Consider the case of Parameter learning, a special case of hybrid models,
16+
where a machine learning model, $g_{\phi_g}$, uses known covariates $x_{Mi}$ at site $i$,
17+
to predict a subset of the parameters, $\theta$ of the process based model, $f$.
18+
19+
The analyst is interested in both,
20+
- the uncertainty of hybrid model predictions, $ŷ$ (predictive posterior), and
21+
- the uncertainty of process-model parameters $\theta$, including their correlations
22+
(posterior)
23+
24+
For example consider a soil organic matter process-model that predicts carbon stocks for
25+
different sites. We need to parameterize the unknown carbon use efficiency (CUE) of the soil
26+
microbial community that differs by site, but is hypothesized to correlate with climate variables
27+
and pedogenic factors, such as clay content.
28+
We apply a machine learning model to estimate CUE and fit it end-to-end with other
29+
parameters of the process-model to observed carbon stocks.
30+
In addition to the predicted CUE, we are interested in the uncertainty of CUE and its correlation
31+
with other parameters.
32+
We are interested in the entire posterior probability distribution of the model parameters.
33+
34+
To understand the background of HVI, refer to the [documentation]((https://EarthyScience.github.io/HybridVariationalInference.jl/dev/)).
35+
36+
## Usage
37+
![image info](./docs/src/hybrid_variational_setup.png)
38+
39+
In order to apply HVI, the user has to construct a `HybridProblem` object by specifying
40+
- the machine learning model, $g$
41+
- covariates $X_{Mi}$ for each site, $i$
42+
- the names of parameters that differs across sites, $\theta_M$, and global parameters
43+
that are the same across sites, $\theta_P$
44+
- optionally, sub-blocks in the within-site correlation structure of the parameters
45+
- optionally, which global parameters should be provided to $g$ as additional covariates,
46+
to account for correlations between global and site parameters
47+
- the parameter transformations from unconstrained scale to the scale relevant to the process models, $\theta = T(\zeta)$, e.g. for strictly positive parameters specify `exp`.
48+
- the process-model, $f$
49+
- drivers of the process-model $X_{Pi}$ at each site, $i$
50+
- the likelihood function of the observations, given the model predictions, $p(y|ŷ, \theta)$
51+
52+
Next this problem is passed to a `HybridPosteriorSolver` that fits an approximation
53+
of the posterior. It returns a NamedTuple of
54+
- `ϕ`: the fitted parameters, a ComponentVector with components
55+
- the machine learning model parameters (usually weights), $\phi_g$
56+
- means of the global parameters, $\phi_P = \mu_{\zeta_P}$ at transformed
57+
unconstrained scale
58+
- additional parameters, $\phi_{unc}$ of the posterior, $q(\zeta)$, such as
59+
coefficients that describe the scaling of variance with magnitude
60+
and coefficients that parameterize the choleski-factor or the correlation matrix.
61+
- `θP`: predicted means of the global parameters, $\theta_P$
62+
- `resopt`: the original result object of the optimizer (useful for debugging)
63+
64+
TODO to get
65+
- means of the site parameters for each site
66+
- samples of posterior
67+
- samples of predictive posterior
68+
## Example
69+
TODO
70+
71+
see test/test_HybridProblem.jl
72+
73+
74+
1175

12-
The model inversion, infers parametric approximations of posterior density
13-
of model parameters, by comparing model outputs to uncertain observations. At
14-
the same time, a machine learning model is fit that predicts parameters of these
15-
approximations by covariates.
1676

dev/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
[deps]
2+
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
23
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
34
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
5+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
6+
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
47
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
8+
ColorBrewer = "a2cac450-b92f-5266-8821-25eda20663c8"
59
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
610
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
711
DistributionFits = "45214091-1ed4-4409-9bcf-fdb48a05e921"
812
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
13+
FigureHelpers = "9ae22f58-2487-4805-bfc5-386577db46c8"
914
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
1015
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1116
HybridVariationalInference = "a108c475-a4e2-4021-9a84-cfa7df242f64"
1217
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
18+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1319
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
1420
MLDataDevices = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
1521
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"

0 commit comments

Comments
 (0)