hstatistics 0.1.0.3 → 0.1.0.4
raw patch · 11 files changed
+125/−86 lines, 11 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Numeric.GSL.Fitting.Linear: linear_est :: Double -> Double -> Double -> Double -> Double -> Double -> (Double, Double)
- Numeric.GSL.Fitting.Linear: linear :: Vector Double -> Vector Double -> (Vector Double, Vector Double, Matrix Double, Matrix Double, Matrix Double, Matrix Double)
+ Numeric.GSL.Fitting.Linear: linear :: Vector Double -> Vector Double -> (Double, Double, Double, Double, Double, Double)
- Numeric.GSL.Fitting.Linear: linear_w :: Vector Double -> Vector Double -> Vector Double -> (Vector Double, Vector Double, Matrix Double, Matrix Double, Matrix Double, Matrix Double)
+ Numeric.GSL.Fitting.Linear: linear_w :: Vector Double -> Vector Double -> Vector Double -> (Double, Double, Double, Double, Double, Double)
Files
- CHANGES +6/−2
- configure.hs +7/−1
- hstatistics.cabal +1/−1
- lib/Numeric/GSL/Distribution/Continuous.hs +5/−4
- lib/Numeric/GSL/Distribution/Discrete.hs +5/−4
- lib/Numeric/GSL/Fitting/Linear.hs +56/−25
- lib/Numeric/GSL/Histogram.hs +11/−16
- lib/Numeric/GSL/Histogram2D.hs +13/−14
- lib/Numeric/GSL/Permutation.hs +4/−3
- lib/Numeric/GSL/Statistics.hs +1/−1
- lib/Numeric/GSL/fitting-aux.c +16/−15
CHANGES view
@@ -6,5 +6,9 @@ updated to reflect exportation of check from Data.Packed.Development in hmatrix-0.9.3.0 -0.1.03: - added Numeric.GSL.Regression.Linear+0.1.0.3: + added Numeric.GSL.Fitting.Linear++0.1.0.4:+ fixed argument types in Numeric.GSL.Fitting.Linear+ removed redundant imports
configure.hs view
@@ -18,7 +18,7 @@ -} import System-import System.Directory(createDirectoryIfMissing)+import System.Directory(createDirectoryIfMissing,getCurrentDirectory,getDirectoryContents) import Data.List(isPrefixOf, intercalate) import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Configure@@ -96,6 +96,12 @@ cs x = x main = do+ dir <- getCurrentDirectory+ putStrLn $ "Current directory: " ++ dir++ files <- getDirectoryContents dir+ mapM_ putStrLn files+ putStr "Checking foreign libraries..." args <- getArgs
hstatistics.cabal view
@@ -1,5 +1,5 @@ Name: hstatistics-Version: 0.1.0.3+Version: 0.1.0.4 License: GPL License-file: LICENSE Copyright: (c) A.V.H. McPhail 2010
lib/Numeric/GSL/Distribution/Continuous.hs view
@@ -36,13 +36,14 @@ --import Numeric.LinearAlgebra.Linear -import Control.Monad(when)+--import Control.Monad(when) import Foreign hiding(shift)-import Foreign.ForeignPtr+--import Foreign.ForeignPtr --import Foreign.Marshal.Alloc(alloca)-import Foreign.C.Types(CInt,CChar)-import Foreign.C.String(newCString,peekCString)+--import Foreign.C.Types(CInt,CChar)+import Foreign.C.Types(CInt)+--import Foreign.C.String(newCString,peekCString) --import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
lib/Numeric/GSL/Distribution/Discrete.hs view
@@ -32,13 +32,14 @@ --import Numeric.LinearAlgebra.Linear -import Control.Monad(when)+--import Control.Monad(when) import Foreign hiding(shift)-import Foreign.ForeignPtr+--import Foreign.ForeignPtr --import Foreign.Marshal.Alloc(alloca)-import Foreign.C.Types(CInt,CUInt,CChar)-import Foreign.C.String(newCString,peekCString)+--import Foreign.C.Types(CInt,CUInt,CChar)+import Foreign.C.Types(CInt,CUInt)+--import Foreign.C.String(newCString,peekCString) --import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
lib/Numeric/GSL/Fitting/Linear.hs view
@@ -14,13 +14,13 @@ ----------------------------------------------------------------------------- module Numeric.GSL.Fitting.Linear (- linear, linear_w+ linear, linear_w, linear_est ) where ----------------------------------------------------------------------------- import Data.Packed.Vector-import Data.Packed.Matrix+--import Data.Packed.Matrix import Data.Packed.Development --import Numeric.LinearAlgebra.Linear@@ -28,7 +28,7 @@ --import Control.Monad(when) import Foreign-import Foreign.ForeignPtr+--import Foreign.ForeignPtr --import Foreign.Marshal.Alloc(alloca) import Foreign.C.Types(CInt) --import Foreign.C.String(newCString,peekCString)@@ -45,22 +45,27 @@ -- | fits the model Y = C X linear :: Vector Double -- ^ x data -> Vector Double -- ^ y data- -> (Vector Double,Vector Double,Matrix Double,Matrix Double,Matrix Double,Matrix Double) -- ^ (c_0,c_1,cov_00,cov_01,cov_11,chi_sq)+ -> (Double,Double,Double,Double,Double,Double) -- ^ (c_0,c_1,cov_00,cov_01,cov_11,chi_sq) linear x y = unsafePerformIO $ do- let s = dim x- c0 <- createVector 1- c1 <- createVector 1- cov00 <- createMatrix RowMajor s s- cov01 <- createMatrix RowMajor s s- cov11 <- createMatrix RowMajor s s- chi_sq <- createMatrix RowMajor s s- app8 fitting_linear vec x vec y vec c0 vec c1 mat cov00 mat cov01 mat cov11 mat chi_sq "linear"- return (c0,c1,cov00,cov01,cov11,chi_sq)+ alloca $ \c0 ->+ alloca $ \c1 ->+ alloca $ \chi_sq -> + alloca $ \cov00 -> + alloca $ \cov01 -> + alloca $ \cov11 -> do+ app2 (fitting_linear c0 c1 chi_sq cov00 cov01 cov11) vec x vec y "linear"+ c0' <- peek c0+ c1' <- peek c1+ cov00' <- peek cov00+ cov01' <- peek cov01+ cov11' <- peek cov11+ chi_sq' <- peek chi_sq+ return (c0',c1',cov00',cov01',cov11',chi_sq') ----------------------------------------------------------------------------- -foreign import ccall "fitting-aux.h linear" fitting_linear :: CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> IO CInt+foreign import ccall "fitting-aux.h linear" fitting_linear :: Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> IO CInt ----------------------------------------------------------------------------- @@ -68,21 +73,47 @@ linear_w :: Vector Double -- ^ x data -> Vector Double -- ^ x weights -> Vector Double -- ^ y data- -> (Vector Double,Vector Double,Matrix Double,Matrix Double,Matrix Double,Matrix Double) -- ^ (c_0,c_1,cov_00,cov_01,cov_11,chi_sq)+ -> (Double,Double,Double,Double,Double,Double) -- ^ (c_0,c_1,cov_00,cov_01,cov_11,chi_sq) linear_w x w y = unsafePerformIO $ do- let s = dim x- c0 <- createVector 1- c1 <- createVector 1- cov00 <- createMatrix RowMajor s s- cov01 <- createMatrix RowMajor s s- cov11 <- createMatrix RowMajor s s- chi_sq <- createMatrix RowMajor s s- app9 fitting_linear_w vec x vec w vec y vec c0 vec c1 mat cov00 mat cov01 mat cov11 mat chi_sq "linear_w"- return (c0,c1,cov00,cov01,cov11,chi_sq)+ alloca $ \c0 ->+ alloca $ \c1 ->+ alloca $ \chi_sq ->+ alloca $ \cov00 -> + alloca $ \cov01 -> + alloca $ \cov11 -> do+ app3 (fitting_linear_w c0 c1 chi_sq cov00 cov01 cov11) vec x vec w vec y "linear_w"+ c0' <- peek c0+ c1' <- peek c1+ cov00' <- peek cov00+ cov01' <- peek cov01+ cov11' <- peek cov11+ chi_sq' <- peek chi_sq+ return (c0',c1',cov00',cov01',cov11',chi_sq') +----------------------------------------------------------------------------- +foreign import ccall "fitting-aux.h linear_weighted" fitting_linear_w :: Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> IO CInt+ ----------------------------------------------------------------------------- -foreign import ccall "fitting-aux.h linear_weighted" fitting_linear_w :: CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> IO CInt+-- | computes the fitted function and standard deviation at the input point+linear_est :: Double -- ^ x data point+ -> Double -- ^ c0+ -> Double -- ^ c1+ -> Double -- ^ cov00+ -> Double -- ^ cov01+ -> Double -- ^ cov11+ -> (Double,Double) -- ^ (y,error)+linear_est x c0 c1 cov00 cov01 cov11 = unsafePerformIO $ do+ alloca $ \y ->+ alloca $ \e -> do+ check "linear_est" $ fitting_linear_est x c0 c1 cov00 cov01 cov11 y e+ y' <- peek y+ e' <- peek e+ return (y',e')++-----------------------------------------------------------------------------++foreign import ccall "fitting-aux.h linear_estimate" fitting_linear_est :: Double -> Double -> Double -> Double -> Double -> Double -> Ptr Double -> Ptr Double -> IO CInt -----------------------------------------------------------------------------
lib/Numeric/GSL/Histogram.hs view
@@ -40,13 +40,14 @@ --import Numeric.LinearAlgebra.Linear -import Control.Monad+--import Control.Monad import Foreign hiding(shift)-import Foreign.ForeignPtr-import Foreign.Marshal.Alloc(alloca)+--import Foreign.ForeignPtr+--import Foreign.Marshal.Alloc(alloca) import Foreign.C.Types(CInt,CChar)-import Foreign.C.String(newCString,peekCString)+--import Foreign.C.String(newCString,peekCString)+import Foreign.C.String(newCString) --import Control.Monad(when) --import GHC.ForeignPtr (mallocPlainForeignPtrBytes)@@ -108,7 +109,7 @@ fromLimitsIO n (l,u) = do h <- histogram_new (fromIntegral n) h' <- newForeignPtr histogram_free h- withForeignPtr h' (\f -> histogram_set_ranges_uniform f l u)+ check "set_ranges_uniform" $ withForeignPtr h' (\f -> histogram_set_ranges_uniform f l u) return $ H n h' foreign import ccall "gsl-histogram.h gsl_histogram_set_ranges" histogram_set_ranges :: HistHandle -> CInt -> Ptr Double -> IO CInt@@ -190,9 +191,7 @@ -- | add 1.0 to the correct bin, fails silently if the value is outside the range incrementIO :: Histogram -> Double -> IO ()-incrementIO (H _ h) x = do- withForeignPtr h (\f -> histogram_increment f x)- return ()+incrementIO (H _ h) x = withForeignPtr h (\f -> check "increment" $ histogram_increment f x) -- | add 1.0 to the correct bin for each element of the vector, fails silently if the value is outside the range incrementListIO :: Histogram -> [Double] -> IO ()@@ -206,9 +205,7 @@ -- | adds the weight (second Double) to the bin appropriate for the value (first Double) accumulateIO :: Histogram -> Double -> Double -> IO ()-accumulateIO (H _ h) x w = do- withForeignPtr h (\f -> histogram_accumulate f x w)- return ()+accumulateIO (H _ h) x w = withForeignPtr h (\f -> check "accumulate" $ histogram_accumulate f x w) -- | add the weight (snd) to the correct bin for each (fst) element of the list, fails silently if the value is outside the range accumulateListIO :: Histogram -> [(Double,Double)] -> IO ()@@ -232,7 +229,7 @@ getRange (H _ h) b = unsafePerformIO $ do alloca $ \l -> alloca $ \u -> do- withForeignPtr h (\f -> histogram_get_range f (fromIntegral b) l u)+ check "get_range" $ withForeignPtr h (\f -> histogram_get_range f (fromIntegral b) l u) l' <- peek l u' <- peek u return (l',u')@@ -251,9 +248,7 @@ -- | reset all the bins to zero reset :: Histogram -> IO ()-reset (H _ h) = do- withForeignPtr h histogram_reset- return ()+reset (H _ h) = withForeignPtr h histogram_reset foreign import ccall "gsl-histogram.h gsl_histogram_increment" histogram_increment :: HistHandle -> Double -> IO CInt foreign import ccall "gsl-histogram.h gsl_histogram_accumulate" histogram_accumulate :: HistHandle -> Double -> Double -> IO CInt@@ -458,7 +453,7 @@ p <- histogram_pdf_new $ fromIntegral b p' <- newForeignPtr histogram_pdf_free p withForeignPtr p' $ \p'' -> - withForeignPtr h $ \h' -> histogram_pdf_init p'' h'+ withForeignPtr h $ \h' -> check "pdf_init" $ histogram_pdf_init p'' h' return $ P p' -- | given a randomm from the uniform distribution [0,1], draw a random sample from the PDF
lib/Numeric/GSL/Histogram2D.hs view
@@ -41,14 +41,15 @@ --import Numeric.LinearAlgebra.Linear -import Control.Monad+--import Control.Monad+--import Control.Monad(when) import Foreign hiding(shift)-import Foreign.ForeignPtr-import Foreign.Marshal.Alloc(alloca)+--import Foreign.ForeignPtr+--import Foreign.Marshal.Alloc(alloca) import Foreign.C.Types(CInt,CChar)-import Foreign.C.String(newCString,peekCString)---import Control.Monad(when)+--import Foreign.C.String(newCString,peekCString)+import Foreign.C.String(newCString) --import GHC.ForeignPtr (mallocPlainForeignPtrBytes) @@ -114,7 +115,7 @@ fromLimitsIO nx ny (lx,ux) (uy,ly) = do h <- histogram2d_new (fromIntegral nx) (fromIntegral ny) h' <- newForeignPtr histogram2d_free h- withForeignPtr h' (\f -> histogram2d_set_ranges_uniform f lx ux ly uy)+ check "set_ranges_uniform" $ withForeignPtr h' (\f -> histogram2d_set_ranges_uniform f lx ux ly uy) return $ H nx ny h' foreign import ccall "gsl-histogram2d.h gsl_histogram2d_set_ranges" histogram2d_set_ranges :: Hist2DHandle -> Ptr Double -> CInt -> Ptr Double -> CInt -> IO CInt@@ -203,7 +204,7 @@ -- | add 1.0 to the correct bin, fails silently if the value is outside the range incrementIO :: Histogram2D -> Double -> Double -> IO () incrementIO (H _ _ h) x y = do- withForeignPtr h (\f -> histogram2d_increment f x y)+ check "increment" $ withForeignPtr h (\f -> histogram2d_increment f x y) return () -- | add 1.0 to the correct bin for each element of the vector pair, fails silently if the value is outside the range@@ -219,7 +220,7 @@ -- | Adds the weight (third Double) to the bin appropriate for the value (first two Doubles) accumulateIO :: Histogram2D -> Double -> Double -> Double -> IO () accumulateIO (H _ _ h) x y w = do- withForeignPtr h (\f -> histogram2d_accumulate f x y w)+ check "accumulate" $ withForeignPtr h (\f -> histogram2d_accumulate f x y w) return () -- | add the weight (third) to the correct bin for each vector pair element, fails silently if the value is outside the range@@ -242,7 +243,7 @@ getXRange (H _ _ h) b = unsafePerformIO $ do alloca $ \l -> alloca $ \u -> do- withForeignPtr h (\f -> histogram2d_get_xrange f (fromIntegral b) l u)+ check "get_xrange" $ withForeignPtr h (\f -> histogram2d_get_xrange f (fromIntegral b) l u) l' <- peek l u' <- peek u return (l',u')@@ -252,7 +253,7 @@ getYRange (H _ _ h) b = unsafePerformIO $ do alloca $ \l -> alloca $ \u -> do- withForeignPtr h (\f -> histogram2d_get_yrange f (fromIntegral b) l u)+ check "get_yrange" $ withForeignPtr h (\f -> histogram2d_get_yrange f (fromIntegral b) l u) l' <- peek l u' <- peek u return (l',u')@@ -283,9 +284,7 @@ -- | reset all the bins to zero reset :: Histogram2D -> IO ()-reset (H _ _ h) = do- withForeignPtr h histogram2d_reset- return ()+reset (H _ _ h) = withForeignPtr h histogram2d_reset foreign import ccall "gsl-histogram2d.h gsl_histogram2d_increment" histogram2d_increment :: Hist2DHandle -> Double -> Double -> IO CInt foreign import ccall "gsl-histogram2d.h gsl_histogram2d_accumulate" histogram2d_accumulate :: Hist2DHandle -> Double -> Double -> Double -> IO CInt@@ -520,7 +519,7 @@ p' <- newForeignPtr histogram2d_pdf_free p withForeignPtr p' $ \p'' -> withForeignPtr h $ \h' -> do- histogram2d_pdf_init p'' h'+ check "pdf_init" $ histogram2d_pdf_init p'' h' return $ P p' -- | given a randomm from the uniform distribution [0,1], draw a random sample from the PDF
lib/Numeric/GSL/Permutation.hs view
@@ -37,13 +37,14 @@ --import Numeric.LinearAlgebra.Linear -import Control.Monad(when)+--import Control.Monad(when) import Foreign hiding(shift)-import Foreign.ForeignPtr+--import Foreign.ForeignPtr --import Foreign.Marshal.Alloc(alloca) import Foreign.C.Types(CInt,CChar)-import Foreign.C.String(newCString,peekCString)+--import Foreign.C.String(newCString,peekCString)+import Foreign.C.String(newCString) --import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
lib/Numeric/GSL/Statistics.hs view
@@ -50,7 +50,7 @@ import Foreign import Foreign.C.Types(CInt)-import Foreign.Marshal.Alloc(alloca)+--import Foreign.Marshal.Alloc(alloca) -----------------------------------------------------------------------------
lib/Numeric/GSL/fitting-aux.c view
@@ -1,28 +1,29 @@ #include <gsl/gsl_fit.h> -int linear(int xs, const double* x, int ys, const double* y,- int c0s, double* c0, int c1s, double* c1,- int cov00x, int cov00y, double* cov00,- int cov01x, int cov01y, double* cov01,- int cov11x, int cov11y, double* cov11,- int chi_sqx, int chi_sqy, double* chi_sq)+int linear(double* c0, double* c1, double* chi_sq,+ double* cov00, double* cov01, double* cov11,+ int xs, const double* x, int ys, const double* y) {- if (xs != ys || xs != c0s || xs != c1s) return 2000; //BAD_SIZE+ if (xs != ys) return 2000; //BAD_SIZE return gsl_fit_linear(x,1,y,1,xs,c0,c1,cov00,cov01,cov11,chi_sq); } -int linear_weighted(int xs, const double* x, int ws, const double * w, - int ys, const double* y,- int c0s, double* c0, int c1s, double* c1,- int cov00x, int cov00y, double* cov00,- int cov01x, int cov01y, double* cov01,- int cov11x, int cov11y, double* cov11,- int chi_sqx, int chi_sqy, double* chi_sq)+int linear_weighted(double* c0, double* c1, double* chi_sq,+ double* cov00, double* cov01, double* cov11,+ int xs, const double* x, + int ws, const double * w, + int ys, const double* y) {- if (xs != ys || xs != ws || xs != c0s || xs != c1s) return 2000; //BAD_SIZE+ if (xs != ys || xs != ws) return 2000; //BAD_SIZE return gsl_fit_wlinear(x,1,w,1,y,1,xs,c0,c1,cov00,cov01,cov11,chi_sq); } +int linear_estimate(double x, double c0, double c1, + double cov00, double cov01, double cov11,+ double* y, double* e)+{+ return gsl_fit_linear_est(x,c0,c1,cov00,cov01,cov11,y,e);+}