diff --git a/mloop/learners.py b/mloop/learners.py index 01c8ea1..b759889 100644 --- a/mloop/learners.py +++ b/mloop/learners.py @@ -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}) diff --git a/mloop/visualizations.py b/mloop/visualizations.py index be8c5f3..494a458 100644 --- a/mloop/visualizations.py +++ b/mloop/visualizations.py @@ -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) - - - \ No newline at end of file