summaryrefslogtreecommitdiff
path: root/src/Example/GMM.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Example/GMM.hs')
-rw-r--r--src/Example/GMM.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Example/GMM.hs b/src/Example/GMM.hs
index ff37f9a..1db88bd 100644
--- a/src/Example/GMM.hs
+++ b/src/Example/GMM.hs
@@ -32,8 +32,16 @@ type TMat = TArr (S (S Z))
-- Master thesis at Utrecht University. (Appendix B.1)
-- <https://studenttheses.uu.nl/bitstream/handle/20.500.12932/38958/report.pdf?sequence=1&isAllowed=y>
-- <https://tomsmeding.com/f/master.pdf>
-gmmObjective :: Ex [R, R, R, I64, TMat R, TMat R, TMat R, TMat R, TVec R, I64, I64, I64] R
-gmmObjective = fromNamed $
+--
+-- The 'wrong' argument, when set to True, changes the objective function to
+-- one with a bug that makes a certain `build` result unused. This triggers
+-- makes the CHAD code fail because it tries to use a D2 (TArr) as if it's
+-- dense, even though it may be a zero (i.e. empty). The "unused" test in
+-- test/Main.hs tries to isolate this test, but the wrong version of
+-- gmmObjective is here to check (after that bug is fixed) whether it really
+-- fixes the original bug.
+gmmObjective :: Bool -> Ex [R, R, R, I64, TMat R, TMat R, TMat R, TMat R, TVec R, I64, I64, I64] R
+gmmObjective wrong = fromNamed $
lambda #N $ lambda #D $ lambda #K $
lambda #alpha $ lambda #M $ lambda #Q $ lambda #L $
lambda #X $ lambda #m $
@@ -100,7 +108,8 @@ gmmObjective = fromNamed $
if_ (#i .== #j)
(exp (#q ! pair nil #i))
(if_ (#i .> #j)
- (toFloat_ $ #i * (#i - 1) `idiv` 2 + 1 + #j)
+ (if wrong then toFloat_ (#i * (#i - 1) `idiv` 2 + #j)
+ else #l ! pair nil (#i * (#i - 1) `idiv` 2 + #j))
0.0)
qmat q l = inline qmat' (SNil .$ q .$ l)
in let_ #k2arr (unit #k2) $