def _response_mechanism(self):
"""Response mechanism."""
pop = self.pop
X = pop.get("X")
# recreate the current population without being evaluated
pop = Population.new(X=X)
# sample self.pop_size individuals in decision space
samples_old = self.sampling_new_pop()
# select self.pop_size/2 individuals with better convergence and diversity
samples = samples_old[:int(len(samples_old)/2)]
# knowledge in objective space
means_stds, mean, std = self._in_decision_or_objective_space_1d(samples, "objective_space")
# Check if sufficient historical data is available for LSTM prediction
if len(means_stds) > self._n_timesteps:
# Update pool
self.data["means_stds"] = means_stds[self._n_timesteps:]
# Prepare time series data from historical means and standard deviations
time_series_data = prepare_data_means_std(self._n_timesteps, means_stds)
# Initialize predictor and generate prediction for next time step
next_prediction = self._lstm.convert_train_predict(time_series_data)
# Convert prediction tensor to numpy array for further processing
next_prediction = next_prediction.numpy()
# Split prediction into mean and standard deviation components
# First n_obj elements represent mean values, remaining elements represent standard deviations
mean_new, std_new = next_prediction[:self.problem.n_obj], next_prediction[self.problem.n_obj:]
std_new = np.abs(std_new)
else:
mean_new, std_new = self._select_means_stds(means_stds, mean, std)
# sample self.pop_size individuals in objective space
F = univariate_gaussian_sample(mean_new, std_new, self.pop_size, random_state=self.random_state)
# TODO
# inverse mapping
# X = FB
B = closed_form_solution(samples.get("X"), samples.get("F"))
# X = FB
X = np.dot(F, B)
# bounds
if self.problem.has_bounds():
xl, xu = self.problem.bounds()
X = clip_and_randomize(X, xl, xu, random_state=self.random_state)
# merge
pop = Population.merge(samples_old, Population.new(X=X))
return pop