GithubHelp home page GithubHelp logo

rcmaes's Introduction

Rust libcmaes bindings

This is a simple library that lets you optimize some model. If you can implement a trait that turns a struct into a Vec<f64> and back (i.e. there is an isomorphism between them), then you can pass it to CMA-ES library.

The C++ CMA-ES project is located here: https://github.com/beniz/libcmaes

I'm using this mostly for some personal projects so it's not all that comprehensive. The bindings implement just enough that you can adjust most important parameters and run heavy optimization concurrently and with reasonable efficiency.

Example

extern crate rcmaes;

use rcmaes::{optimize, CMAESParameters, Vectorizable};

// This example "trains" a very simple model to go to point (2, 8)
#[derive(Clone)]
struct TwoPoly {
    x: f64,
    y: f64,
}

// Vectorizable is essential to specify how to turn something into a Vec<f64>
// and back.
impl Vectorizable for TwoPoly {
    type Context = ();

    fn to_vec(&self) -> (Vec<f64>, Self::Context) {
        (vec![self.x, self.y], ())
    }

    fn from_vec(vec: &[f64], _: &Self::Context) -> Self {
        TwoPoly {
            x: vec[0],
            y: vec[1],
        }
    }
}

fn train_model()
{
    let optimized = optimize(
        &TwoPoly { x: 5.0, y: 6.0 },
        &CMAESParameters::default(),
        |twopoly| (twopoly.x - 2.0).abs() + (twopoly.y - 8.0).abs(),
    ).unwrap();

    let model = optimized.0;
    assert!((model.x - 2.0).abs() < 0.00001);
    assert!((model.y - 8.0).abs() < 0.00001);
}

rcmaes's People

Contributors

noeda avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.