{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Reinforce.Spaces.State
( StateSpace(..)
, StateSpaceStatic(..)
) where
import Reinforce.Prelude
import qualified Data.Vector as V
import Numeric.LinearAlgebra.Static
class StateSpaceStatic s where
type Size s :: Nat
toR :: s -> R (Size s)
instance StateSpaceStatic () where
type Size () = 0
toR = const $ vector []
class StateSpace s where
toVector :: s -> Vector Double
fromVector :: MonadThrow m => Vector Double -> m s
instance StateSpace (Vector Double) where
toVector = id
fromVector = pure
instance Integral n => StateSpace (Vector n) where
toVector = fmap fromIntegral
fromVector = return . fmap round
instance StateSpace [Float] where
toVector = V.fromList . fmap realToFrac
fromVector = return . fmap double2Float . V.toList