Page MenuHomec4science

generic_sampler.py
No OneTemporary

File Metadata

Created
Tue, May 7, 13:04

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
from rrompy.utilities.base.types import List, paramList
from rrompy.utilities.exception_manager import RROMPyException, RROMPyAssert
from rrompy.parameter import checkParameterList
__all__ = ['GenericSampler']
class GenericSampler:
"""ABSTRACT. Generic generator of sample points."""
def __init__(self, lims:paramList, scalingExp : List[float] = None):
self.lims = lims
self.scalingExp = scalingExp
def name(self) -> str:
return self.__class__.__name__
def __str__(self) -> str:
return "{}[{}_{}]".format(self.name(), self.lims[0], self.lims[1])
def __repr__(self) -> str:
return self.__str__() + " at " + hex(id(self))
def __eq__(self, other) -> bool:
return self.__dict__ == other.__dict__
@property
def npar(self):
"""Number of parameters."""
return self._lims.shape[1]
@property
def lims(self):
"""Value of lims."""
return self._lims
@lims.setter
def lims(self, lims):
lims = checkParameterList(lims)[0]
if len(lims) != 2:
raise RROMPyException("2 limits must be specified.")
self._lims = lims
@property
def scalingExp(self):
"""Value of scalingExp."""
return self._scalingExp
@scalingExp.setter
def scalingExp(self, scalingExp):
if scalingExp is None:
scalingExp = [1.] * self.npar
if not hasattr(scalingExp, "__len__"): scalingExp = [scalingExp]
RROMPyAssert(self.npar, len(scalingExp), "Number of scaling terms")
self._scalingExp = scalingExp
@abstractmethod
def generatePoints(self, n:int) -> paramList:
"""Array of points."""
pass

Event Timeline