def test_nnet_rectangles(): rectangles_eval_fn = partial(eval_fn, protocol_cls=RectanglesVectorXV) fmin_pass_expr_memo_ctrl(rectangles_eval_fn) trials = hyperopt.Trials() hyperopt.fmin( rectangles_eval_fn, space=nnet1_preproc_space(sup_min_epochs=20, sup_max_epochs=40), max_evals=10, algo=hyperopt.rand.suggest, trials=trials, )
def test_nnet_mrbi(): rectangles_eval_fn = partial(eval_fn, protocol_cls=MNIST_RotatedBackgroundImages_VectorXV) fmin_pass_expr_memo_ctrl(rectangles_eval_fn) trials = hyperopt.Trials() hyperopt.fmin( rectangles_eval_fn, space=nnet1_preproc_space(sup_min_epochs=20, sup_max_epochs=40), max_evals=10, algo=hyperopt.rand.suggest, trials=trials, )
def main_convex(filename='iptrials_convex.pkl'): from skdata.larochelle_etal_2007.view import ConvexVectorXV as Protocol iptrials = get_iptrials(filename) dataset_eval_fn = partial(eval_fn, protocol_cls=Protocol) for max_evals in range(10, 50, 10): iptrials.fmin( fn=dataset_eval_fn, space=nnet1_preproc_space(), algo=tpe.suggest, max_evals=max_evals, verbose=1, pass_expr_memo_ctrl=True, ) iptrials.wait() iptrials.refresh() ofile = open(filename, 'w') cPickle.dump(iptrials, ofile) ofile.close()
def main_rectangles(filename='iptrials_rectangles.pkl'): from skdata.larochelle_etal_2007.view import RectanglesVectorXV iptrials = get_iptrials(filename) rectangles_eval_fn = partial(eval_fn, protocol_cls=RectanglesVectorXV) for max_evals in [10, 25, 50]: iptrials.fmin( fn=rectangles_eval_fn, space=nnet1_preproc_space(), algo=rand.suggest, max_evals=max_evals, verbose=1, pass_expr_memo_ctrl=True, ) iptrials.wait() iptrials.refresh() ofile = open(filename, 'w') cPickle.dump(iptrials, ofile) ofile.close()
def main_MRBI(filename='iptrials_MRBI.pkl'): from skdata.larochelle_etal_2007.view \ import MNIST_RotatedBackgroundImages_VectorXV as Protocol iptrials = get_iptrials(filename) dataset_eval_fn = partial(eval_fn, protocol_cls=Protocol) for max_evals in range(20, 100, 200): iptrials.fmin( fn=dataset_eval_fn, space=nnet1_preproc_space(), algo=tpe.suggest, max_evals=max_evals, verbose=1, pass_expr_memo_ctrl=True, ) iptrials.wait() iptrials.refresh() ofile = open(filename, 'w') cPickle.dump(iptrials, ofile) ofile.close()
def run_config(config): argd = config["argd"] def config_lookup(key): if key == "scale_mult1": return argd["W_init_algo_old_multiplier"] if key == "scale_heur1": if "old" == argd["W_init_algo"]: return 0 else: assert "Xavier" == argd["W_init_algo"] return 1 if key == "preproc": return {"raw": 0, "normalize": 1, "pca": 2}[argd["preprocessing"]] if key == "batch_size": return 0 if 20 == argd["batchsize"] else 1 if key == "nhid1": return argd["n_hid"] if key == "dist1": return 0 if argd["W_init_algo"] == "old" else 1 if key == "squash": return 0 if argd["squash"] == "tanh" else 1 if key == "colnorm_thresh": return 1e-7 if key == "l2_penalty_nz": return argd["l2_penalty"] if key == "l2_penalty": return 0 if argd["l2_penalty"] == 0 else 1 if key == "iseed": # convert from seed value to choice index return argd["iseed"] - 5 try: return argd[key] except KeyError: print "Returning GarbageCollected for %s" % key return hyperopt.pyll.base.GarbageCollected expr = nnet1_preproc_space() hps = {} expr_to_config(expr, None, hps) print config memo = {} for k, v in hps.items(): # print k, v memo[v["node"]] = config_lookup(k) print memo rval = eval_fn(expr=expr, memo=memo, ctrl=None, protocol_cls=RectanglesVectorXV) print "-" * 80 print "COMPUTED RESULTS IN TERMS OF *ERROR*" print rval["loss"] print "-" * 80 print "SAVED RESULTS IN TERMS OF *ACCURACY*" print config["result"] print "-" * 80
def run_config(config): argd = config['argd'] def config_lookup(key): if key == 'scale_mult1': return argd['W_init_algo_old_multiplier'] if key == 'scale_heur1': if 'old' == argd['W_init_algo']: return 0 else: assert 'Xavier' == argd['W_init_algo'] return 1 if key == 'preproc': return {'raw': 0, 'normalize': 1, 'pca': 2}[argd['preprocessing']] if key == 'batch_size': return 0 if 20 == argd['batchsize'] else 1 if key == 'nhid1': return argd['n_hid'] if key == 'dist1': return 0 if argd['W_init_algo'] == 'old' else 1 if key == 'squash': return 0 if argd['squash'] == 'tanh' else 1 if key == 'colnorm_thresh': return 1e-7 if key == 'l2_penalty_nz': return argd['l2_penalty'] if key == 'l2_penalty': return 0 if argd['l2_penalty'] == 0 else 1 if key == 'iseed': # convert from seed value to choice index return argd['iseed'] - 5 try: return argd[key] except KeyError: print 'Returning GarbageCollected for %s' % key return hyperopt.pyll.base.GarbageCollected expr = nnet1_preproc_space() hps = {} expr_to_config(expr, None, hps) print config memo = {} for k, v in hps.items(): #print k, v memo[v['node']] = config_lookup(k) print memo rval = eval_fn(expr=expr, memo=memo, ctrl=None, protocol_cls=RectanglesVectorXV) print '-' * 80 print 'COMPUTED RESULTS IN TERMS OF *ERROR*' print rval['loss'] print '-' * 80 print 'SAVED RESULTS IN TERMS OF *ACCURACY*' print config['result'] print '-' * 80