Created
August 18, 2016 19:12
-
-
Save dan-lind/af7aca0d14725a8d4a51a64acecfbda6 to your computer and use it in GitHub Desktop.
RL4J
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
/** | |
* Created by danlin on 2016-08-17. | |
*/ | |
import org.deeplearning4j.rl4j.gym.space.Box; | |
import org.deeplearning4j.rl4j.learning.ILearning; | |
import org.deeplearning4j.rl4j.learning.sync.qlearning.QLearning; | |
import org.deeplearning4j.rl4j.learning.sync.qlearning.discrete.QLearningDiscreteDense; | |
import org.deeplearning4j.rl4j.mdp.gym.GymEnv; | |
import org.deeplearning4j.rl4j.network.dqn.DQNFactoryStdDense; | |
import org.deeplearning4j.rl4j.policy.Policy; | |
import org.deeplearning4j.rl4j.space.DiscreteSpace; | |
import org.deeplearning4j.rl4j.util.DataManager; | |
public class Cartpole | |
{ | |
public static String OPENAI_KEY = ""; | |
public static QLearning.QLConfiguration CARTPOLE_QL = | |
new QLearning.QLConfiguration( | |
123, | |
500, | |
150000, | |
100000, | |
32, | |
100, | |
1000, | |
0.99, | |
100.0, | |
0.0f, | |
1f / 40000f, | |
true | |
); | |
public static DQNFactoryStdDense.Configuration CARTPOLE_NET = | |
new DQNFactoryStdDense.Configuration(4, 0.001, 0.001, 0.99); | |
public static void main( String[] args ) | |
{ | |
cartPole(); | |
} | |
public static void cartPole() { | |
DataManager manager = new DataManager(true); | |
GymEnv mdp = new GymEnv("CartPole-v0", false); | |
ILearning<Box, Integer, DiscreteSpace> dql = new QLearningDiscreteDense(mdp, CARTPOLE_NET, CARTPOLE_QL, manager); | |
dql.train(); | |
Policy<Box, Integer> pol = dql.getPolicy(); | |
while(true){ | |
mdp.reset(); | |
pol.play(mdp); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment