Page MenuHomec4science

random_sampler.py
No OneTemporary

File Metadata

Created
Fri, May 3, 20:39

random_sampler.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
from numbers import Number
import numpy as np
from rrompy.parameter.parameter_sampling.generic_random_sampler import (
GenericRandomSampler)
from rrompy.utilities.numerical.halton import haltonGenerate
from rrompy.utilities.numerical.sobol import sobolGenerate
from rrompy.utilities.base.types import List
__all__ = ['RandomSampler']
class RandomSampler(GenericRandomSampler):
"""Generator of (quasi-)random sample points."""
def refine(self, active : List[int] = None) -> List[int]:
if active is None:
n = self.npoints
elif isinstance(active, (Number,)):
n = active
else:
n = len(active)
n = int(n * self.refinementFactor)
if self.kind == "UNIFORM":
xmat = np.random.uniform(size = (n, self.npar))
elif self.kind == "HALTON":
xmat, self.seedLoc = haltonGenerate(self.npar, n, self.seedLoc,
return_seed = True)
else:
xmat, self.seedLoc = sobolGenerate(self.npar, n, self.seedLoc,
return_seed = True)
limsE = self.mapParameterList(self.lims)
for d in range(self.npar):
a, b = limsE(d)
xmat[:, d] = a + (b - a) * xmat[:, d]
pts = self.mapParameterList(xmat, "B")
idx = np.arange(n, dtype = int) + len(self.points)
for pj in pts: self.points.append(pj)
return list(idx)

Event Timeline