Giter Site home page Giter Site logo

Comments (2)

ManuelAlvarezC avatar ManuelAlvarezC commented on May 29, 2024

Hi @echo66

I agree that being able to set the random_state to ensure reproducibility of your results is indeed a useful feature to have.

From the approaches you propose, I'll definetely pick the second one: having random_state as an constructor argument on the classes that use some kind of stochastic process.

I would also take your suggestion of using only one of random and numpy.random. Will you be open to do the changes yourself?

from copulas.

ManuelAlvarezC avatar ManuelAlvarezC commented on May 29, 2024

The required changes should be the following:

  1. Replace all the ocurrences of random with np.random
  2. Create a method random_state_call on copulas.__init__, like this:
def random_state_call(random_state, function, *args, **kwargs):
    if random_state is None:
        return function(*args, **kwargs)

    else:
        original_state = np.random.get_state()
        np.random.seed(random_state)
        
        result = function(*args, **kwargs)
        
        np.random.set_state(original_state)
        return result
  1. Change classes bivariate.base.Bivariate and multivariate.tree.Tree __new__ method in order for them to accept arbitrary positional and keyword arguments *args, **kwargs

  2. Add the argument random_state=None on __init__ for both classes, that sets its value to the attribute of the same name.

  3. Replace on their subclasses all calls to functions that depend on their np.random with calls to random_state_call, that is:

np.random.uniform(0, 1, n_samples)

random_state_call(self.random_state, np.random.uniform, 0, 1, n_samples)
  1. Repeat the steps 4 & 5 for univariate.base.Univariate, multivariate.base.Multivariate and multivariate.vine.VineCopulas.

  2. Create unittests for random_state_call and for the sample methods, in which, after a random state is set, the sample values are exactly the same.

  3. Check everything is according to our Contributing Guide.

If you plan on updating your PR with this changes, please let us know and we will assign this issue to you.

from copulas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.