I imported all this stuff under the assumption that I could use it, eventually.


In [2]:
import pandas
import ctn_benchmark
import seaborn as sns

%matplotlib inline
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from hyperopt import fmin, hp, tpe, Trials 
import pickle

Apparently I cannot use it, since the trials object won't work (this is a python 2/3 compataility thing). One potential solution would be to iopen this as a python2 notebook but I have yet to figure out how to do that.

For now, the workaround is to run this code (found in the script hyperopt_helper.py) as a python2 file and hope that it works.


In [6]:
# define the objective, in which we want the value of 
# curve_width - 10 and shift - 5 to be minimized

# The parameters that we want to change must be childhood, t_glasses_on, and 
# the intercept range (maybe??)
import owl_parameter_search_intercepts
def objective(x):
    vals = owl_parameter_search_intercepts.Owl().run(
        childhood = x['childhood'], t_glasses_on = x['t_glasses_on']
    )
    return {
        'loss': {
            abs(vals['curve_width'] - 10) + abs(vals['shift'] - 5),
        },
        'status': STATUS_OK,
    }
fred = Trials()
best = fmin(objective,
            space = {'childhood': hp.uniform('childhood', 10, 10000), 't_glasses_on': hp.uniform('t_glasses_on', 10, 10000)},
            algo = tpe.suggest,
            max_evals = 10,
            trials = fred
           )
pickle.dump({'Trials': fred, 'Best': best}, open ('owl_hyperopt_data', 'w'))


running Owl#20160627-120206-79b7a2b0
Simulation finished in 0:00:06.                                                 
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-6-201b25553e03> in <module>()
     19             space = {'childhood': hp.uniform('childhood', 10, 10000), 't_glasses_on': hp.uniform('t_glasses_on', 10, 10000)},
     20             algo = tpe.suggest,
---> 21             max_evals = 10,
     22             #trials = fred
     23            )

/home/stacy/anaconda3/lib/python3.5/site-packages/hyperopt/fmin.py in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
    317                     verbose=verbose)
    318     rval.catch_eval_exceptions = catch_eval_exceptions
--> 319     rval.exhaust()
    320     if return_argmin:
    321         return trials.argmin

/home/stacy/anaconda3/lib/python3.5/site-packages/hyperopt/fmin.py in exhaust(self)
    196     def exhaust(self):
    197         n_done = len(self.trials)
--> 198         self.run(self.max_evals - n_done, block_until_done=self.async)
    199         self.trials.refresh()
    200         return self

/home/stacy/anaconda3/lib/python3.5/site-packages/hyperopt/fmin.py in run(self, N, block_until_done)
    170             else:
    171                 # -- loop over trials and do the jobs directly
--> 172                 self.serial_evaluate()
    173 
    174             if stopped:

/home/stacy/anaconda3/lib/python3.5/site-packages/hyperopt/fmin.py in serial_evaluate(self, N)
     87                 ctrl = base.Ctrl(self.trials, current_trial=trial)
     88                 try:
---> 89                     result = self.domain.evaluate(spec, ctrl)
     90                 except Exception as e:
     91                     logger.info('job exception: %s' % str(e))

/home/stacy/anaconda3/lib/python3.5/site-packages/hyperopt/base.py in evaluate(self, config, ctrl, attach_attachments)
    836                 memo=memo,
    837                 print_node_on_error=self.rec_eval_print_node_on_error)
--> 838             rval = self.fn(pyll_rval)
    839 
    840         if isinstance(rval, (float, int, np.number)):

<ipython-input-6-201b25553e03> in objective(x)
      7 def objective(x):
      8     vals = owl_parameter_search_intercepts.Owl().run(
----> 9         childhood = x['childhood'], t_glasses_on = x['t_glasses_on']
     10     )
     11     return {

/home/stacy/github/owl/ctn_benchmarks_owlspecific/ctn_benchmark/benchmark.py in run(self, **kwargs)
    123         self.start_time = time.time()
    124         self.sim_speed = None
--> 125         result = self.evaluate(p, sim, plt)
    126 
    127         if p.backend == 'nengo_spinnaker':

/home/stacy/github/owl/ctn_benchmarks_owlspecific/ctn_benchmark/nengo/owl_parameter_search_intercepts.py in evaluate(self, p, sim, plt)
    146     def evaluate(self, p, sim, plt):
    147 
--> 148         sim.run(self.training2)
    149 
    150         y = sim.data[self.probe]

/home/stacy/anaconda3/lib/python3.5/site-packages/nengo/simulator.py in run(self, time_in_seconds, progress_bar)
    262         logger.info("Running %s for %f seconds, or %d steps",
    263                     self.model.label, time_in_seconds, steps)
--> 264         self.run_steps(steps, progress_bar=progress_bar)
    265 
    266     def run_steps(self, steps, progress_bar=True):

/home/stacy/anaconda3/lib/python3.5/site-packages/nengo/simulator.py in run_steps(self, steps, progress_bar)
    282         with ProgressTracker(steps, progress_bar) as progress:
    283             for i in range(steps):
--> 284                 self.step()
    285                 progress.step()
    286 

/home/stacy/anaconda3/lib/python3.5/site-packages/nengo/simulator.py in step(self)
    293         try:
    294             for step_fn in self._steps:
--> 295                 step_fn()
    296         finally:
    297             np.seterr(**old_err)

/home/stacy/anaconda3/lib/python3.5/site-packages/nengo/builder/neurons.py in step_simneurons()
     66 
     67         def step_simneurons():
---> 68             self.neurons.step_math(dt, J, output, *states)
     69         return step_simneurons
     70 

/home/stacy/anaconda3/lib/python3.5/site-packages/nengo/neurons.py in step_math(self, dt, J, spiked, voltage, refractory_time)
    311         # set voltages of neurons still in their refractory period to 0
    312         # and reduce voltage of neurons partway out of their ref. period
--> 313         voltage *= (1 - refractory_time / dt).clip(0, 1)
    314 
    315         # determine which neurons spike (if v > 1 set spiked = 1/dt, else 0)

KeyboardInterrupt: 

In [ ]:
print (best)

In [ ]:
data = pickle.load(open('owl_hyperopt_data','r'))