-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generic encoding of records -- -- Generic encoding of records. It currently provides a single, -- polymorphic function to encode sum types (i.e. categorical variables) -- as one-hot vectors. @package record-encode @version 0.2 -- | This library provides generic machinery (via GHC.Generics and -- `generics-sop`) to encode values of some algebraic type as points in a -- vector space. -- -- Processing datasets that have one or more categorical variables (which -- in other words are values of a sum type) typically requires a series -- of boilerplate transformations, and the encodeOneHot function -- provided here does precisely that. -- --
-- >>> :set -XDeriveGeneric ---- --
-- >>> import qualified GHC.Generics as G -- -- >>> import qualified Generics.SOP as SOP -- -- >>> import Data.Record.Encode ---- --
-- >>> data X = A | B | C deriving (G.Generic) -- -- >>> instance SOP.Generic X ---- --
-- >>> encodeOneHot B -- [0,1,0] --encodeOneHot :: forall a. G a => a -> OneHot -- | A one-hot encoding is a d-dimensional vector having a single component -- equal to 1 and all others equal to 0. data OneHot OH :: !Int -> !Int -> OneHot -- | Dimension of ambient space (i.e. number of categories) [oDim] :: OneHot -> !Int -- | Index of nonzero entry [oIx] :: OneHot -> !Int compareOH :: OneHot -> OneHot -> Maybe Ordering -- | Create a one-hot vector oneHotV :: Num a => OneHot -> Vector a -- | Constraints necessary to encodeOneHot a value. -- -- NB: GVariants is an internal typeclass, and this constraint is -- automatically satisfied if the type is an instance of Generic type G a = (GVariants (Rep a), Generic a, Generic a) instance GHC.Show.Show Data.Record.Encode.OneHot instance GHC.Classes.Eq Data.Record.Encode.OneHot instance GHC.Generics.Generic (Data.Record.Encode.X a) instance Generics.SOP.Universe.Generic (Data.Record.Encode.X a)