-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Eigen C++ library (linear algebra: matrices, vectors, numerical solvers). -- @package eigen @version 1.1.2 module Data.Eigen.Internal class Cast a b cast :: Cast a b => a -> b performIO :: IO a -> a c_freeString :: CString -> IO () call :: IO CString -> IO () c_initParallel :: IO () c_setNbThreads :: CInt -> IO () c_add :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_sub :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_mul :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_transpose :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_inverse :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_adjoint :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_conjugate :: Ptr CDouble -> CInt -> CInt -> Ptr CDouble -> CInt -> CInt -> IO CString c_normalize :: Ptr CDouble -> CInt -> CInt -> IO CString c_norm :: Ptr CDouble -> CInt -> CInt -> IO CDouble c_squaredNorm :: Ptr CDouble -> CInt -> CInt -> IO CDouble c_blueNorm :: Ptr CDouble -> CInt -> CInt -> IO CDouble c_hypotNorm :: Ptr CDouble -> CInt -> CInt -> IO CDouble c_determinant :: Ptr CDouble -> CInt -> CInt -> IO CDouble instance Cast Int CInt instance Cast CInt Int instance Cast Double CDouble instance Cast CDouble Double module Data.Eigen.Matrix.Mutable -- | Mutable matrix. You can modify elements data MMatrix s MMatrix :: Int -> Int -> MVector s CDouble -> MMatrix s mm_rows :: MMatrix s -> Int mm_cols :: MMatrix s -> Int mm_vals :: MMatrix s -> MVector s CDouble type IOMatrix = MMatrix RealWorld type STMatrix s = MMatrix s -- | Creates a mutable matrix of the given dimension. Elements are -- initialized with 0. new :: PrimMonad m => Int -> Int -> m (MMatrix (PrimState m)) -- | Set all elements of the matrix to the given value set :: PrimMonad m => (MMatrix (PrimState m)) -> Double -> m () -- | Yield the element at the given position. read :: PrimMonad m => MMatrix (PrimState m) -> Int -> Int -> m Double -- | Replace the element at the given position. write :: PrimMonad m => MMatrix (PrimState m) -> Int -> Int -> Double -> m () -- | 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 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 -- | 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]] -- | craete matrix using generator function f :: row -> col -> val generate :: Int -> Int -> (Int -> Int -> Double) -> Matrix -- | 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 -- | return a - b add :: Matrix -> Matrix -> Matrix -- | return a + b sub :: Matrix -> Matrix -> Matrix -- | return a * b mul :: Matrix -> Matrix -> Matrix -- | 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 -- | conjugate of the matrix conjugate :: Matrix -> Matrix -- | transpose of the matrix transpose :: Matrix -> Matrix -- | nomalize the matrix by deviding it on its norm normalize :: Matrix -> Matrix -- | Apply a destructive operation to a matrix. The operation will be -- performed in place if it is safe to do so and will modify a copy of -- the matrix otherwise. modify :: (forall s. MMatrix s -> ST s ()) -> Matrix -> Matrix -- | Yield a mutable copy of the immutable matrix thaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m)) -- | Yield an immutable copy of the mutable matrix freeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix -- | Unsafely convert an immutable matrix to a mutable one without copying. -- The immutable matrix may not be used after this operation. unsafeThaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m)) -- | Unsafe convert a mutable matrix to an immutable one without copying. -- The mutable matrix may not be used after this operation. unsafeFreeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix 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 -- | solve :: Decomposition -> Matrix -> Matrix -> Matrix -- | relativeError :: Matrix -> Matrix -> Matrix -> Double -- | -- -- -- --
--   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