File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 < style >
2626 # app-status {
2727 color : blue;
28+ font-family : monospace;
2829 font-size : 150% ;
2930 padding-bottom : 1em ;
3031 }
32+ # cart-pole-canvas {
33+ display : none;
34+ }
3135 button {
3236 font-size : 105% ;
3337 min-width : 120px ;
@@ -74,6 +78,10 @@ <h1>TensorFlow.js Example:<br/>Reinforcement Learning: Cart Pole </h1>
7478 < span id ="app-status "> Standing by.</ span >
7579 </ div >
7680
81+ < div >
82+ < canvas id ="cart-pole-canvas " height ="150px " width ="500px "> </ canvas >
83+ </ div >
84+
7785 < div >
7886 < div class ="horizontal-sections ">
7987 < div class ="input-div ">
@@ -136,10 +144,6 @@ <h1>TensorFlow.js Example:<br/>Reinforcement Learning: Cart Pole </h1>
136144 < div class ="canvases " id ="steps-canvas "> </ div >
137145 </ div >
138146 </ div >
139-
140- < div >
141- < canvas id ="cart-pole-canvas " height ="150px " width ="500px "> </ canvas >
142- </ div >
143147 </ div >
144148
145149 < script src ="index.js "> </ script >
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ class PolicyNetwork {
186186 this . currentActions_ = actions . dataSync ( ) ;
187187 const labels =
188188 tf . sub ( 1 , tf . tensor2d ( this . currentActions_ , actions . shape ) ) ;
189- return tf . sigmoidCrossEntropyWithLogits ( labels , logits ) . asScalar ( ) ;
189+ return tf . losses . sigmoidCrossEntropy ( labels , logits ) . asScalar ( ) ;
190190 } ) ;
191191 return tf . variableGrads ( f ) ;
192192 }
Original file line number Diff line number Diff line change @@ -125,7 +125,6 @@ function enableModelControls() {
125125 deleteStoredModelButton . disabled = false ;
126126}
127127
128-
129128/**
130129 * Render the current state of the system on an HTML canvas.
131130 *
@@ -134,6 +133,9 @@ function enableModelControls() {
134133 * the rendering will happen.
135134 */
136135function renderCartPole ( cartPole , canvas ) {
136+ if ( ! canvas . style . display ) {
137+ canvas . style . display = 'block' ;
138+ }
137139 const X_MIN = - cartPole . xThreshold ;
138140 const X_MAX = cartPole . xThreshold ;
139141 const xRange = X_MAX - X_MIN ;
@@ -306,7 +308,7 @@ export async function setUpUI() {
306308 const action = policyNet . getActions ( cartPole . getStateTensor ( ) ) [ 0 ] ;
307309 logStatus (
308310 `Test in progress. ` +
309- `Action: ${ action === 1 ? '← ' : ' → ' } (Step ${ steps } )` ) ;
311+ `Action: ${ action === 1 ? '<-- ' : ' --> ' } (Step ${ steps } )` ) ;
310312 isDone = cartPole . update ( action ) ;
311313 renderCartPole ( cartPole , cartPoleCanvas ) ;
312314 } ) ;
You can’t perform that action at this time.
0 commit comments