File tree 4 files changed +126
-103
lines changed
4 files changed +126
-103
lines changed Original file line number Diff line number Diff line change 25
25
< style >
26
26
# app-status {
27
27
color : blue;
28
+ font-family : monospace;
28
29
font-size : 150% ;
29
30
padding-bottom : 1em ;
30
31
}
32
+ # cart-pole-canvas {
33
+ display : none;
34
+ }
31
35
button {
32
36
font-size : 105% ;
33
37
min-width : 120px ;
@@ -74,6 +78,10 @@ <h1>TensorFlow.js Example:<br/>Reinforcement Learning: Cart Pole </h1>
74
78
< span id ="app-status "> Standing by.</ span >
75
79
</ div >
76
80
81
+ < div >
82
+ < canvas id ="cart-pole-canvas " height ="150px " width ="500px "> </ canvas >
83
+ </ div >
84
+
77
85
< div >
78
86
< div class ="horizontal-sections ">
79
87
< div class ="input-div ">
@@ -136,10 +144,6 @@ <h1>TensorFlow.js Example:<br/>Reinforcement Learning: Cart Pole </h1>
136
144
< div class ="canvases " id ="steps-canvas "> </ div >
137
145
</ div >
138
146
</ div >
139
-
140
- < div >
141
- < canvas id ="cart-pole-canvas " height ="150px " width ="500px "> </ canvas >
142
- </ div >
143
147
</ div >
144
148
145
149
< script src ="index.js "> </ script >
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ class PolicyNetwork {
186
186
this . currentActions_ = actions . dataSync ( ) ;
187
187
const labels =
188
188
tf . sub ( 1 , tf . tensor2d ( this . currentActions_ , actions . shape ) ) ;
189
- return tf . sigmoidCrossEntropyWithLogits ( labels , logits ) . asScalar ( ) ;
189
+ return tf . losses . sigmoidCrossEntropy ( labels , logits ) . asScalar ( ) ;
190
190
} ) ;
191
191
return tf . variableGrads ( f ) ;
192
192
}
Original file line number Diff line number Diff line change @@ -125,7 +125,6 @@ function enableModelControls() {
125
125
deleteStoredModelButton . disabled = false ;
126
126
}
127
127
128
-
129
128
/**
130
129
* Render the current state of the system on an HTML canvas.
131
130
*
@@ -134,6 +133,9 @@ function enableModelControls() {
134
133
* the rendering will happen.
135
134
*/
136
135
function renderCartPole ( cartPole , canvas ) {
136
+ if ( ! canvas . style . display ) {
137
+ canvas . style . display = 'block' ;
138
+ }
137
139
const X_MIN = - cartPole . xThreshold ;
138
140
const X_MAX = cartPole . xThreshold ;
139
141
const xRange = X_MAX - X_MIN ;
@@ -306,7 +308,7 @@ export async function setUpUI() {
306
308
const action = policyNet . getActions ( cartPole . getStateTensor ( ) ) [ 0 ] ;
307
309
logStatus (
308
310
`Test in progress. ` +
309
- `Action: ${ action === 1 ? '← ' : ' → ' } (Step ${ steps } )` ) ;
311
+ `Action: ${ action === 1 ? '<-- ' : ' --> ' } (Step ${ steps } )` ) ;
310
312
isDone = cartPole . update ( action ) ;
311
313
renderCartPole ( cartPole , cartPoleCanvas ) ;
312
314
} ) ;
You can’t perform that action at this time.
0 commit comments