pkalivas / radiate

A genetic programming engine which evolves solutions through asynchronous speciation.
MIT License
147 stars 16 forks source link

Linear Algebra #7

Closed luiswirth closed 4 years ago

luiswirth commented 4 years ago

Was it an active decision to not use linear algebra for neural network forward-propagation and the like? I would assume it would speed up the computations significantly. Crates like nalgebra would present themselves as good candidates for such an implementation.

If it was a decision, what was the motivation? Could it be that you can't really use linear algebra for NEAT (I'm not really familiar with how NEAT works)?

pkalivas commented 4 years ago

For NEAT yes that's an active decision, the dense layer of this project (models/layers/dense.rs) follows the algorithm described in the original paper here. Using any sort of matrix math in NEAT is not possible, although it is possible to evolve traditional neural networks (checkout radiate-matrix-tree, the nodes in the tree use traditional matrix neural networks for forward propagation). The main goal of NEAT is to evolve efficient neural networks through adding/removing nodes and connections from the network which is only possible through the sort of neural network graph.

The main motivations were:

This project adds a few layers of abstraction on top of the NEAT algorithm (dense layer) so different types of neural networks can be built using the same algorithm (LSTM, Recurrent, ect). If you're interested in Neat and how it works, there are some really great resources online that probably do a better job of describing it than I am, its super interesting.

luiswirth commented 4 years ago

Okay, very interesting. Do you know how the performance of NEAT is compared to a normal neural-network which uses matrix math? Because I'm currently implementing a simulation using neuroevolution to evolve living agents, and I'm considering implementing NEAT too. I assume that I'm unable to use radiate because I'm using the amethyst game engine, which already uses a concurrent ECS which probably conflicts with your parallelization. Do you think so too?

pkalivas commented 4 years ago

Honestly it would depend on the type of problem you are tying to solve and the size of the dataset. I haven't done any side by side comparisons.

You could use radiate I'm sure, I'm not familiar with that game engine, but radiate uses rayon for the main engine's concurrency and you can set a global (possibly a scoped too) thread variable which controls how many threads rayon is allowed to use. If possible, you can use radiate to train a network on a separate machine too (examples/radiate-web) meaning you could run the game engine on one computer and evolve the network on another which would resolve that problem all together. I've found in some cases evolving an agent using radiate takes a matter of seconds so its definitely possibly you could use radiate and run your game with minimal or no notice.

luiswirth commented 4 years ago

Okay thanks for your support. I'll try using radiate for my own project. I hope it works out. amethyst (game engine) also uses rayon so I think they will play together nicely.

I'm not doing traditional neuroevolution, where I have some fitness function, but instead I'm evolving agents which can reproduce (mutation) and die (selection) and therefore do evolution. So that's why I'm using a game engine, because my agents live in a rather complex environment. Is it even possible to use radiate without a clear fitness function / Problem?

Sorry for abusing this issue. If you want we can move our discussion somewhere else :).

luiswirth commented 4 years ago

I'm really getting the feeling that radiate is not the thing I'm looking for. Can you maybe point me in the right direction?

I want to create artificial life (at least that's what I think it's called). I want to do neuroevoltion on agents without having a fitness function but instead relying on natural selection and mutation.

pkalivas commented 4 years ago

You can certainly do that with radiate... just return a 0 or some base number from the problem. However, I think you'll find it difficult to optimize any sort of neuroevolution without some sort of fitness function or grading material. You would end up with a population just randomly selecting and mutating and without some sort of way to tell which genomes are doing better, your program will most likely fail to find an optimal solution.

luiswirth commented 4 years ago

Okay thanks :)