Permalink
Browse files

NerualNet ready for actually net

There appears to be some issues with multiprocessing and gaussian
process but only on MacOS, and possibly just my machine. So I’ve
removed all the testing statements I had in the previous commit.

Branch should be ready now to integrate in a genuine NN.
  • Loading branch information...
1 parent 97d5b23 commit e8a87155d61406e8f0d06c986883e085a6c93eff @michaelhush committed Dec 1, 2016
Showing with 1 addition and 27 deletions.
  1. +0 −8 mloop/controllers.py
  2. +1 −19 mloop/learners.py
View
@@ -338,7 +338,6 @@ def optimize(self):
log.info('Controller finished. Closing down M-LOOP. Please wait a moment...')
except ControllerInterrupt:
self.log.warning('Controller ended by interruption.')
- '''
except (KeyboardInterrupt,SystemExit):
log.warning('!!! Do not give the interrupt signal again !!! \n M-LOOP stopped with keyboard interupt or system exit. Please wait at least 1 minute for the threads to safely shut down. \n ')
log.warning('Closing down controller.')
@@ -348,7 +347,6 @@ def optimize(self):
self.log.warning('Safely shut down. Below are results found before exception.')
self.print_results()
raise
- '''
self._shut_down()
self.print_results()
self.log.info('M-LOOP Done.')
@@ -707,23 +705,17 @@ def _optimization_routine(self):
ml_count = 0
while self.check_end_conditions():
- print('1-1.')
self.log.info('Run:' + str(self.num_in_costs +1))
if ml_consec==self.generation_num or (self.no_delay and self.ml_learner_params_queue.empty()):
- print('1-2.')
next_params = self._next_params()
- print('1-3.')
self._put_params_and_out_dict(next_params)
ml_consec = 0
else:
- print('1-4.')
next_params = self.ml_learner_params_queue.get()
- print('1-5.')
super(MachineLearnerController,self)._put_params_and_out_dict(next_params, param_type=self.machine_learner_type)
ml_consec += 1
ml_count += 1
if ml_count==self.generation_num:
- print('1-6.')
self.new_params_event.set()
ml_count = 0
View
@@ -1269,7 +1269,6 @@ def fit_gaussian_process(self):
'''
Fit the Gaussian process to the current data
'''
- print('3-1')
self.log.debug('Fitting Gaussian process.')
if self.all_params.size==0 or self.all_costs.size==0 or self.all_uncers.size==0:
self.log.error('Asked to fit GP but no data is in all_costs, all_params or all_uncers.')
@@ -1279,7 +1278,6 @@ def fit_gaussian_process(self):
self.gaussian_process.alpha_ = self.scaled_uncers
self.gaussian_process.fit(self.all_params,self.scaled_costs)
- print('3-2')
if self.update_hyperparameters:
self.fit_count += 1
@@ -1297,10 +1295,7 @@ def fit_gaussian_process(self):
else:
self.length_scale = last_hyperparameters['length_scale']
self.length_scale_history.append(self.length_scale)
- print('3-3')
- print(repr(self.length_scale))
- print(repr(self.noise_level))
-
+
def update_bias_function(self):
'''
@@ -1317,10 +1312,7 @@ def predict_biased_cost(self,params):
Returns:
pred_bias_cost (float): Biased cost predicted at the given parameters
'''
- #print('2-8-1-1.')
- #(pred_cost, pred_uncer) = (self.gaussian_process.predict(params[np.newaxis,:]), 0.1)
(pred_cost, pred_uncer) = self.gaussian_process.predict(params[np.newaxis,:], return_std=True)
- #print('2-8-1-2.')
return self.cost_bias*pred_cost - self.uncer_bias*pred_uncer
def find_next_parameters(self):
@@ -1331,20 +1323,15 @@ def find_next_parameters(self):
next_params (array): Returns next parameters from biased cost search.
'''
self.params_count += 1
- print('2-6.')
self.update_bias_function()
self.update_search_params()
next_params = None
next_cost = float('inf')
- print('2-7.')
for start_params in self.search_params:
- print('2-8-1.')
result = so.minimize(self.predict_biased_cost, start_params, bounds = self.search_region, tol=self.search_precision)
- print('2-8-2.')
if result.fun < next_cost:
next_params = result.x
next_cost = result.fun
- print('2-9.')
return next_params
def run(self):
@@ -1359,18 +1346,13 @@ def run(self):
while not self.end_event.is_set():
#self.log.debug('Learner waiting for new params event')
self.save_archive()
- print('2-1.')
self.wait_for_new_params_event()
#self.log.debug('Gaussian process learner reading costs')
- print('2-2.')
self.get_params_and_costs()
- print('2-4.')
self.fit_gaussian_process()
for _ in range(self.generation_num):
- print('2-5.')
self.log.debug('Gaussian process learner generating parameter:'+ str(self.params_count+1))
next_params = self.find_next_parameters()
- print('2-10.')
self.params_out_queue.put(next_params)
if self.end_event.is_set():
raise LearnerInterrupt()

0 comments on commit e8a8715

Please sign in to comment.