-
Notifications
You must be signed in to change notification settings - Fork 364
/
index.html
185 lines (157 loc) · 6.37 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<title>Self driving car demo | NeuroJS</title>
<style>
html,body {
margin:0;
padding:0;
width:100%;
height:100%;
font-family: sans-serif;
}
* {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.description {
padding: 0 20px;
}
.wrap {
width: 100%; max-width: 1000px; margin: 40px auto;
}
.app-chart .ct-line {
/* Control the thikness of your lines */
stroke-width: 2px;
/* Create a dashed line with a pattern */
stroke-dasharray: 0 0;
}
.app-chart .ct-series-a .ct-line, .app-chart .ct-series-a .ct-point {
/* Set the colour of this series line */
stroke: #000 !important;
}
.app-chart .ct-series-b .ct-line, .app-chart .ct-series-b .ct-point {
/* Set the colour of this series line */
stroke: #14D969 !important;
}
.app-chart .ct-series-c .ct-line, .app-chart .ct-series-c .ct-point {
/* Set the colour of this series line */
stroke: green !important;
}
/* This selector overrides the points style on line charts. Points on line charts are actually just very short strokes. This allows you to customize even the point size in CSS */
.app-chart .ct-point {
/* Size of your points */
stroke-width: 0;
}
.app-chart .ct-grid {
stroke: #eee;
stroke-width: 1px;
stroke-dasharray: 0;
}
.app-chart .ct-label.ct-vertical.ct-start {
font-family: sans-serif;
color: #999;
font-weight: 300;
}
button, input {
display: inline-block;
}
button {
--webkit-appearance: none;
outline: none;
border: 2px solid #eee;
background: #eee;
border-radius: 5px;
padding: 4px 10px;
color: #000;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: #fff;
}
.row {
margin-top: 10px;
}
label {
display: block;
margin-top: 10px;
font-size: 14px;
font-style: italic;
}
.credits {
text-align: center;
color: #ccc;
font-size: 15px;
margin: 30px 0 60px;
}
</style>
<link rel="stylesheet" type="text/css" href="vendor/chartist.min.css">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<div class="description wrap">
<p>This demo is about self-learning cars. The reinforcement-learning-goal of these cars is to maximize their future speed at all times, which means to avoid shapes. The input to the cars' neural network is the sensor data: speed in x- and y-direction, distance + entity type + normal vector (2d) of sensing rays (19 per car). In addition to the current time-step they receive the last action-state pair. Each state has 19x4 + 2 = 78 dimensions. The action space is 2 dimensional, which means the input to the car's brain is 78x2 + 2 = 158 dimensional. </p>
<p>This page uses the DDPG (deep deterministic policy gradient) algorithm, which means the action space is continuous. 1d for speed control (gas pedal, -1 for braking/going backwards, +1 for max thrust in forward direction) and 1d for stearing (-1 left, 0 straight, +1 right). </p>
<p><strong>Click and drag to draw shapes, which must be avoided by the cars.</strong></p>
<p>Takes the agents about 15 minutes to learn driving. </p>
<p>If you want to skip training, there is a pre-trained agent file in the subfolder agents/ of this demo, which you can load using the button below. </p>
<div class="row">
<button onclick="demo.dispatcher.goSlow();">Go slow</button>
<button onclick="demo.dispatcher.goFast();">Go fast</button>
</div>
<div class="row">
<button onclick="demo.world.clearObstacles();">Clear track</button>
<button onclick="demo.saveTrack();">Export track</button>
<button onclick="document.getElementById('__track').click();">Import track</button>
</div>
<div class="row">
<button onclick="document.getElementById('__file').click();">Load from file</button>
<button onclick="demo.save();">Save to file</button>
</div>
<input id="__track" type='file' accept='*/*' onchange='demo.load(event, true)' style="display: none">
<input id="__file" type='file' accept='*/*' onchange='demo.load(event)' style="display: none">
<div style="margin-top: 20px">
<input type="checkbox" onclick="demo.setLearning(this.checked);"> Learning
</div>
<div>
<input type="checkbox" onclick="demo.setFreeze(this.checked);"> Freeze
</div>
</div>
<div id="container" class="wrap"></div>
<div class="wrap">
<p>Agent's lifespan: <span id="agent-age">0</span>s</p>
<div class="ct-chart ct-double-octave app-chart"></div>
<svg width="356px" height="12px" viewBox="0 0 356 12" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="legend">
<g id="Group-2" fill="#000000">
<circle id="Oval" cx="6" cy="6" r="6"></circle>
<text id="LOSS" font-family="Arial-BoldMT, Arial" font-size="10" font-weight="bold">
<tspan x="24.5" y="9">LOSS</tspan>
</text>
</g>
<g id="Group" transform="translate(90.000000, 0.000000)">
<circle id="Oval-Copy" fill="#14D969" cx="6" cy="6" r="6"></circle>
<text id="REWARD" font-family="Arial-BoldMT, Arial" font-size="10" font-weight="bold" fill="#000000">
<tspan x="24" y="9">REWARD</tspan>
</text>
</g>
<g id="Group-Copy" transform="translate(180.000000, 0.000000)">
<circle id="Oval-Copy" fill="#008000" cx="6" cy="6" r="6"></circle>
<text id="REWARD-[RUNNING-AVER" font-family="Arial-BoldMT, Arial" font-size="10" font-weight="bold" fill="#000000">
<tspan x="24.5" y="9">REWARD [RUNNING AVERAGE]</tspan>
</text>
</g>
</g>
</g>
</svg>
</div>
<p class="credits">Made by Jan Hünermann</p>
<script type="text/javascript" src="vendor/chartist.min.js"></script>
<script type="text/javascript" src="vendor/p2.min.js"></script> <!-- physics lib -->
<script type="text/javascript" src="vendor/pixi.min.js"></script> <!-- WebGL renderer -->
<script type="text/javascript" src="../../build/neurojs-v2.js"></script> <!-- brain lib :P -->
<script type="text/javascript" src="build/bundle.js"></script> <!-- app -->
</body>
</html>