RANSAC 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+67/−3 lines, 4 filesdep +HUnitdep +RANSACdep +lensdep ~basedep ~vectorPVP ok
version bump matches the API change (PVP)
Dependencies added: HUnit, RANSAC, lens, linear, test-framework, test-framework-hunit
Dependency ranges changed: base, vector
API changes (from Hackage documentation)
Files
- .gitignore +3/−0
- .travis.yml +3/−0
- RANSAC.cabal +14/−3
- tests/SmokeTest.hs +47/−0
+ .gitignore view
@@ -0,0 +1,3 @@+dist+*.o+*.hi
+ .travis.yml view
@@ -0,0 +1,3 @@+language: haskell+install:+ - cabal install --enable-tests --force-reinstalls
RANSAC.cabal view
@@ -1,5 +1,5 @@ name: RANSAC-version: 0.1.0.0+version: 0.1.0.1 synopsis: The RANSAC algorithm for parameter estimation. description: The RANdom SAmple Consensus (RANSAC) algorithm for estimating the parameters of a mathematical model@@ -17,7 +17,8 @@ category: Math,Numerical build-type: Simple cabal-version: >=1.10-extra-source-files: tests/Perf.hs, tests/LinearFit.hs+extra-source-files: tests/Perf.hs, tests/LinearFit.hs, tests/SmokeTest.hs,+ .travis.yml, .gitignore source-repository head type: git@@ -25,9 +26,19 @@ library exposed-modules: Numeric.Ransac- build-depends: base >= 4.6 && < 5, + build-depends: base >= 4.5 && < 5, vector >= 0.10, random >= 1.0 hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall++test-suite tests+ type: exitcode-stdio-1.0+ hs-source-dirs: tests+ main-is: SmokeTest.hs+ ghc-options: -Wall+ default-language: Haskell2010+ build-depends: base >= 4.5 && < 5,+ test-framework, test-framework-hunit, HUnit,+ linear, vector, lens, RANSAC
+ tests/SmokeTest.hs view
@@ -0,0 +1,47 @@+-- |Basic linear fit unit test. There is no noise in the data set, so+-- it is very unlikely that the correct model will not be found.+module Main where+import Control.Applicative+import Control.Lens (view)+import qualified Data.Foldable as F+import Data.Vector.Storable (Vector)+import qualified Data.Vector.Storable as V+import Linear+import Test.Framework (defaultMain)+import Test.Framework.Providers.HUnit (hUnitTestToTests)+import Test.HUnit (Test, (~?))+import Numeric.Ransac++type Point = V2 Float++sq :: Float -> Float+sq x = x * x++-- | Fit a 2D line to a collection of 'Point's.+fitLine :: Vector Point -> Maybe (V2 Float)+fitLine pts = (!* b) <$> inv22 a+ where sx = V.sum $ V.map (view _x) pts+ a = V2 (V2 (V.sum (V.map (sq . view _x) pts)) sx)+ (V2 sx (fromIntegral (V.length pts)))+ b = V2 (V.sum (V.map F.product pts))+ (V.sum (V.map (view _y) pts))++-- | Compute the error of a 'Point' with respect to a hypothesized+-- linear model.+ptError :: V2 Float -> Point -> Float+ptError (V2 m b) (V2 x y) = sq $ y - (m*x+b)++test1 :: Test+test1 = tst ~? "noise-free linear fit"+ where model = ransac 20 2 0.8 fitLine ptError (< 0.1) pts+ pts :: Vector Point+ pts = V.generate 100 mkPoint+ mkPoint i = let x = fromIntegral i * 0.1+ in V2 x (3 * x + 1)+ tst = do mm <- model+ return $ case mm of+ Nothing -> False+ Just (m,_) -> qd (V2 3 1) m < 0.1++main :: IO ()+main = defaultMain $ hUnitTestToTests test1