Skip to content

Commit

Permalink
Merge pull request #899 from nature-of-code/notion-update-docs
Browse files Browse the repository at this point in the history
[Notion] Update docs
  • Loading branch information
shiffman authored Mar 5, 2024
2 parents 1812f9f + a613985 commit 0f91422
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/07_ca.html
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ <h3 id="the-implementation">The Implementation</h3>
// Correct by subtracting the cell state.
neighborSum -= board[i][j];

//{!1} The rules of life!
//{!2} The rules of life!
if (board[i][j] === 1 &#x26;&#x26; neighborSum &#x3C; 2) next[i][j] = 0;
else if (board[i][j] === 1 &#x26;&#x26; neighborSum > 3) next[i][j] = 0;
//{.continue}
Expand Down
2 changes: 1 addition & 1 deletion content/11_nn_ga.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ <h3 id="the-bird-brain">The Bird Brain</h3>
(nextPipe.x - this.x) / width,
];</pre>
</div>
<p>With the inputs in hand, I’m ready to pass them to the neural network’s <code>classify()</code> method. I have another small problem, however: <code>classify()</code> is asynchronous, meaning I’d have to implement a callback inside the <code>Bird</code> class to process the model’s decision. This would add a significant level of complexity to the code, but luckily, it’s entirely unnecessary in this case. Asynchronous callbacks with ml5.js’s machine learning functions are typically needed because of the time required to process the large amount of data in the model. Without a callback, the code might have to wait a long time to get a result, and if the model is running as part of a p5.js sketch, that delay could severely impact the smoothness of the animation. The neural network here, however, has only four floating-point inputs and two output labels! It’s tiny and can run fast enough that there’s no reason to use asynchronous code.</p>
<p>With the inputs in hand, I’m ready to pass them to the neural network’s <code>classify()</code> method. I have another small problem, however: <code>classify()</code> is asynchronous, meaning I’d have to implement a callback inside the <code>Bird</code> class to process the model’s decision. This would add a significant level of complexity to the code, but luckily, it’s entirely unnecessary in this case. Asynchronous callbacks with ml5.js’s machine learning functions are typically needed because of the time required to process the large amount of data in the model. Without a callback, the code might have to wait a long time to get a result, and if the model is running as part of a p5.js sketch, that delay could severely impact the smoothness of the animation. The neural network here, however, has only four floating-point<br>inputs and two output labels! It’s tiny and can run fast enough that there’s no reason to use asynchronous code.</p>
<div class="avoid-break">
<p>For completeness, I include a version of the example on the book’s website that implements neuroevolution with asynchronous callbacks. For this discussion, however, I’m going to use a feature of ml5.js that allows me to take a shortcut. The method <code>classifySync()</code> is identical to <code>classify()</code>, but it runs synchronously, meaning the code stops and waits for the results before moving on. You should be very careful when using this version of the method as it can cause problems in other contexts, but it will work well for this simple scenario. Here’s the end of the <code>think()</code> method with <code>classifySync()</code>:</p>
</div>
Expand Down

0 comments on commit 0f91422

Please sign in to comment.