function mutateModel(model, percentError) {
    const randomIndex = Math.floor(Math.random() * Math.floor(4));
    const plusOrMinus = Math.floor(Math.random() * Math.floor(2));
    
    const maxDiff = model[randomIndex] * (percentError / 100);
    const diff = getRandomFloat(0, maxDiff);
    const newWeight = plusOrMinus === 1
        ? model[randomIndex] + diff
        : model[randomIndex] - diff;

    const newModel = [...model];
    newModel[randomIndex] = newWeight;
    return newModel;
}
/**
 * mutates the model based on the current percent error of the model.
 * the lower the percent error, the less we're going to mutate it.
 *
 * this returns a copy of the model, and doesn't edit it in-line.
 */
mutates the model based on the current percent error of the model.
the lower the percent error, the less we're going to mutate it.

this returns a copy of the model, and doesn't edit it in-line.
mutates the model based on the current percent error of the model . the lower the percent error the less we ' re going to mutate it . this returns a copy of the model and doesn ' t edit it in - line .
function mutateModel(model, percentError) {
    const randomIndex = Math.floor(Math.random() * Math.floor(4));
    const plusOrMinus = Math.floor(Math.random() * Math.floor(2));
    const maxDiff = model[randomIndex] * (percentError / 100);
    const diff = getRandomFloat(0, maxDiff);
    const newWeight = plusOrMinus === 1
        ? model[randomIndex] + diff
        : model[randomIndex] - diff;
    const newModel = [...model];
    newModel[randomIndex] = newWeight;
    return newModel;
}
function mutateModel ( model , percentError ) { const randomIndex = Math . floor ( Math . random ( ) * Math . floor ( 4 ) ) ; const plusOrMinus = Math . floor ( Math . random ( ) * Math . floor ( 2 ) ) ; const maxDiff = model [ randomIndex ] * ( percentError / 100 ) ; const diff = getRandomFloat ( 0 , maxDiff ) ; const newWeight = plusOrMinus === 1 ? model [ randomIndex ] + diff : model [ randomIndex ] - diff ; const newModel = [ ... model ] ; newModel [ randomIndex ] = newWeight ; return newModel ; }
mutates the model based on the current percent error of the model.
mutates the model based on the current percent error of the model .