https://github.com/timerertim/knevo
Knevo is a neuroevolution library for Java and Kotlin written purely in Kotlin, featuring multiple neuroevolution algorithms, serialization and multi-threading.
https://github.com/timerertim/knevo
jvm machine-learning neural-network neuroevolution
Last synced: 4 months ago
JSON representation
Knevo is a neuroevolution library for Java and Kotlin written purely in Kotlin, featuring multiple neuroevolution algorithms, serialization and multi-threading.
- Host: GitHub
- URL: https://github.com/timerertim/knevo
- Owner: TimerErTim
- License: mit
- Created: 2021-08-19T04:58:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T12:36:23.000Z (almost 4 years ago)
- Last Synced: 2025-08-31T00:52:17.395Z (5 months ago)
- Topics: jvm, machine-learning, neural-network, neuroevolution
- Language: Kotlin
- Homepage:
- Size: 304 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Knevo
[

](https://github.com/TimerErTim/Knevo/blob/master/LICENSE)
[

](https://github.com/TimerErTim/Knevo/actions/workflows/check.yml)
[

](https://search.maven.org/artifact/eu.timerertim.knevo/knevo)

A neuroevolution library for Java and Kotlin written purely in Kotlin, featuring multiple neuroevolution algorithms,
serialization and multi-threading.
## Table of Contents
1. [Installation](#installation)
2. [Content](#content)
3. [Usage](#usage)
4. [License](#license)
5. [Project State](#project-state)
## Installation
From Maven Central:
Maven
```xml
eu.timerertim.knevo
knevo
0.2.0-RC
```
Gradle Groovy
```groovy
dependencies {
implementation 'eu.timerertim.knevo:knevo:0.2.0-RC'
}
```
Gradle KTS
```kotlin
dependencies {
implementation("eu.timerertim.knevo:knevo:0.2.0-RC")
}
```
## Content
Algorithms:
- [x] [Instinct](https://towardsdatascience.com/neuro-evolution-on-steroids-82bd14ddc2f6)
- [ ] [NEAT](http://nn.cs.utexas.edu/keyword?stanley:ec02)
- [ ] [SUNA](https://paperswithcode.com/paper/spectrum-diverse-neuroevolution-with-unified)
- [ ] [AGENT]()
Features:
- Serialization
- Multithreading using Coroutines
- Custom Activation Functions
## Usage
### Environment
You must implement the `Environment` interface and override the `evaluateFitness(population: List)` function.
For each `Genome` in the population, you want to set its fitness.
### Instances
Everything requires an Instance. It is the interface to an algorithm implementation.
```kotlin
val instance = InstinctInstanceBuilder(2, 1)
.mutateAddSelfConnectionChance(0F)
.mutateAddRecurrentConnectionChance(0F)
.mutateRemoveConnectionChance(2.15F)
.hiddenActivations(Sigmoid(), Tanh(), Step(), Sign(), Linear(), Sinus(), Relu(), Selu(), Silu())
.outputActivations(Sign())
.build()
```
```kotlin
val network = instance.Network()
println(network(floatArrayOf(0F, 1F)))
```
The Instance can be set globally, so you don't have to explicitly specify the Instance everytime.
```kotlin
globalInstinctInstance = InstinctInstance(2, 1)
```
```kotlin
val network = Network()
println(network(floatArrayOf(0F, 1F)))
```
### Training
You can use individual `Networks` like above. However, you typically want to make use of a bigger population.
```kotlin
val pool = Pool(
populationSize = 500,
select = Tournament(10)
)
```
You can use this and some environment to write a training loop.
```kotlin
do {
pool.evolve(environment)
} while(pool.topFitness < 100)
```
Finally, the trained `Genome` can be retrieved.
```kotlin
val network = pool.topGenome
```
### Coroutines
This library supports multithreading by using Coroutines. `Populations` are separated into batches, which are processed
in parallel. This behavior can be configured on every `Population`.
```kotlin
val pool = PoolBuilder()
.populationSize(200)
.batchSize(50)
.build()
```
Note that when using this feature, the `Environment` has to be thread safe as multiple `Genomes` are evaluated in
parallel.
### Serialization
You can easily save any `Network` or `Pool`:
```kotlin
network.save("out/my_trained_network.knv")
```
And load it as easily:
```kotlin
val network: InstinctNetwork = load("out/my_trained_network.knv") ?: Network()
```
Because the load function returns null if the specified file does not yet exist, you can easily define an
initiative `Network` or `Pool`.
## License
Knevo is licensed under the [MIT License](LICENSE).
## Project State
I, the project owner, am currently attending
the [higher technical college of Grieskirchen](https://github.com/HTBLA-Grieskirchen). My education takes me about as
much time as a full time job, not counting homework and similar tasks. In addition, I also have a part-time job. Because
of this, the development pace is not as fast as one may expect. Nonetheless, I like to extend this library as demanded.
Just be aware that development might be or become a little slow.