|
| 1 | +@testitem "BIFM Node" begin |
| 2 | + using ReactiveMP, Distributions, LinearAlgebra, Random, Test |
| 3 | + import ReactiveMP: |
| 4 | + getA, getB, getC, getH, getμu, getΣu, default_meta, setH!, setBHBt!, setξz!, setΛz!, setξztilde!, setΛztilde!, setμu!, setΣu!, getBHBt, getξz, getΛz, getξztilde, getΛztilde |
| 5 | + |
| 6 | + @testset "BIFMMeta constructors" begin |
| 7 | + A = [1.0 0.1; 0.0 1.0] |
| 8 | + B = [0.5 0.0; 0.0 0.5] |
| 9 | + C = [1.0 0.0; 0.0 1.0] |
| 10 | + |
| 11 | + meta1 = BIFMMeta(A, B, C) |
| 12 | + @test meta1 isa BIFMMeta{Float64} |
| 13 | + @test getA(meta1) === A |
| 14 | + @test getB(meta1) === B |
| 15 | + @test getC(meta1) === C |
| 16 | + @test getH(meta1) === nothing |
| 17 | + @test getμu(meta1) === nothing |
| 18 | + |
| 19 | + # test dimension checks |
| 20 | + @test_throws AssertionError BIFMMeta(ones(2, 2), ones(3, 2), ones(2, 2)) |
| 21 | + |
| 22 | + # constructor with input priors |
| 23 | + μu = randn(2) |
| 24 | + Σu = diageye(2) |
| 25 | + meta2 = BIFMMeta(A, B, C, μu, Σu) |
| 26 | + @test getμu(meta2) == μu |
| 27 | + @test getΣu(meta2) == Σu |
| 28 | + @test meta2 isa BIFMMeta{Float64} |
| 29 | + end |
| 30 | + |
| 31 | + @testset "BIFMMeta setters and getters" begin |
| 32 | + A = [1.0 0.0; 0.0 1.0] |
| 33 | + B = [0.2 0.3; 0.1 0.4] |
| 34 | + C = [1.0 0.0; 0.0 1.0] |
| 35 | + meta = BIFMMeta(A, B, C) |
| 36 | + |
| 37 | + H = rand(2, 2) |
| 38 | + BHBt = rand(2, 2) |
| 39 | + ξz = rand(2) |
| 40 | + Λz = diageye(2) |
| 41 | + ξztilde = rand(2) |
| 42 | + Λztilde = diageye(2) |
| 43 | + μu = rand(2) |
| 44 | + Σu = diageye(2) |
| 45 | + |
| 46 | + setH!(meta, H) |
| 47 | + setBHBt!(meta, BHBt) |
| 48 | + setξz!(meta, ξz) |
| 49 | + setΛz!(meta, Λz) |
| 50 | + setξztilde!(meta, ξztilde) |
| 51 | + setΛztilde!(meta, Λztilde) |
| 52 | + setμu!(meta, μu) |
| 53 | + setΣu!(meta, Σu) |
| 54 | + |
| 55 | + @test getH(meta) === H |
| 56 | + @test getBHBt(meta) === BHBt |
| 57 | + @test getξz(meta) === ξz |
| 58 | + @test getΛz(meta) === Λz |
| 59 | + @test getξztilde(meta) === ξztilde |
| 60 | + @test getΛztilde(meta) === Λztilde |
| 61 | + @test getμu(meta) === μu |
| 62 | + @test getΣu(meta) === Σu |
| 63 | + end |
| 64 | + |
| 65 | + @testset "BIFM node construction and interface structure" begin |
| 66 | + @test sdtype(BIFM) == Deterministic() |
| 67 | + |
| 68 | + # TODO: test for interface indices and names. Problem: Creating factornode with node = factornode(BIFM, interfaces, factorizations) and then call getinterfaces and interfaceindex, but there is no method matching collect_factorisation(::Type{ReactiveMP.BIFM}, ::Vector{Vector{Symbol}}) |
| 69 | + end |
| 70 | +end |
0 commit comments