edelwace-0.1.0.0: HaskTorch Reinforcement Learning Agents for GACE
Safe HaskellNone
LanguageHaskell2010

Lib

Description

Utility and Helper functions for EDELWACE

Synopsis

Documentation

data Algorithm Source #

Deep Reinforcement Learning Algorithm

Constructors

SAC

Soft Actor-Critic

TD3

Twin Delayed Deep Deterministic Policy Gradient

PPO

Proximal Policy Optimization

Instances

Instances details
Eq Algorithm Source # 
Instance details

Defined in Lib

Read Algorithm Source # 
Instance details

Defined in Lib

Show Algorithm Source # 
Instance details

Defined in Lib

foldLoop' :: Int -> (a -> Int -> IO a) -> a -> IO a Source #

Swaps the arguments of HaskTorch's foldLoop around

nanToNum :: Float -> Float -> Float -> Tensor -> Tensor Source #

Because snake_case sucks

nanToNum' :: Tensor -> Tensor Source #

Default limits for nanToNum

nanToNum'' :: Tensor -> Tensor Source #

Default limits for nanToNum (0.0)

fullLike' :: Tensor -> Float -> Tensor Source #

GPU Tensor filled with Float value

indexSelect'' :: Int -> [Int] -> Tensor -> Tensor Source #

Select index with [Int] from GPU tensor

where'' :: Tensor -> (Tensor -> Tensor) -> Tensor -> Tensor Source #

Torch.where' with fixed type for where'

repeatInterleave' :: Int -> Tensor -> Tensor -> Tensor Source #

Syntactic sugar for HaskTorch's repeatInterleave so it can more easily be fmapped.

both :: (a -> b) -> Either a a -> b Source #

Apply same function to both Left and Right

both' :: (a -> b) -> Either a a -> Either b b Source #

Apply same function to both Left and Right and put back into Either

range :: Int -> [Int] Source #

Range from 0 to n - 1

fst' :: (a, b, c) -> a Source #

First of triple

splits :: [Int] -> [[Int]] Source #

Helper function creating split indices

splits' :: [Int] -> [Tensor] Source #

Helper function creating split indices as gpu int tensor

splitDim :: Int -> Tensor -> [Tensor] Source #

Split Tensor into list of Tensors along dimension

currentTimeStamp :: String -> IO String Source #

Current Timestamp as formatted string

currentTimeStamp' :: IO String Source #

Current Timestamp with default formatting: "%Y%m%d-%H%M%S"

createModelArchiveDir :: String -> IO String Source #

Create a model archive directory for the given algorithm

saveOptim :: Adam -> FilePath -> IO () Source #

Optimizer moments at given prefix

loadOptim :: Int -> Float -> Float -> FilePath -> IO Adam Source #

Load Optimizer State

weightLimit :: Linear -> Float Source #

Calculate weight Limits based on Layer Dimensions

data Initializer Source #

Type of weight initialization

Constructors

Normal

Normally distributed weights

Uniform

Uniformally distributed weights

XavierNormal

Using T.xavierNormal

XavierUniform

Using T.xavierUniform

KaimingNormal

Using T.kaimingNormal

KaimingUniform

Using T.kaimingUniform

Dirac 
Eye 
Ones 
Zeros 
Constant 

initWeights :: Initializer -> Float -> Float -> [Int] -> IO IndependentTensor Source #

Weights for a layer given limits and dimensions.

weightInit :: Initializer -> Float -> Float -> Linear -> IO Linear Source #

Initialize Weights of Linear Layer

weightInit' :: Initializer -> Float -> Float -> Linear -> IO Linear Source #

Initialize Weights and Bias of Linear Layer

weightInitUniform :: Float -> Float -> Linear -> IO Linear Source #

Initialize weights uniformally given upper and lower bounds

weightInitUniform' :: Linear -> IO Linear Source #

Initialize weights uniformally based on Fan In

weightInitNormal :: Float -> Float -> Linear -> IO Linear Source #

Initialize weights normally given mean and std bounds

weightInitNormal' :: Linear -> IO Linear Source #

Initialize weights normally based on Fan In

softUpdate :: Tensor -> Tensor -> Tensor -> Tensor Source #

Softly update parameters from Online Net to Target Net

softSync :: Parameterized f => Tensor -> f -> f -> IO f Source #

