-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskel binding for Eigen library -- -- This module provides Haskell binding for Eigen C++ library. Eigen is a -- C++ template library for linear algebra: matrices, vectors, numerical -- solvers, and related algorithms. Eigen home page is -- http://eigen.tuxfamily.org/. -- -- Eigen is licensed under the MPL2, which is a simple weak copyleft -- license. Common questions about the MPL2 are answered in the official -- MPL2 FAQ at http://www.mozilla.org/MPL/2.0/FAQ.html. -- -- Note that currently, a few features in Eigen rely on third-party code -- licensed under the LGPL: SimplicialCholesky, AMD ordering, and -- constrained_cg. Such features are explicitly disabled by compiling -- Eigen with the EIGEN_MPL2_ONLY preprocessor symbol defined. -- -- Virtually any software may use Eigen. For example, closed-source -- software may use Eigen without having to disclose its own source code. -- Many proprietary and closed-source software projects are using Eigen -- right now, as well as many BSD-licensed projects. -- -- Note that ghci may fail with "unknown symbol ___dso_handle" -- error due to dynamic linking with C++ runtime. Consider to use ghc -- --make instead. Please let me know if you know any workaround for this -- issue. -- -- Some parts of documentation strings are based or replicate original -- Eigen documentation which is available at -- http://eigen.tuxfamily.org/dox/. @package eigen @version 1.0.0 module Data.Eigen.Internal data C_MatrixXd class Cast a b cast :: Cast a b => a -> b c_freeString :: CString -> IO () call :: IO CString -> IO () c_initParallel :: IO () c_setNbThreads :: CInt -> IO () c_create :: CInt -> CInt -> IO (Ptr C_MatrixXd) c_destroy :: FunPtr (Ptr C_MatrixXd -> IO ()) c_clone :: Ptr C_MatrixXd -> IO (Ptr C_MatrixXd) c_get :: Ptr CDouble -> Ptr C_MatrixXd -> CInt -> CInt -> IO CString c_set :: Ptr C_MatrixXd -> CInt -> CInt -> CDouble -> IO CString c_data :: Ptr C_MatrixXd -> IO (Ptr CDouble) c_rows :: Ptr C_MatrixXd -> IO CInt c_cols :: Ptr C_MatrixXd -> IO CInt c_copy :: Ptr C_MatrixXd -> Ptr C_MatrixXd -> IO () c_resize :: Ptr C_MatrixXd -> CInt -> CInt -> IO () c_add :: Ptr C_MatrixXd -> Ptr C_MatrixXd -> Ptr C_MatrixXd -> IO CString c_sub :: Ptr C_MatrixXd -> Ptr C_MatrixXd -> Ptr C_MatrixXd -> IO CString c_mul :: Ptr C_MatrixXd -> Ptr C_MatrixXd -> Ptr C_MatrixXd -> IO CString c_transpose :: Ptr C_MatrixXd -> IO CString c_inverse :: Ptr C_MatrixXd -> IO CString c_adjoint :: Ptr C_MatrixXd -> IO CString c_normalize :: Ptr C_MatrixXd -> IO CString c_norm :: Ptr C_MatrixXd -> IO CDouble c_squaredNorm :: Ptr C_MatrixXd -> IO CDouble c_blueNorm :: Ptr C_MatrixXd -> IO CDouble c_hypotNorm :: Ptr C_MatrixXd -> IO CDouble c_determinant :: Ptr C_MatrixXd -> IO CDouble instance Cast Int CInt instance Cast CInt Int instance Cast Double CDouble instance Cast CDouble Double -- | Some Eigen's algorithms can exploit the multiple cores present in your -- hardware. To this end, it is enough to enable OpenMP on your compiler, -- for instance: GCC: -fopenmp ICC: -openmp MSVC: check the respective -- option in the build properties. You can control the number of thread -- that will be used using using setNbThreads module Data.Eigen.Parallel -- | Must be call first when calling Eigen from multiple threads initParallel :: IO () -- | Sets the max number of threads reserved for Eigen setNbThreads :: Int -> IO () module Data.Eigen.Matrix.Mutable data MMatrix MMatrix :: ForeignPtr C_MatrixXd -> MMatrix mm_fp :: MMatrix -> ForeignPtr C_MatrixXd new :: Int -> Int -> IO MMatrix rows :: MMatrix -> IO Int cols :: MMatrix -> IO Int copy :: MMatrix -> MMatrix -> IO () clone :: MMatrix -> IO MMatrix resize :: MMatrix -> Int -> Int -> IO () get :: MMatrix -> Int -> Int -> IO Double set :: MMatrix -> Int -> Int -> Double -> IO () setRow :: MMatrix -> Int -> [Double] -> IO () setCol :: MMatrix -> Int -> [Double] -> IO () add :: MMatrix -> MMatrix -> MMatrix -> IO () sub :: MMatrix -> MMatrix -> MMatrix -> IO () mul :: MMatrix -> MMatrix -> MMatrix -> IO () inverse :: MMatrix -> IO () adjoint :: MMatrix -> IO () transpose :: MMatrix -> IO () normalize :: MMatrix -> IO () norm :: MMatrix -> IO Double blueNorm :: MMatrix -> IO Double hypotNorm :: MMatrix -> IO Double squaredNorm :: MMatrix -> IO Double determinant :: MMatrix -> IO Double with :: MMatrix -> (Ptr C_MatrixXd -> IO a) -> IO a module Data.Eigen.Matrix -- | constant Matrix class to be used in pure computations, uses the same -- column major memory layout as Eigen MatrixXd data Matrix Matrix :: Int -> Int -> Vector CDouble -> Matrix m_rows :: Matrix -> Int m_cols :: Matrix -> Int m_vals :: Matrix -> Vector CDouble -- | construct matrix from a list of rows, column count is detected as -- maximum row length fromList :: [[Double]] -> Matrix -- | converts matrix to a list of its rows toList :: Matrix -> [[Double]] -- | empty 0x0 matrix empty :: Matrix -- | matrix where all coeff are 0 zero :: Int -> Int -> Matrix -- | matrix where all coeff are 1 ones :: Int -> Int -> Matrix -- | square matrix with 1 on main diagonal and 0 elsewhere identity :: Int -> Matrix -- | matrix where all coeffs are filled with given value constant :: Int -> Int -> Double -> Matrix -- | number of columns for the matrix cols :: Matrix -> Int -- | number of rows for the matrix rows :: Matrix -> Int -- | matrix coefficient at specific row and col coeff :: Int -> Int -> Matrix -> Double -- | the minimum of all coefficients of matrix minCoeff :: Matrix -> Double -- | the maximum of all coefficients of matrix maxCoeff :: Matrix -> Double -- | list of coefficients for the given col col :: Int -> Matrix -> [Double] -- | list of coefficients for the given row row :: Int -> Matrix -> [Double] -- | extract rectangular block from matrix defined by startRow startCol -- blockRows blockCols block :: Int -> Int -> Int -> Int -> Matrix -> Matrix -- | top n rows of matrix topRows :: Int -> Matrix -> Matrix -- | bottom n rows of matrix bottomRows :: Int -> Matrix -> Matrix -- | left n columns of matrix leftCols :: Int -> Matrix -> Matrix -- | right n columns of matrix rightCols :: Int -> Matrix -> Matrix -- | for vectors, the l2 norm, and for matrices the Frobenius norm. In both -- cases, it consists in the square root of the sum of the square of all -- the matrix entries. For vectors, this is also equals to the square -- root of the dot product of this with itself. norm :: Matrix -> Double -- | for vectors, the squared l2 norm, and for matrices the Frobenius norm. -- In both cases, it consists in the sum of the square of all the matrix -- entries. For vectors, this is also equals to the dot product of this -- with itself. squaredNorm :: Matrix -> Double -- | the determinant of the matrix determinant :: Matrix -> Double -- | inverse of the matrix -- -- For small fixed sizes up to 4x4, this method uses cofactors. In the -- general case, this method uses class PartialPivLU inverse :: Matrix -> Matrix -- | adjoint of the matrix adjoint :: Matrix -> Matrix -- | transpose of the matrix transpose :: Matrix -> Matrix -- | nomalize the matrix by deviding it on its norm normalize :: Matrix -> Matrix -- | create a snapshot of mutable matrix freeze :: MMatrix -> IO Matrix -- | create mutable copy of the matrix thaw :: Matrix -> IO MMatrix -- | apply mutable operation to the mutable copy of the matrix and snapshot -- of this copy modify :: (MMatrix -> IO ()) -> Matrix -> Matrix -- | apply foreign operation to the mutable copy of the matrix and -- operation result with :: Matrix -> (Ptr C_MatrixXd -> IO a) -> IO a instance Num Matrix instance Show Matrix -- | The problem: You have a system of equations, that you have written as -- a single matrix equation -- --
-- Ax = b ---- -- Where A and b are matrices (b could be a vector, as a special case). -- You want to find a solution x. -- -- The solution: You can choose between various decompositions, depending -- on what your matrix A looks like, and depending on whether you favor -- speed or accuracy. However, let's start with an example that works in -- all cases, and is a good compromise: -- --
-- import Data.Eigen.Matrix -- import Data.Eigen.LA -- -- main = do -- let -- a = fromList [[1,2,3], [4,5,6], [7,8,10]] -- b = fromList [[3],[3],[4]] -- x = solve ColPivHouseholderQR a b -- putStrLn "Here is the matrix A:" >> print a -- putStrLn "Here is the vector b:" >> print b -- putStrLn "The solution is:" >> print x ---- -- produces the following output -- --
-- Here is the matrix A: -- Matrix 3x3 -- 1.0 2.0 3.0 -- 4.0 5.0 6.0 -- 7.0 8.0 10.0 -- -- Here is the vector b: -- Matrix 3x1 -- 3.0 -- 3.0 -- 4.0 -- -- The solution is: -- Matrix 3x1 -- -2.0000000000000004 -- 1.0000000000000018 -- 0.9999999999999989 ---- -- Checking if a solution really exists: Only you know what error margin -- you want to allow for a solution to be considered valid. -- -- You can compute relative error using norm (ax - b) / norm b -- formula or use relativeError function which provides the same -- calculation implemented slightly more efficient. module Data.Eigen.LA -- |
-- Decomposition Requirements on the matrix Speed Accuracy -- -- PartialPivLU Invertible ++ + -- FullPivLU None - +++ -- HouseholderQR None ++ + -- ColPivHouseholderQR None + ++ -- FullPivHouseholderQR None - +++ -- LLT Positive definite +++ + -- LDLT Positive or negative semidefinite +++ ++ -- JacobiSVD None - +++ -- -- The best way to do least squares solving for square matrices is with a SVD decomposition (JacobiSVD) --data Decomposition -- | LU decomposition of a matrix with partial pivoting. PartialPivLU :: Decomposition -- | LU decomposition of a matrix with complete pivoting. FullPivLU :: Decomposition -- | Householder QR decomposition of a matrix. HouseholderQR :: Decomposition -- | Householder rank-revealing QR decomposition of a matrix with -- column-pivoting. ColPivHouseholderQR :: Decomposition -- | Householder rank-revealing QR decomposition of a matrix with full -- pivoting. FullPivHouseholderQR :: Decomposition -- | Standard Cholesky decomposition (LL^T) of a matrix. LLT :: Decomposition -- | Robust Cholesky decomposition of a matrix with pivoting. LDLT :: Decomposition -- | Two-sided Jacobi SVD decomposition of a rectangular matrix. JacobiSVD :: Decomposition -- |
-- import Data.Eigen.LA -- main = print $ linearRegression [ -- [-4.32, 3.02, 6.89], -- [-3.79, 2.01, 5.39], -- [-4.01, 2.41, 6.01], -- [-3.86, 2.09, 5.55], -- [-4.10, 2.58, 6.32]] ---- -- produces the following output -- --
-- ([-2.3466569233817127,-0.2534897541434826,-0.1749653335680988],1.8905965120153139e-3) --linearRegression :: [[Double]] -> ([Double], Double) instance Show Decomposition instance Enum Decomposition