This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Simple python wrapper to SMAC, a versatile tool for optimizing algorithm parameters.

fmin(objective, x0, xmin, xmax, x0_int, xmin_int, xmax_int, xcategorical, params)
   min_x f(x) s.t. xmin < x < xmax

 objective: The objective function that should be optimized.

Installation

Pip

pip install pysmac

Manual

python setup.py install

Example usage

Let’s take for example the Branin function. (Note that the branin function is not the ideal use case for SMAC, which is designed to be a global optimization tool for costly functions. That said, it’ll serve the purpose of checking that everything is working.)

import numpy as np

def branin(x):
    b = (5.1 / (4.*np.pi**2))
    c = (5. / np.pi)
    t = (1. / (8.*np.pi))
    return 1.*(x[1]-b*x[0]**2+c*x[0]-6.)**2+10.*(1-t)*np.cos(x[0])+10.

For x1 ∈ [-5, 10], x2 ∈ [0, 15] the function reaches a minimum value of: 0.397887.

Note: fmin accepts any function that has a parameter called x (the input array) and returns an objective value.

from pysmac.optimize import fmin

xmin, fval = fmin(branin, x0=(0,0),xmin=(-5, 0), xmax=(10, 15), max_evaluations=5000)

As soon as the evaluations are finished, we can check the output:

>>> xmin
{'x': array([ 3.14305644,  2.27827543])}

>>> fval
0.397917

Let’s run the objective function with the found parameters:

>>> branin(**xmin)
0.397917

License

SMAC is free for academic & non-commercial usage. Please contact Frank Hutter to discuss obtaining a license for commercial purposes.

Advanced

Custom arguments to the objective function:

Note: make sure there is no naming collission with the parameter names and the custom arguments.

def minfunc(x, custom_arg1, custom_arg2):
    print "custom_arg1:", custom_arg1
    print "custom_arg2:", custom_arg2
    return 1


xmin, fval = fmin(minfunc, x0=(0,0),xmin=(-5, 0), xmax=(10, 15),
                  max_evaluations=5000,
                  custom_args={"custom_arg1": "test",
                               "custom_arg2": 123})

Integer parameters

Integer parameters can be encoded as follows:

def minfunc(x, x_int):
    print "x: ", x
    print "x_int: ", x_int
    return 1.

xmin, fval = fmin(minfunc,
                  x0=(0,0), xmin=(-5, 0), xmax=(10, 15),
                  x0_int=(0,0), xmin_int=(-5, 0), xmax_int=(10, 15),
                  max_evaluations=5000)

Categorical parameters

Categorical parameters can be specified as a dictionary of lists of values they can take on, e.g.:

categorical_params = {"param1": [1,2,3,4,5,6,7],
                      "param2": ["string1", "string2", "string3"]}

def minfunc(x_categorical):
    print "param1: ", x_categorical["param1"]
    print "param2: ", x_categorical["param2"]
    return 1.

xmin, fval = fmin(minfunc,
                  x_categorical=categorical_params,
                  max_evaluations=5000)
Release History

Release History

0.8

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pysmac-0.8.tar.gz (9.5 MB) Copy SHA256 Checksum SHA256 Source Jul 8, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting