예제 #1
0
def get_sample_experiment():
    from hyperopt.pyll.stochastic import sample
    from pylearn2.config import yaml_parse
    from os.path import join
    import sys
    sys.path.append('..')
    from hyperopt_api.parser import build
    from yaml_parser import yaml_parser as yp
    from hyperopt_api.search_space import get_search_space
    import configuration.model as config
    from utils.common import get_timestamp

    # prepare all variables that don't need to be updated with each iteration
    spa = get_search_space()    # define search space over possible models

    path = config.data_path

    # obtain the yaml skelton
    with open(config.yaml_skelton_path) as f:
        default_string = f.read()

    samp = sample(spa)  # generate sample (will give a description of a model)
    mod = build(samp)   # based on description generated build an object that will fit into yaml_paser

    # define weight decay parameters. They depend on the number of layers (there is one parameter fo each layer)
    weight_decay_coeffs = yp.parse_weight_decay(mod)

    # generate a filename to store the best model
    pkl_filename = join(config.path_for_storing, get_timestamp() + "_best.pkl")

    # create dictionary with hyper parameters
    hyper_params = {'model': yp.parse_to_yaml(mod), 'path': yp.parse_to_yaml(path),
                    'weight_decay_coeffs': weight_decay_coeffs, 'pkl_filename': pkl_filename}
    # fill the yaml skelton with hyperparameters
    yaml_string = default_string % hyper_params

    network = yaml_parse.load(yaml_string)

    return network
예제 #2
0
from hyperopt.pyll.stochastic import sample
from parser import build
from pylearn2.config import yaml_parse
from os.path import join
import traceback
import sys
sys.path.append('..')
from yaml_parser import yaml_parser as yp
from utils.common import notify, get_timestamp
from hyperopt_api.search_space import get_search_space
from blessings import Terminal
t = Terminal()
import configuration.model as config

# prepare all variables that don't need to be updated with each iteration
spa = get_search_space()    # define search space over possible models

# define data paths
path = config.data_path

# obtain the yaml skelton
with open(config.yaml_skelton_path) as f:
    default_string = f.read()

# for each sample that will be generated from search space space
for i in xrange(20):
    timestamp = get_timestamp()

    print t.bold_red('ITERATION:'), t.bold_red(str(i)), "started at: ", timestamp

    samp = sample(spa)  # generate sample (will give a description of a model)