Skip to content

Commit

Permalink
fix marginal test thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
khosravipasha committed Mar 3, 2021
1 parent 059ae8f commit 8754915
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions test/queries/marginal_flow_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ using LogicCircuits
using ProbabilisticCircuits
using DataFrames: DataFrame
using CUDA
using Random
using Suppressor

include("../helper/gpu.jl")

@testset "Marginals" begin
EPS = 1e-5

prob_circuit = zoo_psdd("little_4var.psdd");
@test prob_circuit(false, false, false, missing) -1.0498221

Expand All @@ -22,16 +25,21 @@ include("../helper/gpu.jl")
0.3499999999999; 0.1; 1.0; 0.8]

calc_prob = exp.(MAR(prob_circuit, data_marg))
@test true_prob calc_prob atol=1e-7
@test true_prob calc_prob atol=EPS
@test marginal_log_likelihood_avg(prob_circuit, data_marg) sum(log.(true_prob))/7
@test marginal_all(prob_circuit, data_marg)
[0.0 -Inf -Inf -Inf -Inf -Inf 0.0 0.0 0.0 0.0 -0.356675 -2.30259 -2.65926
marginal_all_result = marginal_all(prob_circuit, data_marg);

marginal_all_true_answer = [0.0 -Inf -Inf -Inf -Inf -Inf 0.0 0.0 0.0 0.0 -0.356675 -2.30259 -2.65926
0.0 -Inf -Inf 0.0 0.0 -Inf 0.0 -Inf -Inf 0.0 -2.30259 -1.20397 -3.50656
0.0 -Inf -Inf -Inf 0.0 0.0 0.0 0.0 -Inf -Inf -0.356675 -1.60944 -1.96611
0.0 -Inf -Inf -Inf -Inf 0.0 0.0 0.0 0.0 0.0 -0.356675 -0.693147 -1.04982
0.0 -Inf 0.0 0.0 -Inf 0.0 0.0 -Inf 0.0 0.0 -1.60944 -0.693147 -2.30259
0.0 -Inf 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -2.98023f-8 -7.45058f-9 -3.72529f-8
0.0 -Inf -Inf 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.223144 -7.45058f-9 -0.223144]
0.0 -Inf -Inf 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.223144 -7.45058f-9 -0.223144];

for pair in zip(marginal_all_result, marginal_all_true_answer)
@test pair[1] pair[2] atol=EPS
end

cpu_gpu_agree_approx(data_marg) do d
marginal_all(prob_circuit, d)
Expand Down Expand Up @@ -64,11 +72,15 @@ include("../helper/gpu.jl")
end

# Strudel Marginal Flow Test
samples, _ = sample(prob_circuit, 100000)
rng = MersenneTwister(100003); # Fix the seed
samples, _ = sample(prob_circuit, 100000; rng)
mix, weights, _ = learn_strudel(DataFrame(convert(BitArray, samples)); num_mix = 10,
init_maxiter = 20, em_maxiter = 100, verbose = false)
mix_calc_prob = exp.(MAR(mix, data_marg, weights))
@test true_prob mix_calc_prob atol = 0.1
for mix_pair in zip(true_prob, mix_calc_prob)
@test mix_pair[1] mix_pair[2] atol=0.1
end

test_complete_mar(mix, data_full, weights, 0.1)
end

Expand Down

0 comments on commit 8754915

Please sign in to comment.