Skip to content

Commit

Permalink
Riesz s-Energy returns different outputs for same random seed #638
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Aug 25, 2024
1 parent ad98c14 commit fb4d542
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions pymoo/util/ref_dirs/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ def _do(self):
X = ReductionBasedReferenceDirectionFactory(self.n_dim,
self.n_points,
kmeans=True,
lexsort=False) \
lexsort=False,
seed=self.seed) \
.do()

elif self.sampling == "construction":
X = ConstructionBasedReferenceDirectionFactory(self.n_dim,
self.n_points) \
self.n_points,
seed=self.seed) \
.do()
else:
raise Exception("Unknown sampling method. Either reduction or construction.")
Expand Down
2 changes: 1 addition & 1 deletion pymoo/util/ref_dirs/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self,
self.n_points = n_points

def _do(self):
rnd = sample_on_unit_simplex(self.n_sample_points, self.n_dim, unit_simplex_mapping=self.sampling)
rnd = sample_on_unit_simplex(self.n_sample_points, self.n_dim, seed=self.seed, unit_simplex_mapping=self.sampling)

def h(n):
return get_partition_closest_to_points(n, self.n_dim)
Expand Down
5 changes: 3 additions & 2 deletions pymoo/util/reference_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ def do(self):
# Util
# =========================================================================================================

def get_rng(seed = None):
def get_rng(seed=None):
if seed is None or type(seed) == int:
rng = np.random.default_rng(seed)
return rng

def sample_on_unit_simplex(n_points, n_dim, unit_simplex_mapping="kraemer", seed = None):

def sample_on_unit_simplex(n_points, n_dim, unit_simplex_mapping="kraemer", seed=None):
if unit_simplex_mapping == "sum":
rnd = map_onto_unit_simplex(get_rng(seed).random((n_points, n_dim)), "sum")

Expand Down

0 comments on commit fb4d542

Please sign in to comment.