Repository navigation
Fix SHADE never adapting F and CR, and sample DE-variant initial populations within bounds - #258
Merged
Merged
Conversation
Two bugs kept the success-history memory at its initial 0.5 forever, so SHADE ran as DE with fixed F and CR: - the improvements were taken after self.fit had been replaced by the trial fitness, so every successful delta was 0 and the weights were 0/0; - the successful F, CR and deltas were collected by blending NaN-filled arrays with arithmetic, and 0 * NaN is NaN, so every entry stayed NaN. Take the deltas before the fitness update and select the successful entries with torch.where.
…n the bounds They drew torch.randn * (ub - lb) + lb, a normal centred on lb with standard deviation ub - lb, so about two thirds of the initial coordinates fell outside [lb, ub]. Use torch.rand, as DE, ODE, JADE and the PSO variants do.
Collaborator
|
No problem, we welcome AI changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SHADE: the F/CR memory never changes
SHADE.stepkeeps its success-history memory at the initial 0.5 forever, so it runs as DE with fixed F = CR = 0.5. Two bugs, each enough on its own:deltas = self.fit - trial_fitnessis computed afterself.fithas been replaced by the trial fitness, so every successful trial has delta 0 and the weightsS_delta / nansum(S_delta)are 0/0 = NaN.is_success * update + (1 - is_success) * temp. Since0 * NaNis NaN, every entry stays NaN whether or not a trial succeeded.M_F is then NaN every generation and the
is_F_nanguard keeps the old memory.The fix takes the deltas before the fitness update and selects the successful entries with
torch.where(order does not matter for the weighted means, so the loop is no longer needed). The first generation still keeps the memory, because the parents' fitness isinfthere, as before.Sphere/Rastrigin,
dim=10, bounds ±10, pop 50, 300 generations, seeds 0–4:CoDE, SaDE, SHADE: most initial coordinates fall outside the bounds
They initialize with
torch.randn(pop_size, dim) * (ub - lb) + lb: a normal centred onlbwith standard deviationub - lb. With bounds ±10, only 34% of the initial coordinates lie in[lb, ub], and their mean is about −8.7. The second commit usestorch.rand, like DE, ODE, JADE and the PSO variants.Tests
Added to
unit_test/algorithms/test_de_variants.py:test_shade_adapts_memory: the memory changes and stays finite after 5 steps;test_initial_population_within_bounds: for SHADE, CoDE and SaDE.Both fail on
mainand pass here. Locally (Windows, torch 2.11) I can run the eager and (uncompiled) vmap paths of the existing tests for all five DE variants, which pass;torch.compileneeds MSVC, which I don't have, so the compiled paths are left to CI.This was prepared with AI assistance (Claude); I reviewed and tested the change.