Skip to content

wildware-uk/kotlineat

Repository files navigation

Kotlineat 🚀

License Kotlin JVM Build Status

A lightweight Kotlin Multiplatform library for neural network evolution based on the NEAT algorithm.

What is NEAT?

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.

Installation

Gradle (Kotlin DSL)

// 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")
}

Gradle (Groovy DSL)

// 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'
}

Maven

<dependency>
    <groupId>io.github.wildware</groupId>
    <artifactId>kotlineat</artifactId>
    <version>0.1.0</version>
</dependency>

Basic Usage

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]}")

Creating More Complex Networks

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)
}

Splitting Connections

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)
}

Features

  • 🧠 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

Documentation

For detailed documentation and advanced usage examples, visit our GitHub Wiki.

API reference is available at kotlineat.wildware.io/api.

Contributing

Contributions are welcome! If you'd like to contribute, please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgements

  • 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages