-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Most frequently used machine learning tools -- -- Please see the README on Github at -- https://github.com/masterdezign/Learning#readme @package Learning @version 0.0.1 -- |

Machine learning utilities

-- -- A micro library containing the most common machine learning tools. -- Check also the mltool package -- https://hackage.haskell.org/package/mltool. module Learning -- | A dataset representation for supervised learning data Dataset a b Dataset :: [a] -> [b] -> [(a, b)] -> Dataset a b [_samples] :: Dataset a b -> [a] [_labels] :: Dataset a b -> [b] [toList] :: Dataset a b -> [(a, b)] -- | Create a Dataset from list of samples (first) and labels -- (second) fromList :: [(a, b)] -> Dataset a b -- | Principal components analysis tools data PCA PCA :: Matrix Double -> (Vector Double -> Matrix Double) -> (Matrix Double -> Vector Double) -> PCA -- | Compression matrix U [_u] :: PCA -> Matrix Double -- | Compression function [_compress] :: PCA -> Vector Double -> Matrix Double -- | Inverse to compression function [_decompress] :: PCA -> Matrix Double -> Vector Double -- | Principal components analysis resulting in PCA tools pca :: Int -> [Vector Double] -> PCA -- | Compute the covariance matrix sigma and return its -- eigenvectors u' and eigenvalues s pca' :: [Vector Double] -> (Matrix Double, Vector Double) -- | Teacher matrix -- --
--   0 0 0 0 0
--   0 0 0 0 0
--   1 1 1 1 1 <- Desired class index is 2
--   0 0 0 0 0 <- Number of classes is 4
--           ^
--     5 repetitions
--   
type Teacher = Matrix Double -- | Create a binary Teacher matrix with ones row corresponding to -- the desired class index teacher :: Int -> Int -> Int -> Teacher -- | Classifier function that maps some network state with measurements as -- matrix columns and features as rows, into a categorical output. newtype Classifier a Classifier :: (Matrix Double -> a) -> Classifier a [classify] :: Classifier a -> Matrix Double -> a -- | Regressor function that maps some feature matrix into a continuous -- multidimensional output. The feature matrix is expected to have -- columns corresponding to measurements (data points) and rows, -- features. newtype Regressor Regressor :: (Matrix Double -> Matrix Double) -> Regressor [predict] :: Regressor -> Matrix Double -> Matrix Double -- | Linear readout (matrix) type Readout = Matrix Double -- | Perform supervised learning (ridge regression) and create a linear -- Classifier function. The regression is run with regularization -- parameter μ = 1e-4. learnClassifier :: (Storable a, Eq a) => Vector a -> Matrix Double -> Matrix Double -> Either String (Classifier a) -- | Perform supervised learning (ridge regression) and create a linear -- Regressor function. learnRegressor :: Matrix Double -> Matrix Double -> Either String Regressor -- | Create a linear Readout using the ridge regression. Similar to -- learnRegressor, but instead of a Regressor function a -- (already transposed) Readout matrix may be returned. learn' :: Matrix Double -> Matrix Double -> Maybe Readout -- | Evaluate the network state (nonlinear response) according to some -- Readout matrix. Used by classification strategies such as -- winnerTakesAll. scores :: Readout -> Matrix Double -> Vector Double -- | Winner-takes-all classification method winnerTakesAll :: (Storable a, Eq a) => Readout -> Vector a -> Classifier a -- | Error rate in %, an error measure for classification tasks -- --
--   >>> errorRate [1,2,3,4] [1,2,3,7]
--   25.0
--   
errorRate :: (Eq a, Fractional err) => [a] -> [a] -> err -- | Pairs of misclassified and correct values -- --
--   >>> errors $ zip ['x','y','z'] ['x','b','a']
--   [('y','b'),('z','a')]
--   
errors :: Eq a => [(a, a)] -> [(a, a)] -- | Accuracy of classification, 100% - errorRate -- --
--   >>> accuracy [1,2,3,4] [1,2,3,7]
--   75.0
--   
accuracy :: (Eq a, Fractional acc) => [a] -> [a] -> acc -- | Normalized root mean square error (NRMSE), one of the most common -- error measures for regression tasks nrmse :: (Storable a, Floating a) => Vector a -> Vector a -> a