Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RNG seed handling in ProbInput class. #443

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading