Esempio n. 1
0
 def setUp(self):
     self.expName = 'test_experiment_unit_tests'
     self.exp = ro.Experiment(
         self.expName, {
             'param1': ro.Uniform(low=0.0, high=100.0, dtype='int'),
             'param2': ro.Normal(mean=100, std=10, dtype='int'),
         })
Esempio n. 2
0
def run_ro(init, num_epochs):
    param = init

    e = ro.Experiment('ro_example', {'alpha': ro.Uniform(low=0.0, high=0.01)})
    e.sample_all_params()

    for epoch in range(num_epochs):
        param = param - e.alpha * dloss(param)
    e.add_result(loss(param))
    return e
Esempio n. 3
0
def run_hb(init, num_epochs):
    param = init

    e = ro.HyperBand('hb_example', {'alpha': ro.Uniform(low=0.0, high=0.01)},
                     num_iter=num_epochs)
    e.sample_all_params()

    for epoch in range(num_epochs):
        param = param - e.alpha * dloss(param)
        if e.stop(loss(param)):
            return e
    e.add_result(loss(param))
    return e
Esempio n. 4
0
#!/usr/bin/env python

import randopt as ro
from bonn import Bonn

def loss(x, y, z):
    return x**2 + y**2 + z**2

if __name__ == '__main__':
    e = ro.Experiment('bo_simple', {
        'x': ro.Choice([0.0, 1, 2, 3, 4, 5, 6, 7]),
        'y': ro.Gaussian(0.0, 3.0),
        'z': ro.Uniform(0.0, 1.0),
        })

    bo = Bonn(e)

    e.sample_all_params()
    res = loss(e.x, e.y, e.z)
    e.add_result(res)

    for i in xrange(200):
        bo.fit()
        bo.sample(e)
        res = loss(e.x, e.y, e.z)
        print res
        e.add_result(res, {
            'trial': i
            })
Esempio n. 5
0
 def test_raise_with_param_named_result(self):
     with self.assertRaises(ValueError):
         ro.Experiment(
             'invalid experiment', {
                 'result': ro.Uniform(low=0.0, high=100.0, dtype='int'),
             })
Esempio n. 6
0
#!/usr/bin/env python

import randopt as ro

def loss(w, x, y, z):
    return w**2 + x**2 + y**2 + z**2

if __name__ == '__main__':

    e = ro.Experiment('multi_params_example', {
            'dog': ro.Normal(mean=0.0, std=1.0, dtype='float'),
            'cat': ro.Uniform(low=-1.0, high=1.0, dtype='float'),
            'dolphin': ro.LognormVariate(mean=0.0, std=1.0, dtype='float'),
            'any_name': ro.Choice([0.01, 0.05, 0.1, 0.5, 0.7, 0.9], sampler=ro.Uniform()),
        })

    # Seeding will make all of your searches reproducible. (Usually not wanted)
    e.seed(1234)

    # Randomly sampling parameters
    for i in range(100):
        e.sample_all_params()
        res = loss(e.dog, e.cat, e.dolphin, e.any_name)
        print('Result: ', res)
        # Example of using the second parameter
        e.add_result(res, data={
            'sup.data': [e.dog, e.cat, e.dolphin, e.any_name]
        })

    # Save/load the state of the random number generators
    e.save_state('./multi_params_state.pk')
Esempio n. 7
0
#!/usr/bin/env python3

import randopt as ro
from random import random

def loss(x, y):
    return [(x**2 + y**2 + random()) / i for i in range(1, 51)]

if __name__ == '__main__':
    exp = ro.Experiment('quadratic', params={
        'x': ro.Gaussian(),
        'y': ro.Uniform(-0.5, 0.5)
    })

    for _ in range(20):
        exp.sample_all_params()
        conv = loss(exp.x, exp.y)
        exp.add_result(conv[-1], data={
            'convergence': conv
        })