Add 'random' method to VectorArrayInterface #618
Merged
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.
As discussed in #544, this adds a
random
method toVectorArrayInterface
. It has a default implementation for all backends that implementfrom_numpy
. The exact signature iswhere
kwargs
are additional parameters depending ondistribution
. The names of these parameters are chosen to agree with the parameters of the respective NumPy methods.random_state
andseed
behave as forCubicParameterSpace.sample_randomly
: either a (mutable) NumPy RandomState can be provided which is then used to sample random numbers, or aseed
from which a newRandomState
is initialized. If neither are provided a new random state is created usingpymor.tools.new_random_state
with adefault
seed.An important consequence: repeated calls to the
random
method will always create the same random numbers when neitherrandom_state
norseed
are provided. This is probably unexpected behavior and I think it should be changed s.t. we have a global defaultRandomState
which is initialized once with a fixed seed and which is always used unless the user provides a seed orRandomState
. This should be handled in a separate PR, however.I decided to always stick with NumPy
RandomStates
. In case a backend uses its own random generator, the NumPyRandomState
should be used to create a new seed for the random generator of the backend. This way the interface ofrandom
stays generic.