Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60919877
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
Fri, May 3, 09:34
Size
3 KB
Mime Type
text/x-python
Expires
Sun, May 5, 09:34 (2 d)
Engine
blob
Format
Raw Data
Handle
17440092
Attached To
R6746 RationalROMPy
generic_sampler.py
View Options
# Copyright (C) 2018-2020 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/>.
#
import
numpy
as
np
from
abc
import
abstractmethod
from
rrompy.utilities.base.types
import
List
,
DictAny
,
paramList
from
rrompy.utilities.expression
import
expressionEvaluator
from
rrompy.utilities.exception_manager
import
RROMPyException
from
rrompy.parameter
import
checkParameterList
,
parameterMap
as
pMap
from
rrompy.parameter.parameter_list
import
emptyParameterList
__all__
=
[
'GenericSampler'
]
class
GenericSampler
:
"""ABSTRACT. Generic generator of sample points."""
def
__init__
(
self
,
lims
:
paramList
,
parameterMap
:
DictAny
=
1.
):
self
.
lims
=
lims
self
.
parameterMap
=
pMap
(
parameterMap
,
self
.
npar
)
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
:
if
(
not
hasattr
(
other
,
"__dict__"
)
or
self
.
__dict__
.
keys
()
!=
other
.
__dict__
.
keys
()):
return
False
for
key
in
self
.
__dict__
:
val
=
self
.
__dict__
[
key
]
if
isinstance
(
val
,
(
np
.
ndarray
,)):
if
not
np
.
allclose
(
val
,
other
.
__dict__
[
key
]):
return
False
else
:
if
val
!=
other
.
__dict__
[
key
]:
return
False
return
True
@property
def
npar
(
self
):
"""Number of parameters."""
return
self
.
_lims
.
shape
[
1
]
def
normalFoci
(
self
,
d
:
int
=
0
):
return
[
-
1.
,
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
def
mapParameterList
(
self
,
mu
:
paramList
,
direct
:
str
=
"F"
,
idx
:
List
[
int
]
=
None
)
->
paramList
:
if
idx
is
None
:
idx
=
np
.
arange
(
self
.
npar
)
muMapped
=
checkParameterList
(
mu
,
len
(
idx
))
for
j
,
d
in
enumerate
(
idx
):
muMapped
.
data
[:,
j
]
=
expressionEvaluator
(
self
.
parameterMap
[
direct
][
d
],
muMapped
(
j
))
.
flatten
()
return
muMapped
def
reset
(
self
):
self
.
points
=
emptyParameterList
()
@abstractmethod
def
generatePoints
(
self
,
n
:
int
,
reorder
:
bool
=
True
)
->
paramList
:
"""Array of points."""
pass
Event Timeline
Log In to Comment