Repository navigation
Add qConstrainedLogEI - #6744
Conversation
| ) | ||
|
|
||
|
|
||
| class qConstrainedLogEI(qLogEI): |
There was a problem hiding this comment.
Is it possible to encapsulate qLogEI instead of inheriting it?
Although inheritance works fine in Python, nested inheritance usually obfuscates codes, so I'd prefer avoid it.
There was a problem hiding this comment.
Maybe we can do so by using composition as is done in other acquisition functions for constrained optimization (i.e., ConstrainedLogEI and ConstrainedLogEHVI). This would also reduce inconsistency in the implementation strategy.
There was a problem hiding this comment.
Thank you for the review! I agree that the nested inheritance was hard to follow. I've updated the implementation to encapsulate it instead.
|
@sawa3030 Cc: @kAIto47802 |
| @@ -182,40 +169,28 @@ def __init__( | |||
| n_samples=n_qmc_samples, | |||
| seed=qmc_seed, | |||
| ) | |||
There was a problem hiding this comment.
It seems we don't need these instance variables, though we need to define the zero tensor for threshold=-inf.
| y_post = self._conditional_gpr.sample(x) | ||
| return y_post.clamp_(min=torch.tensor(_EPS, dtype=torch.float64)).log() |
There was a problem hiding this comment.
[critical] Somehow q-logEI was not taking the improvement.
| y_post = self._conditional_gpr.sample(x) | |
| return y_post.clamp_(min=torch.tensor(_EPS, dtype=torch.float64)).log() | |
| return (self._conditional_gpr.sample(x) - self._threshold).clamp_min_(_EPS).log() |
|
@sawa3030 @kAIto47802 I don't mind who publishes this PR, but if @sawa3030 doesn't mind, I will publish it (the commit is already co-authored) and you two review it. |
|
Thank you very much for reporting the bug and for submitting a PR to fix it! I’ll take a look at #6760 before moving forward with this PR. |
I reran the benchmark after fixing the issue, and the overall trend does not seem to have changed significantly. |
| ) | ||
|
|
||
|
|
||
| class qConstrainedLogEI(BaseAcquisitionFunc): |
There was a problem hiding this comment.
What about defining qLogPI and encapsulate it?
We need it for qConstrainedLogEHVI anyway, right?
|
Thank you for the suggestion! I have added |
| super().__init__(gpr.length_scales, search_space) | ||
|
|
||
| def eval_acqf(self, x: torch.Tensor) -> torch.Tensor: | ||
| def _log_improvement(self, x: torch.Tensor) -> torch.Tensor: |
There was a problem hiding this comment.
Now that eval_acqf is simple enough to merge this method.
There was a problem hiding this comment.
Ok, I’ve updated qConstrainedLogEI so that the unaggregated log improvement is computed internally. Please let me know if I misunderstood your intention.
| ) | ||
| super().__init__(gpr.length_scales, search_space) | ||
|
|
||
| def _log_prob(self, x: torch.Tensor) -> torch.Tensor: |
There was a problem hiding this comment.
Ditto.
We don't need to separate this method from eval_acqf anymore.
| search_space=search_space, | ||
| threshold=threshold, | ||
| n_qmc_samples=n_qmc_samples, | ||
| qmc_seed=qmc_seed + i + 1, |
There was a problem hiding this comment.
We need to make sure that this value fits in 64bit.
Although the probability is quite low, it is possible to encounter overflow.
Ok, seems the sampler side is doing this job.
But probably, we should use a function with a comment line so that any unintended modifications won't happen.
There was a problem hiding this comment.
Thank you for pointing this out" I had overlooked the possibility of overflow. I’ve updated the code to pass qmc_seeds from the sampler side, ensuring that each generated value fits within a 64-bit integer.
There was a problem hiding this comment.
The old version already handles the overflow issue implicitly by limiting the seed range to [0, 1 << 30].
So your approach (the old version) works fine.
But since this handling is very implicit, we should define the max seed value as a global constant variable with a comment line.
Essentially, we don't know why we use 1 << 30 not (1 << 31) - 1.
Since the number of constraints cannot be very large by design ~ 100, the current max seed value is totally fine.
| y_post = self._acqf._cond_gpr.sample_joint_posterior(x) | ||
| log_feasible_improvement = ( | ||
| (y_post - self._acqf._threshold).clamp_min_(_EPS).log() | ||
| if not np.isneginf(self._acqf._threshold) | ||
| else torch.zeros_like(y_post, dtype=torch.float64) | ||
| ) | ||
|
|
||
| for acqf in self._constraints_acqf_list: | ||
| log_prob = acqf._cond_gpr.sample_joint_posterior(x) | ||
| log_feasible_improvement += torch.nn.functional.logsigmoid( | ||
| (log_prob - acqf._threshold) / acqf._tau | ||
| ) |
There was a problem hiding this comment.
Ok, now I got why you needed to define a separated method for per-sample utility values.
Btw, the per-sample value is termed acquisition utility.
- cf. https://arxiv.org/pdf/1910.06403
But anyways, I'd rather lean toward merging this PR first. (at least, it is not recommended to access private attributes like acqf._cond_gpr and acqf._threshold)
We can work on refactoring in the next PR.
There was a problem hiding this comment.
Thank you for the helpful reference. I will handle the refactoring in the next PR!
| return standard_logei((mean - f0) / (sigma := var.sqrt_())) + sigma.log() | ||
|
|
||
|
|
||
| def _aggregate_log_acqf_over_q_batch(log_acqf: torch.Tensor) -> torch.Tensor: |
There was a problem hiding this comment.
I think this name is more appropriate.
| def _aggregate_log_acqf_over_q_batch(log_acqf: torch.Tensor) -> torch.Tensor: | |
| def _compute_mean_max_utility(log_util_vals: torch.Tensor) -> torch.Tensor: |
There was a problem hiding this comment.
Thank you for the suggestion. I have updated the name accordingly!
There was a problem hiding this comment.
LGTM with the condition of a follow-up PR mentioned above.
Please notice this: @kAIto47802
|
@nabenabe0928 My apologies for overlooking the QMC seed refactoring, and thank you very much for taking the time to suggest a refactoring plan. I have created draft PR #6779 based on your suggestion. Once this PR #6744 has been merged, I will mark #6779 as ready for review. |
Co-authored-by: Kaito Baba <[email protected]>
kAIto47802
left a comment
There was a problem hiding this comment.
Thank you for the update! LGTM


Motivation
PR #6640 introduced a Monte Carlo-based acquisition function for unconstrained single-objective optimization in GPSampler. This PR extends the approach to constrained single-objective optimization.
Description of the changes