Skip to content

Commit 884922a

Browse files
committed
format
1 parent f95d63c commit 884922a

File tree

8 files changed

+338
-259
lines changed

8 files changed

+338
-259
lines changed

docs/Manifest.toml

Lines changed: 273 additions & 221 deletions
Large diffs are not rendered by default.

examples/Cloudy/Cloudy_calibrate.jl

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ u_init = get_u_prior(ekiobj)
211211
anim_eki_unconst_cloudy = @animate for i in 1:(n_iter - 1)
212212
u_i = get_u(ekiobj, i)
213213

214-
p1 = Plots.plot(u_i[1, :], u_i[2, :], seriestype = :scatter, xlims = extrema(u_init[1, :]), ylims = extrema(u_init[2, :]))
214+
p1 = Plots.plot(
215+
u_i[1, :],
216+
u_i[2, :],
217+
seriestype = :scatter,
218+
xlims = extrema(u_init[1, :]),
219+
ylims = extrema(u_init[2, :]),
220+
)
215221
Plots.plot!(
216222
p1,
217223
[θ_true[1]],
@@ -226,7 +232,13 @@ anim_eki_unconst_cloudy = @animate for i in 1:(n_iter - 1)
226232
)
227233
Plots.plot!(p1, [θ_true[2]], seriestype = "hline", linestyle = :dash, linecolor = :red, label = "optimum")
228234

