在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sentenai/reinforce开源软件地址(OpenSource Url):https://github.com/sentenai/reinforce开源编程语言(OpenSource Language):Haskell 98.6%开源软件介绍(OpenSource Introduction):reinforce
This is an environment-first library, with basic reinforcement learning algorithms being developed on branches in subpackages (see #Development and Milestones).
This repo is in active development and has some beginner-friendly contributions, from porting new gym environments to implementing new algorithms. Because this library is not on hackage, if you would like to see the haddocks, you can find it here. An example agentIn module Main where
import Reinforce.Prelude
-- ^ NoImplicitPrelude is on
import Environments.CartPole (Environment, runEnvironment_)
import Control.MonadEnv (Initial(..), Obs(..))
import qualified Control.MonadEnv as Env (step, reset)
import qualified Environments.CartPole as Env (StateCP)
-- Comments:
-- StateCP - An "observation" or "the state of the agent" - note that State overloaded, so StateCP
-- Action - A performable action in the environment.
import qualified Reinforce.Spaces.Action as Actions (randomChoice)
main :: IO ()
main = runEnvironment_ gogoRandomAgent
where
gogoRandomAgent :: Environment ()
gogoRandomAgent = forM_ [0..maxEpisodes] $ \_ ->
Env.reset >>= \case -- this comes from LambdaCase. Sugar for: \a -> case a of ...
EmptyEpisode -> pure ()
Initial obs -> do
liftIO . print $ "Initialized episode and am in state " ++ show obs
rolloutEpisode obs 0
maxEpisodes :: Int
maxEpisodes = 100
-- this is usually the structure of a rollout:
rolloutEpisode :: Env.StateCP -> Double -> Environment ()
rolloutEpisode obs totalRwd = do
a <- liftIO Actions.randomChoice
Env.step a >>= \case
Terminated -> pure ()
Done r mobs ->
liftIO . print
$ "Done! final reward: " ++ show (totalRwd+r) ++ ", final state: " ++ show mobs
Next r obs' -> do
liftIO . print
$ "Stepped with " ++ show a ++ " - reward: " ++ show r ++ ", next state: " ++ show obs'
rolloutEpisode obs' (totalRwd+r) You can build and run this with the following commands:
Note that if you want to run a gym environment, you'll have to run the openai/gym-http-api server with the following steps:
Currently, development has been primarily focused around classic control, so if you want to add any of the Atari environments, this would be an easy contribution! InstallingReinforce doesn't exist on hackage or stackage (yet), so your best bet is to add this git repo to your stack.yaml file: packages:
- '.'
- location:
git: [email protected]:Sentenai/reinforce.git
commit: 'v0.0.1'
extra-dep:true
# This is a requirement due to some tight coupling of the gym-http-api
- location:
git: https://github.com/stites/gym-http-api.git
commit: '5b72789'
subdirs:
- binding-hs
extra-dep: true
- ... and add it to your cabal file or package.yaml (recommended) dependencies. Development and MilestonesIf you want to contribute, you're in luck! There are a range of things to do from the beginner haskeller to, even, advanced pythonistas! Please file an issue mentioning where you'd like to help, or track down @stites in the dataHaskell gitter or directly through keybase.io. While you can check the Github issues, here are some items off the top of my head which could use some immediate attention (and may also need to be filed). A few quick environment contributions might be the following:
Some longer-running algorithmic contributions which would take place on the
For a longer-term view, feel free to check out Milestones. ContributorsThanks goes to these wonderful people (emoji key):
全部评论
专题导读
上一篇:mrkkrp/megaparsec: Industrial-strength monadic parser combinator library发布时间:2022-06-24下一篇:vincenthz/hs-gauge: Lean Haskell Benchmarking发布时间:2022-06-24热门推荐
热门话题
阅读排行榜
|
请发表评论