Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62470970
generic_sampler.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 13, 10:41
Size
3 KB
Mime Type
text/x-python
Expires
Wed, May 15, 10:41 (2 d)
Engine
blob
Format
Raw Data
Handle
17650709
Attached To
R6746 RationalROMPy
generic_sampler.py
View Options
# 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
,
scaling
:
List
[
callable
]
=
None
,
scalingInv
:
List
[
callable
]
=
None
):
self
.
lims
=
lims
self
.
scaling
=
scaling
self
.
scalingInv
=
scalingInv
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
)
if
len
(
lims
)
!=
2
:
raise
RROMPyException
(
"2 limits must be specified."
)
self
.
_lims
=
lims
@property
def
scaling
(
self
):
"""Value of scaling."""
return
self
.
_scaling
@scaling.setter
def
scaling
(
self
,
scaling
):
if
scaling
is
not
None
:
if
not
hasattr
(
scaling
,
"__len__"
):
scaling
=
[
scaling
]
RROMPyAssert
(
self
.
npar
,
len
(
scaling
),
"Number of scaling terms"
)
if
not
all
([
callable
(
s
)
for
s
in
scaling
]):
raise
RROMPyException
((
"Each value of scaling must be a "
"callable."
))
self
.
_scaling
=
scaling
@property
def
scalingInv
(
self
):
"""Value of scalingInv."""
return
self
.
_scalingInv
@scalingInv.setter
def
scalingInv
(
self
,
scalingInv
):
if
scalingInv
is
not
None
:
if
not
hasattr
(
scalingInv
,
"__len__"
):
scalingInv
=
[
scalingInv
]
RROMPyAssert
(
self
.
npar
,
len
(
scalingInv
),
"Number of scalingInv terms"
)
if
not
all
([
callable
(
sInv
)
for
sInv
in
scalingInv
]):
raise
RROMPyException
((
"Each value of scalingInv must be a "
"callable."
))
self
.
_scalingInv
=
scalingInv
@abstractmethod
def
generatePoints
(
self
,
n
:
List
[
int
])
->
paramList
:
"""Array of points."""
if
not
hasattr
(
n
,
"__len__"
):
n
=
[
n
]
RROMPyAssert
(
self
.
npar
,
len
(
n
),
"Point number"
)
pass
Event Timeline
Log In to Comment