11using ParticleDA
22using ParticleDA. Kalman
3- using HDF5, LinearAlgebra, MPI, PDMats, Random, StableRNGs, Statistics, Test, YAML
3+ using HDF5, LinearAlgebra, MPI, PDMats, Random, StableRNGs, Statistics, Test, YAML
44
55include(joinpath(@__DIR__, " models" , " llw2d.jl" ))
66include(joinpath(@__DIR__, " models" , " lorenz63.jl" ))
100100 check_hdf5_group_valid(file, group, group_name)
101101 @test read(group, dataset_name) == test_array
102102 @test all([
103- read_attribute(group[dataset_name], k) == test_attributes[k]
103+ read_attribute(group[dataset_name], k) == test_attributes[k]
104104 for k in keys(test_attributes)
105105 ])
106106 # test writing to existing dataset name results in warning and does not update
115115 # test writing timer data
116116 timer_strings = [" ab" , " cde" , " fg" , " hij" ]
117117 ParticleDA. write_timers(
118- map(length, timer_strings),
119- length(timer_strings),
120- codeunits(join(timer_strings)),
118+ map(length, timer_strings),
119+ length(timer_strings),
120+ codeunits(join(timer_strings)),
121121 output_filename
122122 )
123123 h5open(output_filename, " cw" ) do file
132132
133133
134134@testset (
135- " Generic model interface unit tests - $(parentmodule(typeof(model))) "
135+ " Generic model interface unit tests - $(parentmodule(typeof(model))) "
136136) for model in (
137137 LLW2d. init(Dict()),
138138 Lorenz63. init(Dict()),
159159 " x_length" => 100e3 ,
160160 " y_length" => 100e3 ,
161161 " station_boundary_x" => 30e3 ,
162- " station_boundary_y" => 30e3 ,
162+ " station_boundary_y" => 30e3 ,
163163 )
164164 )
165165 ),
182182 config. model,
183183 seed,
184184 estimate_bound_constant,
185- config. estimate_n_samples;
185+ config. estimate_n_samples;
186186 RNGType= StableRNG
187187 )
188188end
223223 avg= mean(states; dims= 2 ), var= var(states, corrected= true ; dims= 2 )
224224 )
225225 for statistics_type in (
226- ParticleDA. NaiveMeanSummaryStat,
226+ ParticleDA. NaiveMeanSummaryStat,
227227 ParticleDA. NaiveMeanAndVarSummaryStat,
228228 ParticleDA. MeanSummaryStat,
229229 ParticleDA. MeanAndVarSummaryStat
@@ -279,12 +279,12 @@ end
279279 new_states = copy(states)
280280 Random. seed!(rng, seed)
281281 ParticleDA. sample_proposal_and_compute_log_weights!(
282- new_states,
283- log_weights,
284- observation,
285- time_index,
286- model,
287- filter_data,
282+ new_states,
283+ log_weights,
284+ observation,
285+ time_index,
286+ model,
287+ filter_data,
288288 filter_type,
289289 rng
290290 )
@@ -299,12 +299,12 @@ end
299299 # Check filter update gives deterministic updates when rng state is fixed
300300 Random. seed!(rng, seed)
301301 ParticleDA. sample_proposal_and_compute_log_weights!(
302- new_states_2,
303- log_weights_2,
304- observation,
305- time_index,
306- model,
307- filter_data,
302+ new_states_2,
303+ log_weights_2,
304+ observation,
305+ time_index,
306+ model,
307+ filter_data,
308308 filter_type,
309309 rng
310310 )
@@ -318,10 +318,10 @@ end
318318 n_task = 1
319319 model_params_dict = Dict(
320320 " llw2d" => Dict(
321- " nx" => 32 ,
322- " ny" => 32 ,
323- " n_stations_x" => 4 ,
324- " n_stations_y" => 4 ,
321+ " nx" => 32 ,
322+ " ny" => 32 ,
323+ " n_stations_x" => 4 ,
324+ " n_stations_y" => 4 ,
325325 " padding" => 0
326326 )
327327 )
340340 online_matrices = ParticleDA. init_online_matrices(model, 1 )
341341 for f in nfields(online_matrices)
342342 matrix = getfield(online_matrices, f)
343- @test isa(matrix, AbstractMatrix)
344- end
343+ @test isa(matrix, AbstractMatrix)
344+ end
345345 state_dimension = ParticleDA. get_state_dimension(model)
346346 updated_indices = ParticleDA. get_state_indices_correlated_to_observations(
347347 model
@@ -381,10 +381,10 @@ end
381381 # X = F(x) + U and Y = HX + V where x is the previous state value, F the forward
382382 # operator for the deterministic state dynamics, U ~ Normal(0, Q) the additive
383383 # state noise, X the state at the next time step, H the linear observation
384- # operator, V ~ Normal(0, R) the additive observation noise and Y the modelled
385- # observations, is Normal(m, C) where
384+ # operator, V ~ Normal(0, R) the additive observation noise and Y the modelled
385+ # observations, is Normal(m, C) where
386386 # m = F(x) + QHᵀ(HQHᵀ + R)⁻¹(y − HF(x))
387- # = F(x) + cov(X, Y) @ cov(Y, Y)⁻¹ (y − HF(x))
387+ # = F(x) + cov(X, Y) @ cov(Y, Y)⁻¹ (y − HF(x))
388388 # and C = Q − QHᵀ(HQHᵀ + R)⁻¹HQ = cov(X, X) - cov(X, Y) cov(Y, Y)⁻¹ cov(X, Y)ᵀ
389389 analytic_mean = copy(state)
390390 @view(analytic_mean[updated_indices]) .+ = (
404404 # Create set of state ' particles' all equal to propagated state
405405 states = Matrix{ParticleDA.get_state_eltype(model)}(
406406 undef, (state_dimension, nprt)
407- )
407+ )
408408 states .= state
409409 updated_states = copy(states)
410410 for state in eachcol(updated_states)
@@ -414,21 +414,21 @@ end
414414 # Mean of noise added by update_particle_noise! should be zero in all components
415415 # and empirical mean should therefore be zero to within Monte Carlo error. The
416416 # constant in the tolerance below was set by looking at scale of typical
417- # deviation, the point of check is that errors scale at expected O(1/√N) rate.
418- @test maximum(abs.(mean(noise, dims=2))) < (10. / sqrt(nprt))
417+ # deviation, the point of check is that errors scale at expected O(1/√N) rate.
418+ @test maximum(abs.(mean(noise, dims=2))) < (10. / sqrt(nprt))
419419 # Covariance of noise added by update_particle_noise! to observed state
420420 # components should be cov_X_X as computed above and empirical covariance of
421421 # these components should therefore be within Monte Carlo error of cov_X_X. The
422422 # constant in tolerance below was set by looking at scale of typical deviations,
423- # the point of check is that errors scale at expected O(1/√N) rate.
423+ # the point of check is that errors scale at expected O(1/√N) rate.
424424 noise_cov = cov(noise, dims=2)
425- @test maximum(abs.(noise_cov .- cov_X_X)) < (10. / sqrt(nprt))
425+ @test maximum(abs.(noise_cov .- cov_X_X)) < (10. / sqrt(nprt))
426426 ParticleDA.update_states_given_observations!(
427427 updated_states, observation, model, filter_data, rng
428428 )
429429 updated_mean = mean(updated_states, dims=2)
430430 updated_cov = cov(updated_states, dims=2)
431- # Mean and covariance of updated particles should be within O(1/√N) Monte Carlo
431+ # Mean and covariance of updated particles should be within O(1/√N) Monte Carlo
432432 # error of analytic values - constants in tolerances were set by looking at
433433 # scale of typical deviations, main point of checks are that errors scale at
434434 # expected O(1/√N) rate.
@@ -473,24 +473,24 @@ end
473473end
474474
475475
476- @testset "Integration test -- $(input_file) with $(filter_type) and $(stat_type)" for
476+ @testset "Integration test -- $(input_file) with $(filter_type) and $(stat_type)" for
477477 filter_type in (ParticleDA.BootstrapFilter, ParticleDA.OptimalFilter),
478478 stat_type in (ParticleDA.MeanSummaryStat, ParticleDA.MeanAndVarSummaryStat),
479479 input_file in ["integration_test_$i.yaml" for i in 1:6]
480480 observation_file_path = tempname()
481481 ParticleDA.simulate_observations_from_model(
482- LLW2d.init,
483- joinpath(@__DIR__, input_file),
482+ LLW2d.init,
483+ joinpath(@__DIR__, input_file),
484484 observation_file_path
485485 )
486486 observation_sequence = h5open(
487487 ParticleDA.read_observation_sequence, observation_file_path, "r"
488488 )
489489 @test !any(isnan.(observation_sequence))
490490 states, statistics = ParticleDA.run_particle_filter(
491- LLW2d.init,
492- joinpath(@__DIR__, input_file),
493- observation_file_path,
491+ LLW2d.init,
492+ joinpath(@__DIR__, input_file),
493+ observation_file_path,
494494 filter_type,
495495 stat_type,
496496 )
0 commit comments