Page MenuHomec4science

generic_sampler.py
No OneTemporary

File Metadata

Created
Tue, Oct 15, 04:41

generic_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 abc import abstractmethod
import numpy as np
from rrompy.utilities.types import Np1D, Tuple, GenExpr
__all__ = ['GenericSampler']
class GenericSampler:
"""ABSTRACT. Generic generator of sample points."""
def __init__(self, lims:Tuple[Np1D, Np1D]):
self.lims = lims
def name(self) -> str:
return self.__class__.__name__
def __str__(self) -> str:
return "{}[{}{}]".format(self.name(),
np.array2string(self.lims[0], separator = '_'),
np.array2string(self.lims[1], separator = '_'))
def __eq__(self, other) -> bool:
return self.__dict__ == other.__dict__
@property
def lims(self):
"""Value of lims."""
return self._lims
@lims.setter
def lims(self, lims):
if len(lims) != 2:
raise Exception("2 limits must be specified.")
try:
lims = lims.tolist()
except:
lims = list(lims)
for j in range(2):
try:
len(lims[j])
except:
lims[j] = np.array([lims[j]])
if len(lims[0]) != len(lims[1]):
raise Exception("The limits must have the same length.")
self._lims = lims
@abstractmethod
def generatePoints(self, n:GenExpr) -> Tuple[Np1D, Np1D]:
"""Array of points and array of weights."""
pass

Event Timeline