Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122165501
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
Wed, Jul 16, 07:08
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Jul 18, 07:08 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27443211
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
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
Log In to Comment