Skip to content

Commit d2c8dde

Browse files
authored
Merge pull request #539 from ReactiveBayes/improving-codecov
Improving codecov
2 parents 04401f2 + cfa513e commit d2c8dde

17 files changed

Lines changed: 828 additions & 6 deletions

src/rules/gamma_mixture/a.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
@rule GammaMixture((:a, k), Marginalisation) (q_out::Any, q_switch::Any, q_b::GammaDistributionsFamily) = begin
32
p = probvec(q_switch)[k]
43
β = mean(log, q_out) + mean(log, q_b)

src/rules/gamma_mixture/out.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
@rule GammaMixture{N}(:out, Marginalisation) (q_switch::Any, q_a::ManyOf{N, Any}, q_b::ManyOf{N, GammaDistributionsFamily}) where {N} = begin
32
πs = probvec(q_switch)
43
return GammaShapeRate(sum(πs .* mean.(q_a)), sum(πs .* mean.(q_b)))

src/rules/gamma_mixture/switch.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
@rule GammaMixture{N}(:switch, Marginalisation) (q_out::Any, q_a::ManyOf{N, Any}, q_b::ManyOf{N, GammaDistributionsFamily}) where {N} = begin
32
U = map(zip(q_a, q_b)) do (a, b)
43
-score(AverageEnergy(), GammaShapeRate, Val{(:out, :α, :β)}(), map((q) -> Marginal(q, false, false, nothing), (q_out, a, b)), nothing)

test/nodes/predefined/autoregressive_tests.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,66 @@
5353
@test cmatrix == (matrix + ftransition)
5454
end
5555
end
56+
57+
# TODO: multivariate case coverage
58+
59+
end
60+
61+
@testitem "AutoregressiveNode: is_univariate, is_safe, is_unsafe, default_meta, is_multivariate cases, ar_unit, ARPrecisionMatrix" begin
62+
using ReactiveMP, Distributions, ExponentialFamily, LazyArrays, LinearAlgebra, Test
63+
import ReactiveMP: ARMeta, ARsafe, ARunsafe, AR, ar_unit, ar_precision, ARPrecisionMatrix
64+
@testset "ARMeta and ARPrecisionMatrix extensions" begin
65+
66+
# --- ARMeta property tests ---
67+
meta_uni = ARMeta(Univariate, 1, ARsafe())
68+
meta_multi = ARMeta(Multivariate, 3, ARunsafe())
69+
70+
@test ReactiveMP.is_univariate(meta_uni)
71+
@test !ReactiveMP.is_multivariate(meta_uni)
72+
@test ReactiveMP.is_safe(meta_uni)
73+
@test !ReactiveMP.is_unsafe(meta_uni)
74+
75+
@test ReactiveMP.is_multivariate(meta_multi)
76+
@test !ReactiveMP.is_univariate(meta_multi)
77+
@test ReactiveMP.is_unsafe(meta_multi)
78+
@test !ReactiveMP.is_safe(meta_multi)
79+
80+
# --- default_meta should throw ---
81+
@test_throws ErrorException ReactiveMP.default_meta(AR)
82+
83+
# --- ar_unit coverage ---
84+
@test ar_unit(Univariate, 1) == 1.0
85+
@test ar_unit(Multivariate, 3)[1] 1.0
86+
@test eltype(ar_unit(Float32, Univariate, 1)) === Float32
87+
88+
# --- ar_precision and ARPrecisionMatrix ---
89+
γ = 2.5
90+
order = 3
91+
pm = ar_precision(Multivariate, order, γ)
92+
@test size(pm) == (3, 3)
93+
@test pm[1, 1] == γ
94+
@test pm[2, 2] convert(Float64, huge)
95+
@test pm[1, 2] == 0.0
96+
97+
# add_precision & add_precision!
98+
A = zeros(3, 3)
99+
B = copy(A)
100+
res = ReactiveMP.add_precision(A, pm)
101+
@test res[1, 1] == γ
102+
@test res[2, 2] huge
103+
104+
ReactiveMP.add_precision!(B, pm)
105+
@test B[1, 1] == γ
106+
@test B[3, 3] huge
107+
108+
# Real + Real overloads
109+
@test ReactiveMP.add_precision!(1.0, 2.0) == 3.0
110+
@test ReactiveMP.add_precision(1.0, 2.0) == 3.0
111+
112+
# Broadcast! directly
113+
C = zeros(3, 3)
114+
broadcast!(+, C, pm)
115+
@test C[1, 1] == γ
116+
@test all(diag(C)[2:end] .≈ huge)
117+
end
56118
end
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@testitem "dot node: default_meta" begin
2+
using ReactiveMP
3+
using MatrixCorrectionTools
4+
import ReactiveMP: default_meta
5+
6+
# Check that `default_meta` for `dot` returns the correct type
7+
meta = default_meta(dot)
8+
@test meta isa MatrixCorrectionTools.ReplaceZeroDiagonalEntries
9+
10+
# Check that it uses the expected `tiny` value
11+
@test meta.value == tiny
12+
end

0 commit comments

Comments
 (0)