Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60992789
random_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, 20:39
Size
2 KB
Mime Type
text/x-python
Expires
Sun, May 5, 20:39 (2 d)
Engine
blob
Format
Raw Data
Handle
17450379
Attached To
R6746 RationalROMPy
random_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
numbers
import
Number
import
numpy
as
np
from
rrompy.parameter.parameter_sampling.generic_random_sampler
import
(
GenericRandomSampler
)
from
rrompy.utilities.numerical.halton
import
haltonGenerate
from
rrompy.utilities.numerical.sobol
import
sobolGenerate
from
rrompy.utilities.base.types
import
List
__all__
=
[
'RandomSampler'
]
class
RandomSampler
(
GenericRandomSampler
):
"""Generator of (quasi-)random sample points."""
def
refine
(
self
,
active
:
List
[
int
]
=
None
)
->
List
[
int
]:
if
active
is
None
:
n
=
self
.
npoints
elif
isinstance
(
active
,
(
Number
,)):
n
=
active
else
:
n
=
len
(
active
)
n
=
int
(
n
*
self
.
refinementFactor
)
if
self
.
kind
==
"UNIFORM"
:
xmat
=
np
.
random
.
uniform
(
size
=
(
n
,
self
.
npar
))
elif
self
.
kind
==
"HALTON"
:
xmat
,
self
.
seedLoc
=
haltonGenerate
(
self
.
npar
,
n
,
self
.
seedLoc
,
return_seed
=
True
)
else
:
xmat
,
self
.
seedLoc
=
sobolGenerate
(
self
.
npar
,
n
,
self
.
seedLoc
,
return_seed
=
True
)
limsE
=
self
.
mapParameterList
(
self
.
lims
)
for
d
in
range
(
self
.
npar
):
a
,
b
=
limsE
(
d
)
xmat
[:,
d
]
=
a
+
(
b
-
a
)
*
xmat
[:,
d
]
pts
=
self
.
mapParameterList
(
xmat
,
"B"
)
idx
=
np
.
arange
(
n
,
dtype
=
int
)
+
len
(
self
.
points
)
for
pj
in
pts
:
self
.
points
.
append
(
pj
)
return
list
(
idx
)
Event Timeline
Log In to Comment