-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented kl divergence and simple tests
- Loading branch information
Alex Markham
committed
Jan 18, 2024
1 parent
919dc49
commit 8b1b6b2
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import random | ||
|
||
import numpy as np | ||
|
||
from cstrees import cstree as ct | ||
from cstrees.evaluate import kl_divergence | ||
|
||
|
||
def test_kl_divergence(): | ||
np.random.seed(22) | ||
random.seed(22) | ||
|
||
cards = [3, 2, 2, 3] | ||
|
||
t = ct.sample_cstree(cards, max_cvars=2, prob_cvar=0.5, prop_nonsingleton=1) | ||
t.sample_stage_parameters(alpha=2) | ||
|
||
t.sample(1000) | ||
|
||
assert kl_divergence(t, t) == 0 | ||
|
||
e = ct.sample_cstree(cards, max_cvars=2, prob_cvar=0.5, prop_nonsingleton=1) | ||
e.sample_stage_parameters(alpha=2) | ||
|
||
e.sample(1000) | ||
assert kl_divergence(e, t) > 0 |