当前位置: 首页>>代码示例>>Python>>正文


Python random.get_state方法代码示例

本文整理汇总了Python中numpy.random.get_state方法的典型用法代码示例。如果您正苦于以下问题:Python random.get_state方法的具体用法?Python random.get_state怎么用?Python random.get_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.random的用法示例。


在下文中一共展示了random.get_state方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _real_init

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values):
        self.randomstate = npr.get_state()
        # Input dimensionality.
        self.D = dims

        # Initial length scales.
        self.ls = np.ones(self.D)

        # Initial amplitude.
        self.amp2 = np.std(values)+1e-4

        # Initial observation noise.
        self.noise = 1e-3

        # Initial mean.
        self.mean = np.mean(values)

        # Save hyperparameter samples
        self.hyper_samples.append((self.mean, self.noise, self.amp2,
                                   self.ls)) 
开发者ID:NVIDIA,项目名称:Milano,代码行数:22,代码来源:gpeiopt_chooser.py

示例2: _real_init

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values, durations):
        self.randomstate = npr.get_state()

        # Identify constraint violations
        # Note that we'll treat NaNs and Infs as these values as well
        # as an optional user defined value
        goodvals = np.nonzero(np.logical_and(values != self.bad_value,
                                             np.isfinite(values)))[0]

        # Input dimensionality.
        self.D = dims

        # Initial length scales.
        self.ls = np.ones(self.D)
        self.constraint_ls = np.ones(self.D)

        # Initial amplitude.
        self.amp2 = np.std(values[goodvals])+1e-4
        self.constraint_amp2 = 1.0

        # Initial observation noise.
        self.noise = 1e-3
        self.constraint_noise = 1e-3
        self.constraint_gain = 1

        # Initial mean.
        self.mean = np.mean(values[goodvals])
        self.constraint_mean = 0.5 
开发者ID:NVIDIA,项目名称:Milano,代码行数:30,代码来源:gpei_constrained_chooser.py

示例3: save

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def save(self, path):
        del self.params_gen
        self.random_state = random.get_state()
        super(RandomProposer, self).save(path) 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:6,代码来源:RandomProposer.py

示例4: _real_init

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values):
        self.locker.lock_wait(self.state_pkl)

        self.randomstate = npr.get_state()
        if os.path.exists(self.state_pkl):
            fh    = open(self.state_pkl, 'r')
            state = pickle.load(fh)
            fh.close()

            self.D             = state['dims']
            self.ls            = state['ls']
            self.amp2          = state['amp2']
            self.noise         = state['noise']
            self.mean          = state['mean']
            self.hyper_samples = state['hyper_samples']
            self.needs_burnin  = False
        else:

            # Input dimensionality.
            self.D = dims

            # Initial length scales.
            self.ls = np.ones(self.D)

            # Initial amplitude.
            self.amp2 = np.std(values)+1e-4

            # Initial observation noise.
            self.noise = 1e-3

            # Initial mean.
            self.mean = np.mean(values)

            # Save hyperparameter samples
            self.hyper_samples.append((self.mean, self.noise, self.amp2,
                                       self.ls))

        self.locker.unlock(self.state_pkl) 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:40,代码来源:GPEIOptChooser.py

示例5: save_random_state

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def save_random_state():
        state = get_state()
        try:
            yield
        finally:
            set_state(state) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:8,代码来源:test_algebraic_connectivity.py

示例6: __enter__

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def __enter__(self):
        from numpy import random

        self.startstate = random.get_state()
        random.seed(self.seed) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:misc.py

示例7: local_seed

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def local_seed(seed):
    state = random.get_state()

    try:
        random.seed(seed)
        yield
    finally:
        random.set_state(state) 
开发者ID:siddhantgoel,项目名称:streaming-form-data,代码行数:10,代码来源:test_parser.py

示例8: _real_init

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values, durations):

        self.locker.lock_wait(self.state_pkl)

        self.randomstate = npr.get_state()
        if os.path.exists(self.state_pkl):
            fh    = open(self.state_pkl, 'rb')
            state = pickle.load(fh)
            fh.close()

            self.D                = state['dims']
            self.ls               = state['ls']
            self.amp2             = state['amp2']
            self.noise            = state['noise']
            self.mean             = state['mean']
            self.constraint_ls    = state['constraint_ls']
            self.constraint_amp2  = state['constraint_amp2']
            self.constraint_noise = state['constraint_noise']
            self.constraint_mean  = state['constraint_mean']
            self.constraint_gain  = state['constraint_gain']
            self.needs_burnin     = False
        else:

            # Identify constraint violations
            # Note that we'll treat NaNs and Infs as these values as well
            # as an optional user defined value
            goodvals = np.nonzero(np.logical_and(values != self.bad_value,
                                                 np.isfinite(values)))[0]

            # Input dimensionality.
            self.D = dims

            # Initial length scales.
            self.ls = np.ones(self.D)
            self.constraint_ls = np.ones(self.D)

            # Initial amplitude.
            self.amp2 = np.std(values[goodvals])+1e-4
            self.constraint_amp2 = 1.0

            # Initial observation noise.
            self.noise = 1e-3
            self.constraint_noise = 1e-3
            self.constraint_gain = 1

            # Initial mean.
            self.mean = np.mean(values[goodvals])
            self.constraint_mean = 0.5

        self.locker.unlock(self.state_pkl) 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:52,代码来源:GPConstrainedEIChooser.py

示例9: preserve_random_state

# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def preserve_random_state(func):
    """ Decorator to preserve the numpy.random state during a function.

    Parameters
    ----------
    func : function
        function around which to preserve the random state.

    Returns
    -------
    wrapper : function
        Function which wraps the input function by saving the state before
        calling the function and restoring the function afterward.

    Examples
    --------
    Decorate functions like this::

        @preserve_random_state
        def do_random_stuff(x, y):
            return x + y * numpy.random.random()

    Notes
    -----
    If numpy.random is not importable, the state is not saved or restored.
    """
    try:
        from numpy.random import get_state, seed, set_state

        @contextmanager
        def save_random_state():
            state = get_state()
            try:
                yield
            finally:
                set_state(state)

        def wrapper(*args, **kwargs):
            with save_random_state():
                seed(1234567890)
                return func(*args, **kwargs)
        wrapper.__name__ = func.__name__
        return wrapper
    except ImportError:
        return func 
开发者ID:holzschu,项目名称:Carnets,代码行数:47,代码来源:decorators.py


注:本文中的numpy.random.get_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。