Add Kullback-Leibler divergence calculation to the package
diff --git a/test/runtests.jl b/test/runtests.jl
index 7dfe844..e0ff466 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -8,8 +8,8 @@
wpd19 = load(joinpath(artifact"wpd19_10000", "wpd19_10000", "wpd19_10000.vecs"))
@testset "DerekoVecs.jl: loading" begin
- @test wpd19.m == 200;
- @test wpd19.n >= 10000;
+ @test wpd19.m == 200
+ @test wpd19.n >= 10000
end
@testset "DerekoVecs.jl: similarities" begin
@@ -27,4 +27,18 @@
@test "wurden" in knn(wpd19, "wurde", 3)
end
+ @testset "DerekoVecs.jl: kld" begin
+ mykld = kld(wpd19, wpd19)
+ @test mykld.common_type_count == length(wpd19.vocabdict)
+ @test isapprox(mykld.common_type_share, 100)
+ @test isapprox(mykld.kld, 0)
+ @test wpd19.total_tokens == mykld.common_token_count
+ @test isapprox(mykld.common_token_share, 100)
+ end
+
+ @testset "DerekoVecs.jl: load freq list only" begin
+ wpd19_freqlist = load(joinpath(artifact"wpd19_10000", "wpd19_10000", "wpd19_10000.vocab"))
+ @test wpd19.total_tokens == wpd19_freqlist.total_tokens
+ @test isapprox(kld(wpd19_freqlist, wpd19).kld, 0)
+ end
end