mirror of
https://github.com/wassname/rl_2d_walker.js.git
synced 2026-09-09 11:33:20 +08:00
merge
This commit is contained in:
+20
-5
@@ -3,14 +3,14 @@
|
||||
|
||||
<head>
|
||||
<title>Reinforcement Learning 2D Biped Walkers</title>
|
||||
|
||||
<style link="css/walkers.css"></style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="main_holder">
|
||||
<h1>Reinforcement Learning 2D Humanoid Walkers</h1>
|
||||
<h3 id="page_quote">"Play that funky music, robot"</h3>
|
||||
<canvas id="main_screen" width="800" height="350" style="background: url('./images/background.png')"></canvas>
|
||||
<canvas id="main_screen2" width="800" height="350" style="background: url('./images/background.png')"></canvas>
|
||||
|
||||
<image style="display: none" src="./images/background.png"></image><!-- for google and previews-->
|
||||
|
||||
@@ -20,13 +20,12 @@
|
||||
<p></p>
|
||||
It's goal it to hold it head upright and move to the right. If you load it's brain from differen't times you can see it's progress.
|
||||
<p></p><br />
|
||||
Technical: This uses use reinforcement learning to teach them
|
||||
How does it work?: This uses use reinforcement learning to teach them
|
||||
to walk. This is a branch of machine learning targeted at controlling systems such as system of limbs. Training
|
||||
is done offline in tensorflow.js. The environment is in box2d for javascript. The aglorithm is DDPG with
|
||||
prioritized experince replay.
|
||||
<p></p>
|
||||
The dark outlines are when the agent grips the floor, since I found walking was difficult otherwise. The balls
|
||||
are to provide obstacles.
|
||||
The dark outlines are when the agent grips the floor, since I found walking was difficult otherwise. The balls are to provide obstacles.
|
||||
<p></p><br />
|
||||
Credits: The walker code is adapted from <a href="http://rednuht.org/genetic_walkers/">rednuht.org/genetic_walkers/</a>,
|
||||
the DDPG code was adapted from <a href="https://github.com/thibo73800/metacar">github.com/thibo73800/metacar</a>.
|
||||
@@ -40,6 +39,8 @@
|
||||
<button onclick="game.agent.restore('./checkpoints', 'model-ddpg-walker-4h/model')">4 hours</button>
|
||||
<button onclick="game.agent.restore('./checkpoints', 'model-ddpg-walker-8h/model')">8 hours</button>
|
||||
<button onclick="game.agent.restore('./checkpoints', 'model-ddpg-walker-22h/model')">22 hours</button>
|
||||
<button onclick="game.agent.restore('./checkpoints', 'model-ddpg-walker-42h/model')">42 hours</button>
|
||||
<button onclick="game.agent.restore('./checkpoints', 'model-ddpg-walker-60h/model')">60 hours</button>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Be mean:</h4><button onclick="game.agent.env.chuckBalls()">Thow balls</button>
|
||||
@@ -49,5 +50,19 @@
|
||||
|
||||
|
||||
</body>
|
||||
<script>
|
||||
function init() {
|
||||
var canvas_id = 'main_screen2'
|
||||
window.game = new Game(config, canvas_id)
|
||||
game.agent.restore('./checkpoints', 'model-ddpg-walker-60h/model') // load checkpoint
|
||||
game.agent.restore('../outputs', 'model-ddpg-walker/model') // load latest
|
||||
game.loop()
|
||||
|
||||
chooseQoute()
|
||||
var canvas=document.getElementById(canvas_id)
|
||||
canvas.style.background=''
|
||||
}
|
||||
window.addEventListener("load", init, false);
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
+15
-15
@@ -37,6 +37,7 @@ chooseQoute = function () {
|
||||
"This is a metaphor for life",
|
||||
"The balls represent love",
|
||||
"You're driving me up the wall",
|
||||
"Ministry of silly walks",
|
||||
"The wall represent's life, it can lift you up, it can bring you down.",
|
||||
]
|
||||
var qoute = qoutes[randi(0, qoutes.length)]
|
||||
@@ -63,14 +64,17 @@ class HeadlessGame {
|
||||
stateSize,
|
||||
nbActions,
|
||||
resetEpisode: true,
|
||||
batchSize: 128,
|
||||
batchSize: 64,
|
||||
actorLr: 0.0001,
|
||||
criticLr: 0.001,
|
||||
memorySize: 30000,
|
||||
memorySize: 20000,
|
||||
gamma: 0.99,
|
||||
|
||||
desiredActionStddev: 0.1,
|
||||
initialStddev: 0.4,
|
||||
desiredActionStddev: 0.2,
|
||||
minActionStddev: 0.001,
|
||||
initialStddev: 0.6,
|
||||
adoptionCoefficient: 1.01,
|
||||
noiseDecay: 0.99,
|
||||
|
||||
actorFirstLayerSize: 128,
|
||||
actorSecondLayerSize: 64,
|
||||
@@ -78,7 +82,7 @@ class HeadlessGame {
|
||||
criticFirstLayerASize: 128,
|
||||
criticSecondLayerSize: 64,
|
||||
|
||||
nbEpochs: 1000,
|
||||
nbEpochs: 500,
|
||||
nbEpochsCycle: 10,
|
||||
nbTrainSteps: 100,
|
||||
maxStep: 1800,
|
||||
@@ -86,30 +90,26 @@ class HeadlessGame {
|
||||
saveInterval: 5,
|
||||
|
||||
tau: 0.008,
|
||||
adoptionCoefficient: 1.01,
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var removeCanvasBackground = function (){
|
||||
var canvas=document.getElementById('main_screen')
|
||||
canvas.style.background=''
|
||||
}
|
||||
|
||||
|
||||
class Game extends HeadlessGame {
|
||||
constructor(config) {
|
||||
constructor(config, canvas_id) {
|
||||
config.canvas_id = canvas_id
|
||||
super(config)
|
||||
|
||||
this.agent.stop()
|
||||
this.agent.restore('./checkpoints', 'model-ddpg-walker-22h/model') // load checkpoint
|
||||
this.agent.restore('../outputs', 'model-ddpg-walker/model') // load latest
|
||||
}
|
||||
|
||||
loop() {
|
||||
setInterval(() => {
|
||||
this.play()
|
||||
}, 1000/this.config.draw_fps)
|
||||
chooseQoute()
|
||||
removeCanvasBackground()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user