I'm writing a genetic algorithm to be used to control the weights of a neural net.
To specify the bases ("bits" of the code) of the "DNA", I'm allowing the caller to pass in a
List<T> of all the possible bases. When I need to mutate a base or generate a random sequence, it will be based on this passed
So what's the problem?
I didn't realize this until now, but the neural net may require a massive
List of possible weights (possibly thousands of different bases; our DNA has 4). Obviously, passing in a
List that actually contains every possible base would be very inefficient; it could potentially be huge.
My "solution" was to implement a Range class that implements
List that can represent all the possible bases by only storing 3 numbers (assuming they follow a regular pattern). My attempt is on CR here: Range Code Review.
It kind of solves the problem, but has its own problems:
- It barely implements
List; half of the required methods throw an
UnsupportedOperationException, since most of the operations don't make sense for a
- Since Java doesn't seem to have a usable
Numberinterface that allows for math, I'm using the most "general" number type I could think of; a
Double. Anyone using the
Rangewill need to and from
Doubleif they're using another type.
- The container is subject to floating-point errors since the whole "container" relies heavily on math to get elements.
I need to be able to allow the user of the genetic algorithm to specify the bases that they want it to use. The bases could be of any type, and there could be any number of possible bases.
How can I allow them to specify all the possible bases without using a potentially inefficient like storing every possible base explicitly in a list?