GithubHelp home page GithubHelp logo

pysurrogate's Introduction

pysurrogate - Surrogate Models

The aim of this project is to build an interface to find the best surrogate for observations made on a blackbox function. The nature of a blackbox function do not let us make any assumptions about the data and therefore the model selection needs to be done more carefully.

Installation

pip install pysurrogate

Surrogates

Currently the following surrogate models are implemented:

  • DACE (Matlab Version, matlab library for python needs to be installed)
  • RBF (Scipy)
  • NN (pytorch)

Usage

The method that should be used for interfacing is the pysurrogate.optimize.fit and pysurrogate.optimize.predict method.

import numpy as np
import matplotlib.pyplot as plt
from pysurrogate.optimize import fit, predict


if __name__ == '__main__':
    # number of samples we will use for this example
    n_samples = 20

    # ---------------------------------------------------------
    # Example 1: One input variable and one target
    # ---------------------------------------------------------

    X = np.random.rand(n_samples, 1) * 4 * np.pi
    Y = np.cos(X)

    # fit the model and predict the data
    model = fit(X, Y, n_folds=3, disp=True, normalize_X=True, normalize_Y=True)
    _X = np.linspace(0, 4 * np.pi, 1000)
    _Y = predict(model, _X)

    plt.scatter(X, Y, label="Observations")
    plt.plot(_X, _Y, label="True")
    plt.show()

    # ---------------------------------------------------------
    # Example 2: Two input variables and two targets.
    #            Normalize before building the model and use only an RBF implementation with a specific kernel
    #            Finally validate the model error on the true function.
    # ---------------------------------------------------------

    X = (np.random.rand(n_samples, 2) * 200) + 500
    func_eval = lambda X: np.concatenate([np.sum(np.square(X), axis=1)[:, None], np.sum(np.sqrt(X), axis=1)[:, None]], axis=1)
    Y = func_eval(X)

    # fit the model and predict the data
    model = fit(X, Y, n_folds=3, disp=True, normalize_X=True, normalize_Y=True)

    # create two dimensional data to test the
    M = np.meshgrid(np.linspace(100, 200, 1000), np.linspace(100, 200, 1000))
    _X = np.concatenate([X[:, :, None] for e in X], axis=2).reshape(n_samples * n_samples, 2)
    _Y = predict(model, _X)
    print(np.mean(np.abs(_Y - func_eval(_X)), axis=0))

Contact

Feel free to contact me if you have any question:

Julian Blank (blankjul [at] egr.msu.edu)
Michigan State University
Computational Optimization and Innovation Laboratory (COIN)
East Lansing, MI 48824, USA

pysurrogate's People

Contributors

blankjul avatar

Watchers

 avatar  avatar

Forkers

mberkanbicer

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.