Softly copy parameters from Online Net to Target Net

copySync :: Parameterized f => f -> f -> f Source #

Hard Copy of Parameter from one net to the other

gpu :: Device Source #

GPU 1

cpu :: Device Source #

CPU 0

dataType :: DType Source #

Default Tensor Data Type

toTensor :: TensorLike a => a -> Tensor Source #

Convert an Array to a Tensor on GPU

toTensor' :: TensorLike a => a -> Tensor Source #

Convert an Array to a Tensor on CPU

toIntTensor :: TensorLike a => a -> Tensor Source #

Convert an Array to a Tensor on GPU

toIntTensor' :: TensorLike a => a -> Tensor Source #

Convert an Array to a Tensor on CPU

emptyTensor :: Tensor Source #

Create an empty Float Tensor on GPU

emptyTensor' :: Tensor Source #

Create an empty Float Tensor on CPU

toScalar :: Float -> Tensor Source #

Convert a Scalar to a Tensor on GPU

toScalar' :: Float -> Tensor Source #

Convert a Scalar to a Tensor on CPU

toDoubleGPU :: forall a. HasTypes a Tensor => a -> a Source #

Convert model to Double on GPU

toDoubleGPU' :: forall a. HasTypes a Tensor => a -> a Source #

Convert model to Double on CPU

toFloatGPU :: forall a. HasTypes a Tensor => a -> a Source #

Convert model to Float on CPU

toFloatCPU :: forall a. HasTypes a Tensor => a -> a Source #

Convert model to Float on CPU

randomInts :: Int -> Int -> Int -> IO Tensor Source #

Generate a Tensor of random Integers on GPU

randomInts' :: Int -> Int -> Int -> IO Tensor Source #

Generate a Tensor of random Integers on CPU

normal' :: [Int] -> IO Tensor Source #

Generate Normally Distributed Random values given dimensions

normal :: Tensor -> Tensor -> IO Tensor Source #

Generate Normally Distributed Random values given μs and σs

uniform' :: [Int] -> Float -> Float -> IO Tensor Source #

Generate Uniformally distributed values in a given range

rescale :: Tensor -> Tensor Source #

Rescale tensor s.t. mean = 0.0 and std = 1.0

httpOptions :: Options Source #

HTTP options for Hym server communication, sometimes simulations can take a while, therefore we wait ...

data Info Source #

Info object gotten form stepping

Constructors

Info 

Fields

Instances

Instances details
Show Info Source # 
Instance details

Defined in Lib

Methods

showsPrec :: Int -> Info -> ShowS #

show :: Info -> String #

showList :: [Info] -> ShowS #

Generic Info Source # 
Instance details

Defined in Lib

Associated Types

type Rep Info :: Type -> Type #

Methods

from :: Info -> Rep Info x #

to :: Rep Info x -> Info #

ToJSON Info Source # 
Instance details

Defined in Lib

FromJSON Info Source # 
Instance details

Defined in Lib

type Rep Info Source # 
Instance details

Defined in Lib

