Skip to content

Commit b41e75b

Browse files
author
Alexey Stukalov
committed
tests/model: replace_observed() kwargs passing
1 parent 690d248 commit b41e75b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/unit_tests/model.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using StructuralEquationModels, Test, Statistics
22

3+
const SEM = StructuralEquationModels
4+
35
dat = example_data("political_democracy")
46
dat_missing = example_data("political_democracy_missing")[:, names(dat)]
57

@@ -73,3 +75,34 @@ end
7375

7476
@test @inferred(nsamples(model)) == nsamples(obs)
7577
end
78+
79+
@testset "replace_observed() preserves WLS state through finite-diff wrappers" begin
80+
model = Sem(
81+
specification = ram_matrices,
82+
observed = obs,
83+
implied = RAMSymbolic,
84+
loss = SemWLS,
85+
)
86+
wls_loss = sem_term(model)
87+
findiff_model = Sem(SEM.FiniteDiffWrapper(wls_loss))
88+
89+
new_data = randn(nsamples(obs), nobserved_vars(obs))
90+
91+
findiff_model_oldstate =
92+
replace_observed(findiff_model, new_data; update_internal_state = false)
93+
findiff_model_newstate =
94+
replace_observed(findiff_model, new_data; update_internal_state = true)
95+
96+
loss_orig = SEM._unwrap(sem_term(findiff_model))
97+
loss_oldstate = SEM._unwrap(sem_term(findiff_model_oldstate))
98+
loss_newstate = SEM._unwrap(sem_term(findiff_model_newstate))
99+
100+
@test loss_orig isa SemWLS
101+
@test loss_oldstate isa SemWLS
102+
@test loss_newstate isa SemWLS
103+
@test loss_orig !== loss_oldstate
104+
@test loss_orig !== loss_newstate
105+
@test loss_oldstate.V === loss_orig.V
106+
@test loss_newstate.V !== loss_orig.V
107+
@test observed_vars(loss_oldstate) == observed_vars(loss_orig)
108+
end

0 commit comments

Comments
 (0)