Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91497848
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, Nov 11, 16:43
Size
2 KB
Mime Type
text/x-python
Expires
Wed, Nov 13, 16:43 (2 d)
Engine
blob
Format
Raw Data
Handle
22272460
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/>.
#
import
numpy
as
np
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
]
def
normalFoci
(
self
,
d
:
int
=
0
):
return
[
-
1.
,
1.
]
def
groundPotential
(
self
,
d
:
int
=
0
):
fp
=
self
.
normalFoci
(
d
)[
1
]
fpa
=
np
.
abs
(
fp
)
if
np
.
isclose
(
fpa
,
0.
)
or
np
.
isclose
(
fpa
,
1.
):
return
1.
return
(
1.
+
np
.
abs
(
1.
-
fp
**
2.
)
**
.
5
)
/
fpa
@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
=
np
.
array
(
scalingExp
)
@abstractmethod
def
generatePoints
(
self
,
n
:
int
,
reorder
:
bool
=
True
)
->
paramList
:
"""Array of points."""
pass
Event Timeline
Log In to Comment