Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding crossover function #100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

enginefeeder101
Copy link
Contributor

@enginefeeder101 enginefeeder101 commented Mar 10, 2018

This commit adds crossover functions to the Matrix and NeuralNetwork class. It defaults
to a uniform crossover (ratio = 0.5), but this is customizable (third parameter).

You can use it as such:

let parentA = new NeuralNetwork(2, 4, 1);
let parentB = new NeuralNetwork(2, 4, 1);
let child = NeuralNetwork.crossover(parentA, parentB);

enginefeeder101 and others added 2 commits March 10, 2018 18:56
This commit adds crossover functions to the Matrix and NeuralNetwork class. It defaults
to a uniform crossover (ratio = 0.5), but this is customizable (third parameter).

You can use it as such:
```javascript
  let mom = new NeuralNetwork(2, 4, 1);
  let dad = new NeuralNetwork(2, 4, 1);
  let child = NeuralNetwork.crossover(mom, dad);
```
@shiffman
Copy link
Member

Awesome job! The use of map() is very clever!

Note for examples I prefer to use something generic like parentA or parent1 rather than "mom" / "dad".

I will hold off on merging but will do so during a video when I implement the algorithm! I think this is simple enough that I don't need to do my own video tutorial implementing crossover. (I cover it in the GA series anyway.)

There was a semicolon missing after the `map()` function.
This commit adds a check to the `crossover()` functions (both Matrix and NeuralNetwork)
that does not allow to crossover between different breeds. In other words, only if two
NeuralNetwork have the same number of nodes thay can crossover. Otherwise undefined is
returned. Same for the Matrix crossover function.
@enginefeeder101
Copy link
Contributor Author

I added a commit which checks if a NeuralNetwork and/or Matrix are of the same breed before applying the crossover algorithm. This prevents crossing-over between objects with different sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants