A lightweight Kotlin Multiplatform library for neural network evolution based on the NEAT algorithm.
NEAT (NeuroEvolution of Augmenting Topologies) is a genetic algorithm for evolving artificial neural networks. It was developed by Kenneth O. Stanley in 2002 and has several key features:
- Evolves both network weights and structure
- Preserves innovation through speciation
- Starts with minimal networks and grows complexity as needed
- Efficiently solves complex control and decision tasks
Kotlineat provides a clean, Kotlin-native implementation of NEAT with a powerful DSL for creating and evolving neural networks.
// For Kotlin Multiplatform projects
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.wildware:kotlineat:0.1.0")
}
}
}
}
// For single-platform projects
dependencies {
implementation("io.github.wildware:kotlineat:0.1.0")
}// For Kotlin Multiplatform projects
kotlin {
sourceSets {
commonMain {
dependencies {
implementation 'io.github.wildware:kotlineat:0.1.0'
}
}
}
}
// For single-platform projects
dependencies {
implementation 'io.github.wildware:kotlineat:0.1.0'
}<dependency>
<groupId>io.github.wildware</groupId>
<artifactId>kotlineat</artifactId>
<version>0.1.0</version>
</dependency>Kotlineat provides a DSL for creating neural networks:
// Create a simple network with 2 inputs, 1 hidden node, and 1 output
val network = buildNeat {
activation = ActivationFunction.Tanh
inputSize = 2
outputSize = 1
val hidden = hidden()
connect(input(0), hidden, weight = 0.5f)
connect(input(1), hidden, weight = 0.3f)
connect(hidden, output(0), weight = 0.8f)
}
// Calculate outputs for given inputs
val result = network.calculate(listOf(1.0f, 0.5f))
println("Output: ${result[0]}")val network = buildNeat {
activation = ActivationFunction.Sigmoid
inputSize = 3
outputSize = 2
val hidden1 = hidden()
val hidden2 = hidden()
// Connect inputs to hidden nodes
connect(input(0), hidden1, weight = 0.5f)
connect(input(1), hidden1, weight = 0.3f)
connect(input(1), hidden2, weight = 0.2f)
connect(input(2), hidden2, weight = 0.4f)
// Connect hidden nodes to outputs
connect(hidden1, output(0), weight = 0.7f)
connect(hidden2, output(0), weight = 0.1f)
connect(hidden1, output(1), weight = 0.2f)
connect(hidden2, output(1), weight = 0.9f)
}You can split existing connections to create more complex network topologies:
val network = buildNeat {
activation = ActivationFunction.Tanh
inputSize = 1
outputSize = 1
val conn = connect(input(0), output(0), weight = 0.8f)
// Split the connection, creating a new hidden node
splitConnection(conn, weight1 = 0.5f, weight2 = 0.6f)
}- 🧠 Flexible Neural Networks: Create networks with any number of inputs, outputs, and hidden nodes
- 🔌 Connection Management: Add, remove, and modify connections between nodes
- 📊 Multiple Activation Functions: Choose from Sigmoid, Tanh, and Linear activation functions
- 🛠️ DSL Builder: Intuitive Kotlin DSL for creating and configuring networks
- 🧬 Topological Sorting: Ensures correct forward propagation through the network
- 🔄 Connection Splitting: Easily split connections to create more complex network structures
- 📱 Multiplatform Support: Works on JVM, with more platforms coming soon
For detailed documentation and advanced usage examples, visit our GitHub Wiki.
API reference is available at kotlineat.wildware.io/api.
Contributions are welcome! If you'd like to contribute, please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the project guidelines:
- Keep code clean, maintainable and pragmatic
- Unit test as much code as possible
- Avoid using // comments, prefer using well-named functions and variables
- Use KDoc comments on public methods/properties
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Kenneth O. Stanley for the original NEAT algorithm
- The Kotlin team for the amazing language and multiplatform capabilities
- All contributors who help make this project better
Made with ❤️ by Wildware