Skip to content

Commit

Permalink
mutate function bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Apr 16, 2020
1 parent a9eadce commit d84ebce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/NeuralNetwork/NeuralNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class NeuralNetwork {
* @param {*} rate
* @param {*} mutateFunction
*/
mutate(rate, mutateFunction) {
mutate(rate = 0.1, mutateFunction) {
tf.tidy(() => {
const weights = this.model.getWeights();
const mutatedWeights = [];
Expand All @@ -296,11 +296,11 @@ class NeuralNetwork {
// TODO: Evaluate if this should be sync or not
const values = tensor.dataSync().slice();
for (let j = 0; j < values.length; j+=1) {
if (Math.random() < rate || 0.1) {
if (Math.random() < rate) {
if (mutateFunction) {
values[j] = mutateFunction(values[j]);
} else {
values[j] += randomGaussian();
values[j] = Math.min(Math.max(values[j] + randomGaussian(), -1), 1);
}
}
}
Expand Down

0 comments on commit d84ebce

Please sign in to comment.