diff --git a/content/07_ca.html b/content/07_ca.html index 8da8b78..9c0db32 100644 --- a/content/07_ca.html +++ b/content/07_ca.html @@ -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} diff --git a/content/11_nn_ga.html b/content/11_nn_ga.html index 7220ac7..af16802 100644 --- a/content/11_nn_ga.html +++ b/content/11_nn_ga.html @@ -267,7 +267,7 @@ function draw() { (nextPipe.x - this.x) / width, ]; -
With the inputs in hand, I’m ready to pass them to the neural network’s classify()
method. I have another small problem, however: classify()
is asynchronous, meaning I’d have to implement a callback inside the Bird
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.
With the inputs in hand, I’m ready to pass them to the neural network’s classify()
method. I have another small problem, however: classify()
is asynchronous, meaning I’d have to implement a callback inside the Bird
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.
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 classifySync()
is identical to classify()
, 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 think()
method with classifySync()
: