-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test code for integrating Tensorforce
* Need TF v1.7.0 * lefnire/tforce_btc_trader#33
- Loading branch information
1 parent
9014e62
commit af9832b
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .TensorforcePPOAgent import TensorforcePPOAgent |