Skip to content

Commit 15ae613

Browse files
authored
Create Neural-Evolution.md
1 parent 874962a commit 15ae613

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Documents/Neural-Evolution.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Use Neural Evolution to optimize Neural Network
2+
3+
Neural Evolution is a totally different algorithm from gradient descent to optimize a neural network.
4+
It uses [Evolutionary Algorithm](https://en.wikipedia.org/wiki/Evolutionary_algorithm) to find the best weights of the neural network.
5+
6+
A [paper](https://arxiv.org/pdf/1712.06567.pdf) from Uber shows that [genetic algorithm (GA)](https://en.wikipedia.org/wiki/Genetic_algorithm) can
7+
,a subtype of Evolutionary Algorithm, performs well on deep reinformcement learning problems as well. However, here we are not gonna use GA yet, but MAES instead since we already have it.
8+
9+
Note that evolutionary algorithms can be very efficient if you can fun it in parallel on a lot of computers, because the children of each generation
10+
can usually be evalutad independently. But again, we are not doing this neither yet.
11+
12+
## Overall Steps
13+
The steps are similiar to using other training method. See the scene `UnityTensorflow/Examples/3DBall/3DBallNE` for a simple example.
14+
15+
1. Create a environment using ML-Agent API. See the [instruction from Unity](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Create-New.md)
16+
2. Change the BrainType of your brain to `InternalTrainable` in inspector.
17+
3. Create a Trainer
18+
1. Attach a `TrainerNeuralEvolution.cs` to any GameObject.
19+
2. Create a `TrainerParamsNeuralEvolution` scriptable object with proper parameters in your project and assign it to the Params field in `TrainerNeuralEvolution.cs`.
20+
3. Assign the Trainer to the `Trainer` field of your Brain.
21+
3. Create a Model
22+
1. Any model that implements INeuralEvolutionModel can be used as a model for neural evolution trainer. Currently both `RLModelPPO.cs`
23+
and `SupervisedLearningModel.cs` have that. Attach a one of those two to any GameObject.
24+
2. Create a Network scriptable object in your project for your model and attach it to the model.(See [Training with Proximal Policy Optimization(PPO)](https://github.com/tcmxx/UnityTensorflowKeras/blob/tcmxx/docs/Documents/Training-PPO.md) if you don't know how)
25+
3. Assign the created Model to the `modelRef` field of in `TrainerNeuralEvolution.cs`
26+
27+
5. Play!
28+
29+
## Explanation of fields in the inspector
30+
### TrainerNeuralEvolution.cs
31+
* `isTraining`: Toggle this to switch between training and inference mode. Note that in inference mode, the best solutions from all previous generations will be used.
32+
* `parameters`: You need to assign this field with a TrainerParamsNeuralEvolution scriptable object.
33+
* `continueFromCheckpoint`: If true, when the game starts, the trainer will try to load the saved checkpoint file to resume previous training.
34+
* `checkpointPath`: the path of the checkpoint, including the file name. Note that there are two checkpoint files for neural evolution. One is the neural network's data which can be loaded by the model directly. The other one is called `YourName_NEData.xxx`, which stores the data of current generation.
35+
* `steps`: Just to show you the current step of the training.
36+
* `currentEvaluationIndex`: The index of the child to evaluate in current generation.
37+
* `currentGeneration`: How many generations have been evolved.
38+
* `parameterDimension`: The total number of parameters to optimize.
39+
40+
### TrainerParamsNeuralEvolution
41+
* `learningRate`: Not used.
42+
* `maxTotalSteps`: Max steps the trainer will be training.
43+
* `saveModelInterval`: The trained model will be saved every this amount of steps. However, the checkpoint file for generation data is saved after each evaluation of childen.
44+
* `optimizerType`: Which MAES algorithm to use. Should choose LMMAES if the parameter dimension is big(which is common for neural network).
45+
* `populationSize`: How many childrens to evaluate for each generation.
46+
* `mode`: Whether the optimizer should maximize or minimize the value.
47+
* `initialStepSize`: Initial step size of the optimizer.
48+
* `timeHorizon`: How many steps a sample will run to evaluate it.
49+

0 commit comments

Comments
 (0)