From b1420fd67715803c18f5530c245fac4772804611 Mon Sep 17 00:00:00 2001 From: Justin Staples Date: Mon, 9 Apr 2018 10:40:37 -0400 Subject: [PATCH 1/3] adding test for cauchy transformation to student's t --- haskell/Tests/RoundTrip.hs | 6 ++++++ tests/RoundTrip2/t_cauchy_to_students_t.0.hk | 14 +++++++++++++ .../t_cauchy_to_students_t.expected.hk | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/RoundTrip2/t_cauchy_to_students_t.0.hk create mode 100644 tests/RoundTrip2/t_cauchy_to_students_t.expected.hk diff --git a/haskell/Tests/RoundTrip.hs b/haskell/Tests/RoundTrip.hs index 810746e3..ab5c0bd7 100644 --- a/haskell/Tests/RoundTrip.hs +++ b/haskell/Tests/RoundTrip.hs @@ -211,6 +211,11 @@ testStdChiSqRelations = test [ "t_rayleigh_to_stdChiSq" ~: testConcreteFiles "tests/RoundTrip2/t_rayleigh_to_stdChiSq.0.hk" "tests/RoundTrip2/t_rayleigh_to_stdChiSq.expected.hk" ] +testCauchyRelations :: Test +testCauchyRelations = test [ + "t_cauchy_to_students_t" ~: testConcreteFiles "tests/RoundTrip2/t_cauchy_to_students_t.0.hk" "tests/RoundTrip2/t_cauchy_to_students_t.expected.hk" + ] + testOther :: Test testOther = test [ "t82" ~: testConcreteFiles "tests/RoundTrip/t82.0.hk" "tests/RoundTrip/t82.expected.hk", @@ -253,6 +258,7 @@ allTests = test , testMeasureNat , testMeasureInt , testStdChiSqRelations + , testCauchyRelations , testOther ] diff --git a/tests/RoundTrip2/t_cauchy_to_students_t.0.hk b/tests/RoundTrip2/t_cauchy_to_students_t.0.hk new file mode 100644 index 00000000..90cfd748 --- /dev/null +++ b/tests/RoundTrip2/t_cauchy_to_students_t.0.hk @@ -0,0 +1,14 @@ +def stdNormal(): + p <~ normal(0, 1) + return p + +def stdCauchy(): + X1 <~ stdNormal() + X2 <~ stdNormal() + return X1/X2 + +def cauchy(a real, alpha prob): + X <~ stdCauchy() + return a + alpha*X + +cauchy(0, 1) \ No newline at end of file diff --git a/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk b/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk new file mode 100644 index 00000000..d82c6fd0 --- /dev/null +++ b/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk @@ -0,0 +1,21 @@ +def chiSq_iid(n nat, mean real, stdev prob): + q <~ plate _ of n: normal(mean,stdev) + return summate i from 0 to size(q): + ((q[i]-mean)/stdev)^2 + +def standardChiSq(n nat): + chiSq_iid(n,0,1) + +def standardChi(n nat): + q <~ standardChiSq(n) + return sqrt(real2prob(q)) + +def nonCentralT(n nat, delta prob): + U <~ normal(0,1) + X <~ standardChi(n) + return (U + delta)*sqrt(n)/(X) + +def t(n nat): + return nonCentralT(n,0) + +t(1) From 70d80bc8e9293ca5eaf8d6ede893c870e7c0ab84 Mon Sep 17 00:00:00 2001 From: Justin Staples Date: Tue, 24 Apr 2018 00:00:37 -0400 Subject: [PATCH 2/3] fixing test case --- tests/RoundTrip2/t_cauchy_to_students_t.expected.hk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk b/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk index d82c6fd0..b0af40d3 100644 --- a/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk +++ b/tests/RoundTrip2/t_cauchy_to_students_t.expected.hk @@ -16,6 +16,6 @@ def nonCentralT(n nat, delta prob): return (U + delta)*sqrt(n)/(X) def t(n nat): - return nonCentralT(n,0) + nonCentralT(n,0) t(1) From d8b9ad7cf6637580a46edc8e451998809c11d94a Mon Sep 17 00:00:00 2001 From: Mahmoud Khattab Date: Tue, 24 Apr 2018 13:57:35 -0400 Subject: [PATCH 3/3] Fix --- tests/RoundTrip/t_cauchy_to_students_t.expected.hk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RoundTrip/t_cauchy_to_students_t.expected.hk b/tests/RoundTrip/t_cauchy_to_students_t.expected.hk index 428e16d1..b7c3f5e7 100644 --- a/tests/RoundTrip/t_cauchy_to_students_t.expected.hk +++ b/tests/RoundTrip/t_cauchy_to_students_t.expected.hk @@ -1,4 +1,4 @@ #t(1) U <~ normal(+0/1,1/1) X <~ normal(+0/1,1/1) -return U/abs(X) +return U/X