Skip to content

Commit

Permalink
Added test code for integrating Tensorforce
Browse files Browse the repository at this point in the history
 * Need TF v1.7.0
 * lefnire/tforce_btc_trader#33
  • Loading branch information
seungjaeryanlee committed Jul 22, 2018
1 parent 9014e62 commit af9832b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helper/baselines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .RandomAgent import RandomAgent
from .FixedActionAgent import FixedActionAgent
from .keras import *

from .tensorforce import *
32 changes: 32 additions & 0 deletions helper/baselines/tensorforce/TensorforcePPOAgent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from tensorforce.agents import PPOAgent
from helper.wrappers import ClientToEnv, DictToListFull, JSONable

class TensorforcePPOAgent:
def __init__(self, env):
# Create a Proximal Policy Optimization agent
self.agent = PPOAgent(
states=dict(type='float', shape=(347,)),
actions=dict(type='float', shape=(19,)),
network=[
dict(type='dense', size=64),
dict(type='dense', size=64)
],
batching_capacity=1000,
step_optimizer=dict(
type='adam',
learning_rate=1e-4
)
)

self.env = DictToListFull(env)

def test(self, env):
# Poll new state from client
state = self.env.reset(project=False)
import numpy as np
# Get prediction from agent, execute
action = self.agent.act(state)
obs, rew, done, info = self.env.step(action, project=False)

# Add experience, agent automatically updates model according to batch size
self.agent.observe(reward=rew, terminal=done)
1 change: 1 addition & 0 deletions helper/baselines/tensorforce/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .TensorforcePPOAgent import TensorforcePPOAgent

0 comments on commit af9832b

Please sign in to comment.