Merge remote-tracking branch 'origin/master'

# Conflicts:
#	AcquistionFunctions/PreferenceExpectedImprovement.py
This commit is contained in:
Niko Feith 2023-07-13 10:48:18 +02:00
commit 47f48662f4

View File

@ -12,11 +12,9 @@ class PreferenceExpectedImprovement:
self.upper_bound = upper_bound self.upper_bound = upper_bound
self.lower_bound = lower_bound self.lower_bound = lower_bound
self.initial_variance = 5.0
self.user_model = None self.user_model = None
self.proposal_model_mean = np.array((nr_dims, 1)) self.proposal_model_mean = np.array((nr_dims, 1))
self.proposal_model_covariance = np.diag(np.ones((nr_dims, )) * self.initial_variance) self.proposal_model_covariance = np.diag(np.ones((nr_dims, )) * 5)
self.rng = np.random.default_rng(seed=seed) self.rng = np.random.default_rng(seed=seed)
@ -24,37 +22,20 @@ class PreferenceExpectedImprovement:
pass pass
def rejection_sampling(self): def rejection_sampling(self):
samples = np.empty((0, self.nr_dims)) samples = np.empty((self.nr_samples, self.nr_dims))
while samples.shape[0] < self.nr_samples: i = 0
# sample from the multi variate gaussian distribution while i < self.nr_samples:
sample = self.rng.multivariate_normal( pass
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): def expected_improvement(self):
pass pass
def update_user_preference_model(self, preferred_input, preference_array): def update_user_preference_model(self):
# Update mean to reflect preferred input pass
self.user_model_mean = preferred_input
initial_variance = np.ones((self.nr_dims, )) * self.initial_variance def update_proposal_model(self):
reduced_variance = initial_variance / 10.0 pass
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__': if __name__ == '__main__':