Skip to content

Commit

Permalink
Add tracker for the log of the closest distance to f_opt discovered s…
Browse files Browse the repository at this point in the history
…o far
  • Loading branch information
timothyatkinson committed Nov 7, 2022
1 parent 67c7df8 commit 0b6d8d6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/evotorch/bbo/bbob_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(

# Initialize meta variables
self.initialize_meta_variables()
self._log_closest = 1e6

""" Extra BBOB-specific generator functions that ensure compliant dtype, device and generator
"""
Expand Down Expand Up @@ -164,12 +165,25 @@ def apply_function(self, z: torch.Tensor, x: torch.Tensor) -> torch.Tensor:
f_z = self._apply_function(z, x) + self._f_opt
return f_z

@property
def log_closest(self) -> torch.Tensor:
"""The logarithm of the best discovered solution so far"""
return self._log_closest

@log_closest.setter
def log_closest(self, new_log_closest):
self._log_closest = new_log_closest

def _evaluate_batch(self, batch: SolutionBatch) -> None:
# Get x from batch
x = batch.values.clone()
# Map x to z
z = self.map_x_to_z(x)
# Get f(x) from function application to z
f_x = self.apply_function(z, x)
# Compute log distance from f_opt
log_f_x = torch.log(f_x - self._f_opt)
if torch.amin(log_f_x) < self.log_closest:
self.log_closest = torch.amin(log_f_x)
# Assign fitnesses to batch
batch.set_evals(f_x)

0 comments on commit 0b6d8d6

Please sign in to comment.