Skip to content

Conversation

sdrave
Copy link
Member

@sdrave sdrave commented Mar 8, 2019

As discussed in #544, this adds a random method to VectorArrayInterface. It has a default implementation for all backends that implement from_numpy. The exact signature is

def random(self, count=1, distribution='uniform', random_state=None, seed=None,
           reserve=0, **kwargs):

where kwargs are additional parameters depending on distribution. The names of these parameters are chosen to agree with the parameters of the respective NumPy methods.

random_state and seed behave as for CubicParameterSpace.sample_randomly: either a (mutable) NumPy RandomState can be provided which is then used to sample random numbers, or a seed from which a new RandomState is initialized. If neither are provided a new random state is created using pymor.tools.new_random_state with a default seed.

An important consequence: repeated calls to the random method will always create the same random numbers when neither random_state nor seed are provided. This is probably unexpected behavior and I think it should be changed s.t. we have a global default RandomState which is initialized once with a fixed seed and which is always used unless the user provides a seed or RandomState. 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 NumPy RandomState should be used to create a new seed for the random generator of the backend. This way the interface of random stays generic.

@sdrave sdrave added pr:new-feature Introduces a new feature interfaces labels Mar 8, 2019
@sdrave sdrave added this to the 2019.2 milestone Mar 8, 2019
@sdrave sdrave requested review from renefritze and pmli March 8, 2019 10:37
@sdrave sdrave changed the title Add 'random' method to VectorArrayInterface Add 'random' method to VectorArrayInterface Mar 8, 2019
@pmli
Copy link
Member

pmli commented Mar 8, 2019

@sdrave Looks good to me. Did you plan for this PR to also replace the from_numpy(np.random.randn(...)) stuff with the new method (in reductors/h2.py, reductors/sor_irka.py and algorithms/lradi.py)?

@sdrave
Copy link
Member Author

sdrave commented Mar 8, 2019

@pmli, I think we should better do this in another PR after the RandomState issue has been resolved.

@sdrave sdrave merged commit 9a882f6 into master Mar 8, 2019
@sdrave sdrave deleted the va_rand branch March 8, 2019 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:new-feature Introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants