def sample_randomly(self, count=None, random_state=None, seed=None): """Iterator sampling random |Parameters| from the space.""" assert not random_state or seed is None c = 0 ranges = self.ranges random_state = random_state or new_random_state(seed) while count is None or c < count: yield Parameter(((k, random_state.uniform(ranges[k][0], ranges[k][1], shp)) for k, shp in self.parameter_type.iteritems())) c += 1
def sample_randomly(self, count=None, random_state=None, seed=None): """Iterator sampling random |Parameters| from the space.""" assert not random_state or seed is None c = 0 ranges = self.ranges random_state = random_state or new_random_state(seed) while count is None or c < count: yield Parameter( ((k, random_state.uniform(ranges[k][0], ranges[k][1], shp)) for k, shp in self.parameter_type.iteritems())) c += 1
def sample_randomly(self, count=None, random_state=None, seed=None): """Randomly sample |Parameters| from the space. .. warning:: When neither `random_state` nor `seed` are specified, repeated calls to this method will return the same sequence of parameters! Parameters ---------- count `None` or number of random parameters (see below). random_state :class:`~numpy.random.RandomState` to use for sampling. If `None`, a new random state is generated using `seed` as random seed. seed Random seed to use. If `None`, the :func:`default <pymor.tools.random.new_random_state>` random seed is used. Returns ------- If `count` is `None`, an inexhaustible iterator returning random |Parameters|. Otherwise a list of `count` random |Parameters|. """ assert not random_state or seed is None ranges = self.ranges random_state = random_state or new_random_state(seed) get_param = lambda: Parameter( ((k, random_state.uniform(ranges[k][0], ranges[k][1], shp)) for k, shp in sorted(self.parameter_type.items()))) # sorted is needed to ensure that the sampling of parameter components happens in an # deterministic order if count is None: def param_generator(): while True: yield get_param() return param_generator() else: return [get_param() for _ in range(count)]
def sample_randomly(self, count=None, random_state=None, seed=None): """Randomly sample |Parameters| from the space. .. warning:: When neither `random_state` nor `seed` are specified, repeated calls to this method will return the same sequence of parameters! Parameters ---------- count `None` or number of random parameters (see below). random_state :class:`~numpy.random.RandomState` to use for sampling. If `None`, a new random state is generated using `seed` as random seed. seed Random seed to use. If `None`, the :func:`default <pymor.tools.random.new_random_state>` random seed is used. Returns ------- If `count` is `None`, an inexhaustible iterator returning random |Parameters|. Otherwise a list of `count` random |Parameters|. """ assert not random_state or seed is None ranges = self.ranges random_state = random_state or new_random_state(seed) get_param = lambda: Parameter(((k, random_state.uniform(ranges[k][0], ranges[k][1], shp)) for k, shp in sorted(self.parameter_type.items()))) # sorted is needed to ensure that the sampling of parameter components happens in an # deterministic order if count is None: def param_generator(): while True: yield get_param() return param_generator() else: return [get_param() for _ in range(count)]