From 859ac5bc8ffe854cb5b29c1eb89ce5d56db10e12 Mon Sep 17 00:00:00 2001 From: Niko Feith Date: Wed, 12 Jul 2023 17:56:20 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=80=9EAcquistionFunctions/PreferenceExpe?= =?UTF-8?q?ctedImprovement.py=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PreferenceExpectedImprovement.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AcquistionFunctions/PreferenceExpectedImprovement.py b/AcquistionFunctions/PreferenceExpectedImprovement.py index b69595c..829b06b 100644 --- a/AcquistionFunctions/PreferenceExpectedImprovement.py +++ b/AcquistionFunctions/PreferenceExpectedImprovement.py @@ -22,10 +22,19 @@ class PreferenceExpectedImprovement: pass def rejection_sampling(self): - samples = np.empty((self.nr_samples, self.nr_dims)) - i = 0 - while i < self.nr_samples: - pass + samples = np.empty((0, self.nr_dims)) + while samples.shape[0] < self.nr_samples: + # sample from the multi variate gaussian distribution + sample = self.rng.multivariate_normal( + self.proposal_model_mean, + self.proposal_model_covariance + ) + + # check if the sample is within the bounds + if np.all(sample >= self.lower_bound) and np.all(sample <= self.upper_bound): + samples = np.append(samples, [sample], axis=0) + + return samples def expected_improvement(self): From 3f9b12e7f2f547ed1b61fa7d9584b92d0d37c443 Mon Sep 17 00:00:00 2001 From: Niko Feith Date: Wed, 12 Jul 2023 18:40:21 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E2=80=9EAcquistionFunctions/PreferenceExpe?= =?UTF-8?q?ctedImprovement.py=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PreferenceExpectedImprovement.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/AcquistionFunctions/PreferenceExpectedImprovement.py b/AcquistionFunctions/PreferenceExpectedImprovement.py index 829b06b..d72424d 100644 --- a/AcquistionFunctions/PreferenceExpectedImprovement.py +++ b/AcquistionFunctions/PreferenceExpectedImprovement.py @@ -12,9 +12,11 @@ class PreferenceExpectedImprovement: self.upper_bound = upper_bound self.lower_bound = lower_bound + self.initial_variance = 5.0 + self.user_model = None self.proposal_model_mean = np.array((nr_dims, 1)) - self.proposal_model_covariance = np.diag(np.ones((nr_dims, )) * 5) + self.proposal_model_covariance = np.diag(np.ones((nr_dims, )) * self.initial_variance) self.rng = np.random.default_rng(seed=seed) @@ -40,11 +42,19 @@ class PreferenceExpectedImprovement: def expected_improvement(self): pass - def update_user_preference_model(self): - pass + def update_user_preference_model(self, preferred_input, preference_array): + # Update mean to reflect preferred input + self.user_model_mean = preferred_input - def update_proposal_model(self): - pass + initial_variance = np.ones((self.nr_dims, )) * self.initial_variance + reduced_variance = initial_variance / 10.0 + variances = np.where(preference_array, reduced_variance, initial_variance) + self.user_model_covariance = np.diag(variances) + + def update_proposal_model(self, alpha=0.5): + # Update proposal model to be a weighted average of the current proposal model and the user model + self.proposal_model_mean = alpha * self.proposal_model_mean + (1 - alpha) * self.user_model_mean + self.proposal_model_covariance = alpha * self.proposal_model_covariance + (1 - alpha) * self.user_model_covariance if __name__ == '__main__':