Skip to content

add test for regressions #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions statistics.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ test-suite tests
Tests.ApproxEq
Tests.Correlation
Tests.Distribution
Tests.Regression
Tests.Function
Tests.Helpers
Tests.KDE
Expand Down
41 changes: 41 additions & 0 deletions tests/Tests/Regression.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Tests.Regression
( tests ) where

import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as U
import Debug.Trace (trace)
import Statistics.Regression
import Test.Framework (Test, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.QuickCheck

data Predictor = Predictor [Vector Double] (Vector Double)
deriving Show

instance Arbitrary Predictor where
arbitrary = do
-- we pick an arbitrary length N - this is the length the
-- predictor vectors and the responder vector will have
n <- arbitrary `suchThat` (>1)

matrix <- listOf1 (vectorOf n $ elements [1,2,3])
-- the matrix must have more rows than columns
`suchThat` ((<n) . length)

responder <- vectorOf n (elements [4,5,6])

return (Predictor (map U.fromList matrix) (U.fromList responder))

tests :: Test
tests = testGroup "Regression"
[ testProperty "OLS test - shape" testOLS ]


testOLS :: Predictor -> Bool
testOLS (Predictor matrix responder) =
let (v,double) = olsRegress matrix responder in
let vlen = U.length v
mlen = length matrix in
if (vlen == mlen+1 && double >=0 && double <= 1)
then True
else trace (show ("ols", vlen,mlen,U.length (head matrix), double)) False
17 changes: 10 additions & 7 deletions tests/tests.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Test.Framework (defaultMain)
import qualified Tests.Distribution as Distribution
import qualified Tests.Function as Function
import qualified Tests.KDE as KDE
import qualified Tests.Matrix as Matrix
import Test.Framework (defaultMain)
import qualified Tests.Correlation as Correlation
import qualified Tests.Distribution as Distribution
import qualified Tests.Function as Function
import qualified Tests.KDE as KDE
import qualified Tests.Matrix as Matrix
import qualified Tests.NonParametric as NonParametric
import qualified Tests.Transform as Transform
import qualified Tests.Correlation as Correlation
import qualified Tests.Regression as Regression
import qualified Tests.Transform as Transform


main :: IO ()
main = defaultMain [ Distribution.tests
Expand All @@ -15,4 +17,5 @@ main = defaultMain [ Distribution.tests
, NonParametric.tests
, Transform.tests
, Correlation.tests
, Regression.tests
]