type Rep Info = D1 ('MetaData "Info" "Lib" "edelwace-0.1.0.0-NlkYKOSwr4E6F4MQQAmdJ" 'False) (C1 ('MetaCons "Info" 'PrefixI 'True) (S1 ('MetaSel ('Just "observations") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [String]) :*: S1 ('MetaSel ('Just "actions") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [String])))

data Step Source #

Single Environment Step

Constructors

Step 

Fields

Instances

Instances details
Show Step Source # 
Instance details

Defined in Lib

Methods

showsPrec :: Int -> Step -> ShowS #

show :: Step -> String #

showList :: [Step] -> ShowS #

Generic Step Source # 
Instance details

Defined in Lib

Associated Types

type Rep Step :: Type -> Type #

Methods

from :: Step -> Rep Step x #

to :: Rep Step x -> Step #

ToJSON Step Source # 
Instance details

Defined in Lib

FromJSON Step Source # 
Instance details

Defined in Lib

type Rep Step Source # 
Instance details

Defined in Lib

type HymURL = String Source #

Base Route to Hym Server

data ActionSpace Source #

Possible Action Spaces

Constructors

Continuous

Continuous Action Space

Discrete

Discrete Action Space

Instances

Instances details
Eq ActionSpace Source # 
Instance details

Defined in Lib

Show ActionSpace Source # 
Instance details

Defined in Lib

mapToTensor :: Map Int [Float] -> Tensor Source #

Convert a Map to a Tensor where Pool index is a dimension on GPU

mapToTensor' :: Map Int [Float] -> Tensor Source #

Convert a Map to a Tensor where Pool index is a dimension on CPU

tensorToMap :: Tensor -> Map Int [Float] Source #

Convert Tensor to Map (Continuous action spaces) on GPU

tensorToMap' :: Tensor -> Map Int Int Source #

Convert Tensor to Map (Discrete action spaces) on CPU

stepsToTuple :: Map Int Step -> (Tensor, Tensor, Tensor, [Info]) Source #

Convert the Pooled Step Map to a Tuple on GPU

stepsToTuple' :: Map Int Step -> (Tensor, Tensor, Tensor, [Info]) Source #

Convert the Pooled Step Map to a Tuple on CPU

hymGet :: HymURL -> String -> IO ByteString Source #

Generic HTTP GET Request to Hym Server

hymPost :: HymURL -> String -> Value -> IO ByteString Source #

Send a POST Request to a Hym Server

hymPoolMap :: HymURL -> String -> IO (Map Int (Map String Float)) Source #

Convert a JSON Response from an ACE Server to a Map: String Float

hymPoolMap' :: HymURL -> String -> IO (Map Int (Map String Bool)) Source #

Convert a JSON Response from an ACE Server to a Map: String Bool

hymPoolList :: HymURL -> String -> IO (Map Int [Float]) Source #

Convert a JSON Response from an ACE Server to a Float-List

hymPoolList' :: HymURL -> String -> IO (Map Int [String]) Source #

Convert a JSON Response from an ACE Server to a String-List

hymPoolReset :: HymURL -> IO (Map Int [Float]) Source #

Reset Pooled Environments on a Hym server

hymPoolRandomAction :: HymURL -> IO (Map Int [Float]) Source #

Get Random Actions from all Pooled Environments

hymPoolRandomStep :: HymURL -> IO (Map Int Step) Source #

Perform Random Actions in all Pooled Environments

hymPoolStep :: HymURL -> Map Int [Float] -> IO (Map Int Step) Source #

Take Steps in All Environments (Continuous)

hymPoolStep' :: HymURL -> Map Int Int -> IO (Map Int Step) Source #

Take Steps in All Environments (Discrete)

aceURL :: String -> String -> String -> String -> String -> HymURL Source #

Generate URL to a Hym-GACE server from meta information

gymURL :: String -> String -> String -> String -> HymURL Source #

Generate URL to a Hym-Gym server from meta information

acePoolTarget :: HymURL -> IO (Map Int (Map String Float)) Source #

Send a GET Request to a GACE Server Obtain the Target of Pooled GACE Environments

acePoolPredicate :: HymURL -> IO (Map Int (Map String Bool)) Source #

Send a GET Request to a GACE Server Obtain the Target Predicate of Pooled GACE Environments

acePoolScaler :: HymURL -> IO (Map Int (Map String [Float])) Source #

Get minmax estimates for performances andor targets

acePoolActKeys :: HymURL -> IO (Map Int [String]) Source #

Action Keys from GACE Server

acePoolObsKeys :: HymURL -> IO (Map Int [String]) Source #

Observation Keys from GACE Server

shaceLogPath' :: HymURL -> IO (Map String String) Source #

Get the SHACE logging path as a dict

shaceLogPath :: HymURL -> IO String Source #

Get the SHACE logging path

resetPool :: HymURL -> IO Tensor Source #

Reset a Vectorized Environment Pool

resetPool' :: HymURL -> Tensor -> IO Tensor Source #

Reset selected Environments from Pool

actKeysPool :: HymURL -> IO [String] Source #

Shorthand for getting keys of pooled same envs

obsKeysPool :: HymURL -> IO [String] Source #

Shorthand for getting keys of pooled same envs

numEnvsPool :: HymURL -> IO Int Source #

Number of Environments in Pool

infoPool :: HymURL -> IO Info Source #

Get Info without stepping

targetPool :: HymURL -> IO Tensor Source #

Get Targets for all envs in Pool

targetPool' :: HymURL -> IO Tensor Source #

Get Targets for all envs in Pool and process them

targetKeysPool :: HymURL -> IO [String] Source #

Target parameter keys

scalerPool :: HymURL -> [String] -> IO Tensor Source #

Implying same target params for all envs in pool.

scalerPool' :: HymURL -> IO Tensor Source #

Implying same target params for all envs in pool and we want all of them.

stepPool :: HymURL -> Tensor -> IO (Tensor, Tensor, Tensor, [Info]) Source #

Step in a Control Environment

stepPool' :: HymURL -> Tensor -> IO (Tensor, Tensor, Tensor, [Info]) Source #

Step in a Discrete Environment

randomStepPool :: HymURL -> IO (Tensor, Tensor, Tensor, [Info]) Source #

Take a random Step an Environment

randomActionPool :: HymURL -> IO Tensor Source #

Get a set of random actions from the current environment

boolMask :: Int -> [Int] -> Tensor Source #

Create Boolean Mask Tensor from list of indices.

boolMask'' :: Int -> [Int] -> Tensor Source #

Create Boolean Mask Tensor from list of indices on CPU.

boolMask' :: Int -> Tensor -> Tensor Source #

Create a Boolean Mask Tensor from index Tensor

processTarget :: Map Int (Map String Float) -> Tensor Source #

Process Targets for HER

postProcess' :: Map String [Float] -> (Tensor, Tensor, Tensor, [Info]) -> (Tensor, Tensor, Tensor, Tensor, Tensor) Source #

Convenience, takes output straight from stepPool.

postProcess :: Info -> Map String [Float] -> Tensor -> (Tensor, Tensor, Tensor) Source #

Process for HER returns processed observations, the target and the augmented target

processGace'' :: Tensor -> Info -> (Tensor, Tensor, Tensor) Source #

Process for HER returns processed observations, the target and the augmented target

processGace' :: Tensor -> Info -> Tensor Source #

Standardize state over all parallel envs

processGace :: Tensor -> Info -> Tensor Source #

Process / Sanitize the Observations from GACE

scaleRewards :: Tensor -> Float -> Tensor Source #

Scale reward to center

normalize :: Float -> Float -> Tensor -> Tensor Source #

Normalize feature x s.t. x' ∈ [a,b]

normalize' :: Tensor -> Tensor Source #

Convenience: Normalize feature x s.t. x' ∈ [-1.0,1.0]

normalize'' :: Float -> Float -> Tensor -> Tensor -> Tensor -> Tensor Source #

Normalize given some arbitrary min / max values

denormalize :: Tensor -> Tensor -> Tensor -> Tensor Source #

Normalize feature x' ∈ [a,b] given the original min/max

sanatizeJSON :: Char -> Char Source #

Sanatize JSON for MLFlow: Names may only contain alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and slashes (/).

data Tracker Source #

Data Logging to MLFlow Trackign Server

Constructors

Tracker 

Fields

Instances

Instances details
Show Tracker Source # 
Instance details

Defined in Lib

runId :: Tracker -> String -> RunID Source #

Retrieve a run ID

mkTracker :: TrackingURI -> String -> IO Tracker Source #

Make new Tracker given a Tracking Server URI

mkTracker' :: String -> Int -> String -> IO Tracker Source #

Make new Tracker given a Hostname and Port

newExperiment :: Tracker -> String -> IO Tracker Source #

Create a new Experiment with rng suffix

newExperiment' :: Tracker -> String -> IO Tracker Source #

Create a new Experiment

newRuns :: Tracker -> [String] -> [Param] -> IO Tracker Source #

Create a new run with a set of given paramters

newRuns' :: Int -> Tracker -> IO Tracker Source #

New run with algorithm id and #envs as log params

endRun :: String -> Tracker -> IO Tracker Source #

End a run

endRuns :: Tracker -> IO Tracker Source #

End all runs of a Tracker

endRuns' :: Tracker -> IO () Source #

End all runs and discard tracker

trackLoss :: Tracker -> Int -> String -> Float -> IO (Response ByteString) Source #

Write Loss to Tracking Server

trackReward :: Tracker -> Int -> Tensor -> IO () Source #

Write Reward to Tracking Server

filterPerformance :: Map Int (Map String Float) -> [String] -> Map Int (Map String Float) Source #

Filter Performance of all envs

trackEnvState :: Tracker -> HymURL -> Int -> IO () Source #

Write Current state of the Environment to Trackign Server