This repository has been archived by the owner on Dec 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,123 @@ | ||
# NEAT (NeuroEvolution of Augmenting Topologies) | ||
|
||
[![GoDoc](https://godoc.org/github.com/whitewolf-studio/neat?status.svg)](https://godoc.org/github.com/whitewolf-studio/neat) | ||
![alt text](https://github.com/jinyeom/neat/blob/master/banner.png "neat") | ||
[![GoDoc](https://godoc.org/github.com/jinyeom/neat?status.svg)](https://godoc.org/github.com/jinyeom/neat) | ||
|
||
NEAT (NeuroEvolution of Augmenting Topologies) is a neuroevolution algorithm by | ||
Dr. Kenneth Stanley which evolves not only neural networks' weights but also their | ||
topologies. This package is created for optimization of neural networks for general | ||
purpose reinforcement learning, given that the user can provide a clear evaluation | ||
function. (UNDER CONSTRUCTION!) | ||
Dr. Kenneth O. Stanley which evolves not only neural networks' weights but also their | ||
topologies. | ||
|
||
## Installation | ||
To install `neat` run the following: | ||
|
||
```bash | ||
$ go get -u github.com/jinyeom/neat | ||
``` | ||
|
||
## Usage | ||
|
||
## Example | ||
This NEAT package is as simple as plug and play. All you have to do is to create | ||
a new instance of NEAT, given the configuration from a JSON file, for which the | ||
template is provided below, and an evaluation method of a neural network, and | ||
run. | ||
|
||
```json | ||
{ | ||
"numInputs": 3, | ||
"numOutputs": 1, | ||
"numGenerations": 50, | ||
"populationSize": 100, | ||
"initFitness": 9999.0, | ||
"minimizeFitness": true, | ||
"survivalRate": 0.5, | ||
"hallOfFameSize": 10, | ||
"ratePerturb": 0.2, | ||
"rateAddNode": 0.2, | ||
"rateAddConn": 0.2, | ||
"distanceThreshold": 20.0, | ||
"coeffUnmatching": 1.0, | ||
"coeffMatching": 1.0 | ||
} | ||
``` | ||
|
||
Now that you have the configuration JSON file is ready as `config.json`, we can | ||
start experiment with NEAT. Below is an example XOR experiment. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/whitewolf-studio/neat" | ||
"log" | ||
"math" | ||
|
||
// Import NEAT package after installing the package through | ||
// the instruction provided above. | ||
"github.com/jinyeom/neat" | ||
) | ||
|
||
param := NewParam("xor_param.np") | ||
toolbox := &Toolbox{ | ||
Activation: neat.NEATSet(), | ||
Comparison: neat.DirectCompare(), | ||
Evaluation: neat.XORTest(), | ||
} | ||
func main() { | ||
|
||
// First, create a new instance of Config from the JSON file created above. | ||
// If there's a file import error, the program will crash. | ||
config, err := NewConfigJSON("config.json") | ||
if err != nil{ | ||
log.Fatal(err) | ||
} | ||
|
||
// Then, we can define the evaluation function, which is a type of function | ||
// which takes a neural network, evaluates its performance, and returns some | ||
// score that indicates its performance. This score is essentially a genome's | ||
// fitness score. With the configuration and the evaluation function we | ||
// defined, we can create a new instance of NEAT and start the evolution | ||
// process. | ||
// | ||
// By passing true as an argument of Run(), we can also observe the progress | ||
// by generations. | ||
neat.New(config, func(n *neat.NeuralNetwork) float64 { | ||
score := 0.0 | ||
|
||
inputs := make([]float64, 3) | ||
inputs[0] = 1.0 // bias | ||
|
||
neat.Init(param, toolbox) | ||
// 0 xor 0 | ||
inputs[1] = 0.0 | ||
inputs[2] = 0.0 | ||
output, err := n.FeedForward(inputs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
score += math.Pow((output[0] - 0.0), 2.0) | ||
|
||
n := neat.New() | ||
n.Run() | ||
// for parallel computing, | ||
// numProcs := 4 | ||
// n.RunParallel(numProcs) | ||
// 0 xor 1 | ||
inputs[1] = 0.0 | ||
inputs[2] = 1.0 | ||
output, err = n.FeedForward(inputs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
score += math.Pow((output[0] - 1.0), 2.0) | ||
|
||
// 1 xor 0 | ||
inputs[1] = 1.0 | ||
inputs[2] = 0.0 | ||
output, err = n.FeedForward(inputs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
score += math.Pow((output[0] - 1.0), 2.0) | ||
|
||
// 1 xor 1 | ||
inputs[1] = 1.0 | ||
inputs[2] = 1.0 | ||
output, err = n.FeedForward(inputs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
score += math.Pow((output[0] - 0.0), 2.0) | ||
|
||
return score | ||
}).Run(true) | ||
} | ||
|
||
``` | ||
|
||
## License | ||
This package is under GNU General Public License. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.