Permalink
Browse files

Add (trivial) scaler back to NNL

  • Loading branch information...
1 parent 89f1e1a commit 3e4b3df1efdc22b9b3055c55dbb49b5dd77c7e96 @charmasaur charmasaur committed Dec 4, 2016
Showing with 14 additions and 7 deletions.
  1. +10 −3 mloop/learners.py
  2. +4 −4 mloop/visualizations.py
View
@@ -1655,6 +1655,12 @@ def __init__(self,
self.cost_has_noise = True
self.noise_level = 1
+ # Set up the scaler to do nothing.
+ # TODO: Figure out how to use scaling for the NN (it's a bit difficult because we don't
+ # completely re-train each time, and don't want the scaling changing without doing a complete
+ # re-train).
+ self.cost_scaler = skp.StandardScaler(with_mean=False, with_std=False)
+
self.archive_dict.update({'archive_type':'nerual_net_learner',
'bad_run_indexs':self.bad_run_indexs,
'generation_num':self.generation_num,
@@ -1684,7 +1690,9 @@ def fit_neural_net(self):
Fit the Neural Net with the appropriate topology to the data
'''
- self.neural_net_impl.fit_neural_net(self.all_params, self.all_costs)
+ self.scaled_costs = self.cost_scaler.fit_transform(self.all_costs[:,np.newaxis])[:,0]
+
+ self.neural_net_impl.fit_neural_net(self.all_params, self.scaled_costs)
def predict_cost(self,params):
'''
@@ -1940,8 +1948,7 @@ def find_global_minima(self):
self.predicted_best_parameters = curr_best_params
self.predicted_best_scaled_cost = curr_best_cost
- self.predicted_best_cost = self.predicted_best_scaled_cost
-
+ self.predicted_best_cost = float(self.cost_scaler.inverse_transform(self.predicted_best_scaled_cost))
self.archive_dict.update({'predicted_best_parameters':self.predicted_best_parameters,
'predicted_best_scaled_cost':self.predicted_best_scaled_cost,
'predicted_best_cost':self.predicted_best_cost})
View
@@ -653,7 +653,10 @@ def return_cross_sections(self, points=100, cross_section_center=None):
sample_parameters[:, ind] = cross_parameter_arrays[ind]
costs = self.predict_costs_from_param_array(sample_parameters)
cost_arrays.append(costs)
- cross_parameter_arrays = np.array(cross_parameter_arrays)/self.cost_scaler.scale_
+ if self.cost_scaler.scale_:
+ cross_parameter_arrays = np.array(cross_parameter_arrays)/self.cost_scaler.scale_
+ else:
+ cross_parameter_arrays = np.array(cross_parameter_arrays)
cost_arrays = self.cost_scaler.inverse_transform(np.array(cost_arrays))
return (cross_parameter_arrays,cost_arrays)
@@ -683,6 +686,3 @@ def plot_cross_sections(self):
for ind in range(self.num_params):
artists.append(plt.Line2D((0,1),(0,0), color=self.param_colors[ind], linestyle='-'))
plt.legend(artists,[str(x) for x in range(1,self.num_params+1)],loc=legend_loc)
-
-
-

0 comments on commit 3e4b3df

Please sign in to comment.