@@ -46,11 +46,11 @@ An ensemble of `inputs` and their corresponding `outputs` from the forward model
46
46
47
47
$(DocStringExtensions. FIELDS)
48
48
"""
49
- struct Ensemble{T ,O}
49
+ struct Ensemble{I ,O}
50
50
"""
51
51
A matrix of inputs: each column corresponds to a vector of ``θ``s
52
52
"""
53
- inputs:: Matrix{T }
53
+ inputs:: Vector{I }
54
54
"""
55
55
Result of forward model for each column of `inputs`.
56
56
"""
63
63
Peform an iteration of NEKI, returning a new `Ensemble` object.
64
64
"""
65
65
function neki_iter (prob:: SolusProblem , ens:: Ensemble )
66
- covθ = cov (ens. inputs; dims = 2 )
66
+ covθ = cov (ens. inputs)
67
67
covθ += (tr (covθ)* 1e-15 )I
68
68
69
69
m = mean (ens. outputs)
70
- CG = [dot (u- prob. obs, v- m, prob. space) for u in ens. outputs, v in ens. outputs] # compute mean-field matrix
71
-
72
- Δt = 0.1 / norm (CG)
73
- implicit = lu ( I + 1 * Δt .* covθ * cov (prob. prior)) # todo: incorporate means
74
- rhsv = ens. inputs* CG
75
- rhs = ens. inputs - rhsv* Δt
76
70
77
- inputs = (implicit \ rhs) + rand (MvNormal (Δt .* covθ), size (ens. inputs, 2 ))
78
- outputs = [prob. forwardmodel (θ) for θ in eachslice (ens. inputs,dims= 2 )]
71
+ CG = [dot (Gθk - m, Gθj - prob. obs, prob. space) for Gθj in ens. outputs, Gθk in ens. outputs]
72
+
73
+ Δt = 0.1 / norm (CG) # use better constants
74
+ implicit = lu ( I + Δt .* (covθ / cov (prob. prior)) ) # todo: incorporate means
75
+ noise = MvNormal (covθ)
76
+
77
+ inputs = map (enumerate (ens. inputs)) do (j, θj)
78
+ X = sum (enumerate (ens. inputs)) do (k, θk)
79
+ CG[k,j]* θk
80
+ end
81
+ rhs = θj .- Δt .* X
82
+ (implicit \ rhs) .+ sqrt (Δt)* rand (noise)
83
+ end
84
+
85
+ outputs = map (prob. forwardmodel, inputs)
79
86
Ensemble (inputs, outputs)
80
87
end
81
88
0 commit comments