packages feed

hstatistics 0.1.0.4 → 0.1.0.5

raw patch · 5 files changed

+131/−5 lines, 5 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Numeric.GSL.Fitting.Linear: multifit :: Matrix Double -> Vector Double -> (Vector Double, Matrix Double, Double)
+ Numeric.GSL.Fitting.Linear: multifit_est :: Vector Double -> Vector Double -> Matrix Double -> (Double, Double)
+ Numeric.GSL.Fitting.Linear: multifit_w :: Matrix Double -> Vector Double -> Vector Double -> (Vector Double, Matrix Double, Double)

Files

CHANGES view
@@ -8,7 +8,13 @@  0.1.0.3:		 		added Numeric.GSL.Fitting.Linear+		attempt to fix problem on hackage with configure (localBuild "dist")  0.1.0.4: 		fixed argument types in Numeric.GSL.Fitting.Linear 		removed redundant imports+		attempt to fix problem on hackage with configure (printCurrentDirectory)++0.1.0.5:+		added multifit to Numeric.GSL.Fitting.Linear+		attempt to fix problem on hackage with configure (removed printCurrentDirectory)
configure.hs view
@@ -99,8 +99,8 @@     dir <- getCurrentDirectory     putStrLn $ "Current directory: " ++ dir -    files <- getDirectoryContents dir-    mapM_ putStrLn files+--    files <- getDirectoryContents dir+--    mapM_ putStrLn files      putStr "Checking foreign libraries..." 
hstatistics.cabal view
@@ -1,5 +1,5 @@ Name:               hstatistics-Version:            0.1.0.4+Version:            0.1.0.5 License:            GPL License-file:       LICENSE Copyright:          (c) A.V.H. McPhail 2010
lib/Numeric/GSL/Fitting/Linear.hs view
@@ -14,13 +14,14 @@ -----------------------------------------------------------------------------  module Numeric.GSL.Fitting.Linear (-                                   linear, linear_w, linear_est+                                   linear, linear_w, linear_est,+                                   multifit, multifit_w, multifit_est                              ) where  -----------------------------------------------------------------------------  import Data.Packed.Vector---import Data.Packed.Matrix+import Data.Packed.Matrix import Data.Packed.Development  --import Numeric.LinearAlgebra.Linear@@ -115,5 +116,66 @@ -----------------------------------------------------------------------------  foreign import ccall "fitting-aux.h linear_estimate" fitting_linear_est :: Double -> Double -> Double -> Double -> Double -> Double -> Ptr Double -> Ptr Double -> IO CInt++-----------------------------------------------------------------------------++-- | fit the model Y = C X, with design matrix X+-- |    X is a design matrix X_{ij} = x_j(i) with i observations and p predictors +-- |      a polynomial would be X_{ij} = x_i^j+-- |      a fourier series would be X_{ij} = sin (\omega_j x_i)+multifit :: Matrix Double          -- ^ design matrix (X)+         -> Vector Double          -- ^ observations+         -> (Vector Double,Matrix Double,Double)   -- ^ (coefficients,covariance,chi_sq)+multifit x y = unsafePerformIO $ do+               let ys = dim y +               cov <- createMatrix RowMajor ys ys +               p <- createVector ys +               alloca$ \chi_sq -> do+                   app4 (fitting_multifit chi_sq) mat x vec y vec p mat cov "multifit"+                   chi_sq' <- peek chi_sq+                   return (p,cov,chi_sq')++-----------------------------------------------------------------------------++foreign import ccall "fitting_aux.h multifit" fitting_multifit :: Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> IO CInt++-----------------------------------------------------------------------------++-- | fit the model Y = C X, with design matrix X, and x weighted+multifit_w :: Matrix Double          -- ^ design matrix (X)+           -> Vector Double          -- ^ weights +           -> Vector Double          -- ^ observations+           -> (Vector Double,Matrix Double,Double)   -- ^ (coefficients,covariance,chi_sq)+multifit_w x w y = unsafePerformIO $ do+                   let ys = dim y +                   cov <- createMatrix RowMajor ys ys +                   p <- createVector ys +                   alloca$ \chi_sq -> do+                       app5 (fitting_multifit_w chi_sq) mat x vec w vec y vec p mat cov "multifit"+                       chi_sq' <- peek chi_sq+                       return (p,cov,chi_sq')++-----------------------------------------------------------------------------++foreign import ccall "fitting_aux.h multifit_weighted" fitting_multifit_w :: Ptr Double -> CInt -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> IO CInt++-----------------------------------------------------------------------------++-- | computes the fitted function and standard deviation at the input point+multifit_est :: Vector Double     -- ^ input point+             -> Vector Double     -- ^ the coefficients+             -> Matrix Double     -- ^ the covariance matrix+             -> (Double,Double)   -- ^ (y,y_error_+multifit_est x c cov = unsafePerformIO $ do+                       alloca $ \y ->+                           alloca $ \e -> do+                               app3 (fitting_multifit_est y e) vec x vec c mat cov "multifit_estimate"+                               y' <- peek y+                               e' <- peek e+                               return (y',e')++-----------------------------------------------------------------------------++foreign import ccall "fitting_aux.h multifit_estimate" fitting_multifit_est :: Ptr Double -> Ptr Double -> CInt -> Ptr Double -> CInt -> Ptr Double -> CInt -> CInt -> Ptr Double -> IO CInt  -----------------------------------------------------------------------------
lib/Numeric/GSL/fitting-aux.c view
@@ -1,5 +1,9 @@ #include <gsl/gsl_fit.h>+#include <gsl/gsl_multifit.h> +#include <gsl/gsl_vector.h>+#include <gsl/gsl_matrix.h>+ 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)@@ -26,4 +30,58 @@ 		    double* y, double* e) {   return gsl_fit_linear_est(x,c0,c1,cov00,cov01,cov11,y,e);+}++int multifit(double* chi_sq,+	     int xrs, int xcs, const double* x,+	     int ys, const double* y,+	     int cs, double* c,+	     int covrs, int covcs, double* cov)+{+  gsl_multifit_linear_workspace* wsp = gsl_multifit_linear_alloc(xrs,xcs);++  gsl_matrix_const_view X = gsl_matrix_const_view_array(x,xrs,xcs);+  gsl_vector_const_view Y = gsl_vector_const_view_array(y,ys);+  gsl_vector_view C = gsl_vector_view_array(c,cs);+  gsl_matrix_view V = gsl_matrix_view_array(cov,covrs,covcs);++  int err = gsl_multifit_linear(&X.matrix,&Y.vector,&C.vector,&V.matrix,chi_sq,wsp);++  gsl_multifit_linear_free(wsp);++  return err;+}++int multifit_weighted(double* chi_sq,+		      int xrs, int xcs, const double* x,+		      int ws, const double* w,+		      int ys, const double* y,+		      int cs, double* c,+		      int covrs, int covcs, double* cov)+{+  gsl_multifit_linear_workspace* wsp = gsl_multifit_linear_alloc(xrs,xcs);++  gsl_matrix_const_view X = gsl_matrix_const_view_array(x,xrs,xcs);+  gsl_vector_const_view W = gsl_vector_const_view_array(w,ws);+  gsl_vector_const_view Y = gsl_vector_const_view_array(y,ys);+  gsl_vector_view C = gsl_vector_view_array(c,cs);+  gsl_matrix_view V = gsl_matrix_view_array(cov,covrs,covcs);++  int err = gsl_multifit_wlinear(&X.matrix,&W.vector,&Y.vector,&C.vector,&V.matrix,chi_sq,wsp);++  gsl_multifit_linear_free(wsp);++  return err;+}++int multifit_estimate(double* y, double* e,+		      int xs, const double* x,+		      int cs, double* c,+		      int covrs, int covcs, double* cov)+{+  gsl_vector_const_view X = gsl_vector_const_view_array(x,xs);+  gsl_vector_const_view C = gsl_vector_const_view_array(c,cs);+  gsl_matrix_const_view V = gsl_matrix_const_view_array(cov,covrs,covcs);++  return gsl_multifit_linear_est(&X.vector,&C.vector,&V.matrix,y,e); }