mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-09-29 05:36:56 +02:00
Notion - Update docs
This commit is contained in:
parent
1812f9f579
commit
a61398577b
2 changed files with 2 additions and 2 deletions
|
@ -583,7 +583,7 @@ for (let i = 1; i < columns - 1; i++) {
|
|||
// 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 && neighborSum < 2) next[i][j] = 0;
|
||||
else if (board[i][j] === 1 && neighborSum > 3) next[i][j] = 0;
|
||||
//{.continue}
|
||||
|
|
|
@ -267,7 +267,7 @@ function draw() {
|
|||
(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>
|
||||
|
|
Loading…
Reference in a new issue