Skip to content

Commit

Permalink
Fix RNG seed handling in ProbInput class.
Browse files Browse the repository at this point in the history
Assigning an integer value to `rng_seed`
property of `ProbInput` class will correctly reset
the RNG with the assigned seed value.

This commit should resolve Issue #424.
  • Loading branch information
damar-wicaksono committed Dec 9, 2024
1 parent aaa50d6 commit 876fd7a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Fixed

- Assigning an integer value to `rng_seed` property of `ProbInput` now
correctly reset the RNG with the assigned seed number.
- The fifth input variable of the Friedman is now active instead of the sixth.
Only the first five input variables of the Friedman functions are active.
- The argument `input_dimension` to filter the output of `list_functions()`
Expand Down
2 changes: 1 addition & 1 deletion src/uqtestfuns/core/prob_input/probabilistic_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def rng_seed(self) -> Optional[int]:
@rng_seed.setter
def rng_seed(self, value: Optional[int]):
"""Set/reset the seed for RNG."""
self.reset_rng(self._rng_seed)
self.reset_rng(value)

def transform_sample(self, xx: np.ndarray, other: ProbInput):
"""Transform a sample from the distribution to another."""
Expand Down
4 changes: 3 additions & 1 deletion tests/core/prob_input/test_prob_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_set_rng_seed(input_dimension):
marginals = create_random_marginals(input_dimension)

# Create two instances with an identical seed number
my_input = ProbInput(marginals, rng_seed=42)
my_input = ProbInput(marginals)

# Generate sample points
xx_1 = my_input.get_sample(1000)
Expand All @@ -225,6 +225,8 @@ def test_set_rng_seed(input_dimension):

# Reset the RNG and generate new sample points
my_input.rng_seed = 42
xx_1 = my_input.get_sample(1000)
my_input.rng_seed = 42
xx_2 = my_input.get_sample(1000)

# Assertion: Both samples should now be equal
Expand Down

0 comments on commit 876fd7a

Please sign in to comment.