229-
p2 = Plots.plot(u_i[2, :], u_i[3, :], seriestype = :scatter, xlims = extrema(u_init[2, :]), ylims = extrema(u_init[3, :]))
235+
p2 = Plots.plot(
236+
u_i[2, :],
237+
u_i[3, :],
238+
seriestype = :scatter,
239+
xlims = extrema(u_init[2, :]),
240+
ylims = extrema(u_init[3, :]),
241+
)
230242
Plots.plot!(
231243
p2,
232244
[θ_true[2]],
@@ -242,7 +254,13 @@ anim_eki_unconst_cloudy = @animate for i in 1:(n_iter - 1)
242254

243255
Plots.plot!(p2, [θ_true[3]], seriestype = "hline", linestyle = :dash, linecolor = :red, label = "optimum")
244256

245-
p3 = Plots.plot(u_i[3, :], u_i[1, :], seriestype = :scatter, xlims = extrema(u_init[3, :]), ylims = extrema(u_init[1, :]))
257+
p3 = Plots.plot(
258+
u_i[3, :],
259+
u_i[1, :],
260+
seriestype = :scatter,
261+
xlims = extrema(u_init[3, :]),
262+
ylims = extrema(u_init[1, :]),
263+
)
246264
Plots.plot!(
247265
p3,
248266
[θ_true[3]],
@@ -268,7 +286,13 @@ gif(anim_eki_unconst_cloudy, joinpath(output_directory, "cloudy_eki_unconstr.gif
268286
anim_eki_cloudy = @animate for i in 1:(n_iter - 1)
269287
ϕ_i = get_ϕ(priors, ekiobj, i)
270288

271-
p1 = Plots.plot(ϕ_i[1, :], ϕ_i[2, :], seriestype = :scatter, xlims = extrema(ϕ_init[1, :]), ylims = extrema(ϕ_init[2, :]))
289+
p1 = Plots.plot(
290+
ϕ_i[1, :],
291+
ϕ_i[2, :],
292+
seriestype = :scatter,
293+
xlims = extrema(ϕ_init[1, :]),
294+
ylims = extrema(ϕ_init[2, :]),
295+
)
272296
Plots.plot!(
273297
p1,
274298
[ϕ_true[1]],
@@ -284,7 +308,13 @@ anim_eki_cloudy = @animate for i in 1:(n_iter - 1)
284308

285309
Plots.plot!(p1, [ϕ_true[2]], seriestype = "hline", linestyle = :dash, linecolor = :red, label = "optimum")
286310

287-
p2 = Plots.plot(ϕ_i[2, :], ϕ_i[3, :], seriestype = :scatter, xlims = extrema(ϕ_init[2, :]), ylims = extrema(ϕ_init[3, :]))
311+
p2 = Plots.plot(
312+
ϕ_i[2, :],
313+
ϕ_i[3, :],
314+
seriestype = :scatter,
315+
xlims = extrema(ϕ_init[2, :]),
316+
ylims = extrema(ϕ_init[3, :]),
317+
)
288318

289319
Plots.plot!(
290320
p2,
@@ -301,7 +331,13 @@ anim_eki_cloudy = @animate for i in 1:(n_iter - 1)
301331

302332
Plots.plot!(p2, [ϕ_true[3]], seriestype = "hline", linestyle = :dash, linecolor = :red, label = "optimum")
303333

304-
p3 = Plots.plot(ϕ_i[3, :], ϕ_i[1, :], seriestype = :scatter, xlims = extrema(ϕ_init[3, :]), ylims = extrema(ϕ_init[1, :]))
334+
p3 = Plots.plot(
335+
ϕ_i[3, :],
336+
ϕ_i[1, :],
337+
seriestype = :scatter,
338+
xlims = extrema(ϕ_init[3, :]),
339+
ylims = extrema(ϕ_init[1, :]),
340+
)
305341
Plots.plot!(
306342
p3,
307343
[ϕ_true[3]],

examples/Emulator/L63/emulate.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,7 @@ function main()
9696

9797

9898
# Emulate
99-
cases = [
100-
"GP",
101-
"RF-prior",
102-
"RF-lr-scalar",
103-
"rf-diag-scalar",
104-
"RF-lr-lr",
105-
"RF-nonsep",
106-
]
99+
cases = ["GP", "RF-prior", "RF-lr-scalar", "rf-diag-scalar", "RF-lr-lr", "RF-nonsep"]
107100

108101
case = cases[4] # 7
109102

examples/Lorenz/emulate_sample_spatial_dep.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function main()
2929
]
3030

3131
#### CHOOSE YOUR CASE:
32-
mask =[2] # e.g. 1:2 or [3]
32+
mask = [2] # e.g. 1:2 or [3]
3333
for (case) in cases[mask]
3434

3535

@@ -92,7 +92,7 @@ function main()
9292
"n_features_opt" => 160,
9393
)
9494
n_features = 200
95-
# kernel_structure = SeparableKernel(LowRankFactor(1,nugget), OneDimFactor())
95+
# kernel_structure = SeparableKernel(LowRankFactor(1,nugget), OneDimFactor())
9696
kernel_structure = SeparableKernel(DiagonalFactor(nugget), OneDimFactor())
9797
mlt = ScalarRandomFeatureInterface(
9898
n_features,
@@ -112,7 +112,7 @@ function main()
112112
)
113113
kernel_structure = NonseparableKernel(LowRankFactor(1, nugget))
114114
n_features = 200
115-
115+
116116
mlt = VectorRandomFeatureInterface(
117117
n_features,
118118
n_params,
@@ -165,9 +165,7 @@ function main()
165165

166166
# data processing configuration
167167
retain_var = 0.95
168-
encoder_schedule = [
169-
(decorrelate_structure_mat(retain_var = retain_var), "in_and_out"),
170-
]
168+
encoder_schedule = [(decorrelate_structure_mat(retain_var = retain_var), "in_and_out")]
171169

172170
emulator = Emulator(
173171
mlt,

src/RandomFeature.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function hyperparameters_from_flat(x::V, lrf::LowRankFactor) where {V <: Abstrac
212212

213213
D = Diagonal(x[1:d]) # D acts like sing.vals.^2
214214
U = reshape(x[(d + 1):end], d, r)
215-
return U * U' + D + get_eps(lrf)*I
215+
return U * U' + D + get_eps(lrf) * I
216216
217217
end
218218
@@ -259,11 +259,11 @@ function build_default_prior(name::SS, n_hp::Int, lrf::LowRankFactor) where {SS
259259
Dict(
260260
"name" => "$(name)_lowrank_diagonal",
261261
"distribution" => VectorOfParameterized(repeat([Normal(log(sqrt(0.1 / d)), 2)], d)),
262-
# "distribution" => VectorOfParameterized(repeat([Normal(log(1.0 / d), 2)], d)),
262+
# "distribution" => VectorOfParameterized(repeat([Normal(log(1.0 / d), 2)], d)),
263263
"constraint" => repeat([bounded_below(1e-8 / d)], d),
264264
),
265265
)
266-
# U = constrained_gaussian("$(name)_lowrank_U", 0.0, 10.0 / (d * r), -Inf, Inf, repeats = Int(d * r))
266+
# U = constrained_gaussian("$(name)_lowrank_U", 0.0, 10.0 / (d * r), -Inf, Inf, repeats = Int(d * r))
267267
U = constrained_gaussian("$(name)_lowrank_U", 0.0, sqrt(0.1 / d) / r, -Inf, Inf, repeats = Int(d * r))
268268
# D scales with sqrt(1/d), U scales with 1/r,sqrt(1/d)
269269
return combine_distributions([D, U])
@@ -298,10 +298,10 @@ function calculate_n_hyperparameters(
298298
299299
# if both in and output dim are "OneDimFactors" we still learn 1 hp
300300
if n_hp_in + n_hp_out == 0
301-
return 1
301+
return 1
302302
end
303303
304-
return n_hp_in + n_hp_out
304+
return n_hp_in + n_hp_out
305305
end
306306
307307
function calculate_n_hyperparameters(input_dim::Int, kernel_structure::KST) where {KST <: KernelStructureType}
@@ -319,10 +319,10 @@ function calculate_n_hyperparameters(
319319
320320
# if both in and output dim are "OneDimFactors" we still learn 1 hp
321321
if n_hp == 0
322-
return 1
322+
return 1
323323
end
324324
325-
return n_hp
325+
return n_hp
326326
end
327327
328328
@@ -352,7 +352,7 @@ function build_default_prior(input_dim::Int, output_dim::Int, kernel_structure::
352352
else
353353
return combine_distributions([input_prior, output_prior])
354354
end
355-
355+
356356
end
357357
358358
function build_default_prior(input_dim::Int, kernel_structure::KST) where {KST <: KernelStructureType}
@@ -370,7 +370,7 @@ function build_default_prior(input_dim::Int, output_dim::Int, kernel_structure::
370370
end
371371
372372
return pd_kern
373-
373+
374374
end
375375
376376
function hyperparameters_from_flat(

src/ScalarRandomFeature.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function RFM_from_hyperparameters(
277277
MT <: MultithreadType,
278278
}
279279
280-
xi_hp= isa(l, AbstractVecOrMat) ? l[:] : [l]
280+
xi_hp = isa(l, AbstractVecOrMat) ? l[:] : [l]
281281
kernel_structure = get_kernel_structure(srfi)
282282
pd = hyperparameter_distribution_from_flat(xi_hp, input_dim, kernel_structure, prior_in_scale)
283283
@@ -437,10 +437,10 @@ function build_models!(
437437
end
438438
439439
# scale up the prior so that default priors are always "reasonable"
440-
prior_in_scale = 1.0 ./ std(input_values, dims = 2)
440+
prior_in_scale = 1.0 ./ std(input_values, dims = 2)
441441
prior_out_scale = std(output_values[i, :])
442-
443-
442+
443+
444444
prior = build_default_prior(input_dim, kernel_structure)
445445
446446
# where prior space has changed we need to rebuild the priors
@@ -508,12 +508,12 @@ function build_models!(
508508
scheduler = optimizer_options["scheduler"]
509509
accelerator = optimizer_options["accelerator"]
510510
localization = optimizer_options["localization"]
511-
511+
512512
initial_params = construct_initial_ensemble(rng, prior, n_ensemble)
513513
# bug with scalar mean o/w
514514
prior_mean = isa(mean(prior), AbstractVector) ? mean(prior) : [mean(prior)]
515515
prior_cov = cov(prior)
516-
516+
517517
ekiobj = EKP.EnsembleKalmanProcess(
518518
initial_params,
519519
observation,

src/VectorRandomFeature.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function RFM_from_hyperparameters(
330330
MT <: MultithreadType,
331331
}
332332
333-
xi_hp= isa(l, AbstractVecOrMat) ? l[:] : [l]
333+
xi_hp = isa(l, AbstractVecOrMat) ? l[:] : [l]
334334
prior_out_scale_scalar = maximum(prior_out_scale) # most conservative scaling
335335
336336
kernel_structure = get_kernel_structure(vrfi)
@@ -566,7 +566,7 @@ function build_models!(
566566
567567
initial_params = construct_initial_ensemble(rng, prior, n_ensemble)
568568
# bug with scalar mean o/w
569-
prior_mean = isa(mean(prior), AbstractVector) ? mean(prior) : [mean(prior) ]
569+
prior_mean = isa(mean(prior), AbstractVector) ? mean(prior) : [mean(prior)]
570570
prior_cov = cov(prior)
571571
572572
ekiobj = EKP.EnsembleKalmanProcess(

test/RandomFeature/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ rng = Random.MersenneTwister(seed)
104104
ndims(build_default_prior("input", calculate_n_hyperparameters(d, c_in), c_in)) +
105105
ndims(build_default_prior("output", calculate_n_hyperparameters(p, c_out), c_out))
106106
@test ndims(build_default_prior(d, p, k_nonsep)) ==
107-
ndims(build_default_prior("full", calculate_n_hyperparameters(d * p, c_in), c_in))
107+
ndims(build_default_prior("full", calculate_n_hyperparameters(d * p, c_in), c_in))
108108

109109
@test ndims(build_default_prior(1, 1, k_sep1d)) == 1
110110
@test ndims(build_default_prior(1, 1, k_nonsep1d)) == 1

0 commit comments

Comments
 (0)