@@ -164,6 +164,30 @@ using FiniteDifferences
164164
165165end
166166
167+ function test_simobs(post, x, int = nothing )
168+ obs = simulate_observation(post, x)[begin ]
169+ @test length(obs) == length(post. data[begin ])
170+ obs_nn = simulate_observation(post, x, add_thermal_noise = false )[begin ]
171+ @test Comrade. measurement(obs_nn) == Comrade. likelihood(post. lklhds[1 ], last(Comrade. forward_model(post, x))). μ
172+
173+ if isnothing(int)
174+ postsim = VLBIPosterior(skym, obs)
175+ postsim_nn = VLBIPosterior(skym, obs_nn)
176+ else
177+ postsim = VLBIPosterior(skym, int, obs)
178+ postsim_nn = VLBIPosterior(skym, int, obs_nn)
179+ end
180+
181+
182+ c2 = chi2(postsim, x; reduce = true )
183+ c2nn = chi2(postsim_nn, x; reduce = true )
184+ @test all(x -> reduce(& , x .< 1.25 ), c2)
185+ return @test all(x -> reduce(& , x .≈ 0 ), c2nn)
186+
187+
188+ end
189+
190+
167191@testset " simulate_obs" begin
168192 _, vis, amp, lcamp, cphase, coh = load_data()
169193 g = imagepixels(μas2rad(150.0 ), μas2rad(150.0 ), 256 , 256 )
191215 x = μas2rad(30.0 ), y = μas2rad(30.0 ),
192216 ),
193217 )
194- function test_simobs(post, x, int = nothing )
195- obs = simulate_observation(post, x)[begin ]
196- @test length(obs) == length(post. data[begin ])
197- obs_nn = simulate_observation(post, x, add_thermal_noise = false )[begin ]
198- @test Comrade. measurement(obs_nn) == Comrade. likelihood(post. lklhds[1 ], last(Comrade. forward_model(post, x))). μ
199-
200- if isnothing(int)
201- postsim = VLBIPosterior(skym, obs)
202- postsim_nn = VLBIPosterior(skym, obs_nn)
203- else
204- postsim = VLBIPosterior(skym, int, obs)
205- postsim_nn = VLBIPosterior(skym, int, obs_nn)
206- end
207-
208-
209- c2 = chi2(postsim, x; reduce = true )
210- c2nn = chi2(postsim_nn, x; reduce = true )
211- @test all(x -> reduce(& , x .< 1.25 ), c2)
212- @test all(x -> reduce(& , x .≈ 0 ), c2nn)
213-
214-
215- end
216218
217219 test_simobs(post_amp, x0)
218220 test_simobs(post_cp, x0)
@@ -236,13 +238,13 @@ end
236238function test_nonanalytic(intm, algorithm, vis)
237239 skym = SkyModel(test_model, test_prior(), imagepixels(μas2rad(150.0 ), μas2rad(150.0 ), 256 , 256 ); algorithm)
238240 post = VLBIPosterior(skym, intm, vis)
239-
241+
240242 tpostf = asflat(post)
241243 x0 = prior_sample(tpostf)
242244 @inferred logdensityof(tpostf, x0)
243245 gz, = Enzyme. gradient(set_runtime_activity(Enzyme. Reverse), Const(tpostf), x0)
244246 gn, = FiniteDifferences. grad(mfd, tpostf, x0)
245- @test gz ≈ gn
247+ return @test gz ≈ gn
246248end
247249
248250
0 commit comments