neurotron v2.0.2
Neurotron
A simple library build on brain.js for genetic evolution, NEAT etc.
About
Neurotron uses brain.js NeuralNetwork and provides a couple of useful functions to perform genetic evolution with it.
Installation and Usage
NPM
npm i neurotron
Neurotron is dependent on brain.js, consult https://www.npmjs.com/package/brain.js#Installation-and-Usage for it's information if any problems occur.
Examples
Here's an example, showcasing how to create and use a basic neurotron.
import Neurotron from "neurotron";
/**
* Creating a neurotron with 5 inputs, 1 hiddenlayer with 5 neurons and 5 outputs
*/
const neurotron = new Neurotron(Neurotron.createNetwork(5, [5], 5))
/**
* Getting the neurotron's output, given the input [1, 1, 1, 1, 1]
*/
const output = neurotron.getOutput([1, 1, 1, 1, 1])
/**
* Cloning a neurotron
*/
const neurotronClone = neurotron.clone()
/**
* Mutating a neurotron with a rate of 0.5
*/
neurotron.mutate(0.5)
Methods
Neurotron.createNetwork(inputSize: number, hiddenLayers: number[], outputSize: number) -> NeuralNetwork
The function to use to create a randomized starting NeuralNetwork, hiddenLayers should specify an array where each number n represents a layer with n neurons.
getOutput(input: number[]) -> output: number[]
The input should have the same length as the specified inputs in the constructor.
clone() -> Neurotron
To clone a neurotron.
cloneNetwork() -> NeuralNetwork
This method gets used internally, and shouldn't be needed.
mutate(rate: number)
Mutates the neurotron directly, where the rate should be between 0 and 1, where 0 means nothing will be mutated and 1 means everything will be mutated fully.
getMutation(base: number, rate: number) -> mutatedBase: number
Mutates a number, based on the rate.
Issues
If you have any issues, you can create a github issue at:
https://github.com/sjoegd/neurotron