Swiftpack.co - ejjonny/swift-slime as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ejjonny.
ejjonny/swift-slime 2.0.1
A lightweight stochastic optimizer based on slime mold (Slime Mold Algorithm)
⭐️ 5
🕓 1 year ago
.package(url: "https://github.com/ejjonny/swift-slime.git", from: "2.0.1")

Slime

This is a Swift implementation of a Slime Mold Algorithm - a stochastic optimizer - generally based on this paper

The only dependency required by Slime is SwiftNumerics

Visual Examples

Searching for the global maxima of -abs(x + 100000) - abs(y + 100000) + sin(10 * x)

Searching for the shortest path visiting 50 locations (traveling salesman)

Use the Slime

In a SwiftPM project:

Add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/ejjonny/slime", from: "2.0.0"),

Add Slime as a dependency for your target:

.target(
    name: "MyTarget", 
    dependencies: [
        .product(name: "Slime", package: "Slime"),
    ]
),

Add import Slime to your swift file.

var slime = Slime(
                populationSize: 10,
                maxIterations: 100,
                lower: SIMD2(-1, -1),
                upper: SIMD2(1, 1),
                method: .minimize, // Use .maximize if higher fitness values are better
                fitnessEvaluation: { vector in
                    let x = vector[0]
                    let y = vector[1]
                    // Return a fitness value Double using the proposed vector
                }
            )
slime.run() // This runs the fitness evaluation many times, among other busy work, & will usually be expensive

slime.bestCells // An array of the top 3 Cells. Use Cell.position for the associated vectors

This example is using a 2 dimensional solution space. The algorithm will work with any number of vector components if you're looking for a solution in hyperspace.

More Info

wikiversity

"Slime mold algorithm (SMA) is a population-based optimization technique which is proposed based on the oscillation style of slime mold in nature. The SMA has a unique mathematical model that simulates positive and negative feedbacks of the propagation wave of slime mold. It has a dynamic structure with a stable balance between global and local search drifts."

TODO:

  • Readme walkthrough of the math used in the algorithm
  • Explore some deterministic changes

GitHub

link
Stars: 5
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2.0.1
1 year ago

Readme update

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics