Exemple #1
0
void random(Net<SIZE> & subject) {
    for (int c = 0; c < SIZE; ++c) {
        for (int r = 0; r < SIZE; ++r) {
            if (subject.hasSynapse(c, r)) {
                subject[c][r] = randMax(2) - 1.;
            }
        }
    }
}
Exemple #2
0
void mutate(Net<SIZE> & subject, double rate) {
    for (int c = 0; c < SIZE; ++c) {
        for (int r = 0; r < SIZE; ++r) {
            if (subject.hasSynapse(c, r) && chance(rate)) {
                if (chance(0.5)) {
                    subject[c][r] += rand() - .5;
                } else {
                    subject[c][r] = randMax(2) - 1.;
                }
            }
        }
    }
}
Exemple #3
0
Net<SIZE> cross(const Net<SIZE> & mother, const Net<SIZE> & father) {
    const Net<SIZE> * parents[2] = {&mother, &father};
    Net<SIZE> child;

    int inheritence = 1;
    for (int c = 0; c < SIZE; ++c) {
        for (int r = 0; r < SIZE; ++r) {
            if (mother.hasSynapse(c, r)) {
                // alternate parents
                child[c][r] = (*parents[inheritence = !inheritence])[c][r];
            }
        }
    }


    return child;
}