1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Integrated Nested Laplace Approximation (INLA) for latent Gaussian models
//!
//! INLA is a fast approximate Bayesian inference method for latent Gaussian
//! models (LGMs). Instead of MCMC sampling, INLA uses deterministic
//! approximations (Laplace and numerical integration) to compute
//! posterior marginals.
//!
//! # Model class
//!
//! INLA targets models of the form:
//! - **Observations**: y_i | x, θ ~ p(y_i | η_i, θ) (conditionally independent)
//! - **Latent field**: x | θ ~ N(0, Q(θ)^{-1}) (Gaussian Markov Random Field)
//! - **Linear predictor**: η = A × x
//! - **Hyperparameters**: θ ~ p(θ)
//!
//! # Usage
//!
//! ```rust,no_run
//! use scirs2_stats::inla::{
//! LatentGaussianModel, INLAConfig, LikelihoodFamily,
//! compute_marginals,
//! };
//! use scirs2_core::ndarray::{array, Array2};
//!
//! let y = array![1.0, 2.0, 3.0];
//! let design = Array2::eye(3);
//! let precision = Array2::eye(3);
//!
//! let model = LatentGaussianModel::new(
//! y, design, precision,
//! LikelihoodFamily::Gaussian,
//! ).with_observation_precision(1.0);
//!
//! let config = INLAConfig {
//! n_hyperparameter_grid: 10,
//! hyperparameter_range: Some((-1.0, 1.0)),
//! ..INLAConfig::default()
//! };
//!
//! let result = compute_marginals(&model, &config).expect("INLA failed");
//! println!("Posterior means: {:?}", result.marginal_means);
//! println!("Posterior variances: {:?}", result.marginal_variances);
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use INLAModelBuilder;
pub use ;