Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F14875973
parameter_sampling.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
Thu, Sep 24, 14:06
Size
2 KB
Mime Type
text/xpython
Expires
Sat, Sep 26, 14:06 (2 d)
Engine
blob
Format
Raw Data
Handle
3954600
Attached To
R6746 RationalROMPy
parameter_sampling.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
rrompy.parameter.parameter_sampling
import
(
ManualSampler
,
QuadratureSampler
,
RandomSampler
,
FFTSampler
)
from
rrompy.parameter
import
checkParameter
def
test_manual
():
sampler
=
ManualSampler
(
lims
=
[
0.
,
3.
],
points
=
np
.
linspace
(
0
,
3
,
101
),
scalingExp
=
2.
)
assert
sampler
.
name
()
==
"ManualSampler"
x
=
sampler
.
generatePoints
(
10
)
assert
np
.
allclose
(
x
(
0
),
np
.
linspace
(
0
,
3
,
101
)[:
10
],
rtol
=
1e5
)
def
test_quadrature
():
sampler
=
QuadratureSampler
(
lims
=
[
0.
,
3.
],
kind
=
"CHEBYSHEV"
)
x
=
sampler
.
generatePoints
(
9
,
reorder
=
False
)
assert
np
.
isclose
(
x
(
0
)[
4
],
1.5
,
rtol
=
1e5
)
def
test_random
():
sampler
=
RandomSampler
(
lims
=
[
0.
,
3.
],
kind
=
"SOBOL"
,
seed
=
13432
)
x
=
sampler
.
generatePoints
(
100
)
assert
np
.
isclose
(
x
(
0
)[
47
],
0.55609130859375
,
rtol
=
1e5
)
def
test_fft
():
sampler
=
FFTSampler
(
lims
=
[

1.
,
1.
])
x
=
sampler
.
generatePoints
(
100
)
assert
np
.
allclose
(
np
.
power
(
x
(
0
),
100
),
1.
,
rtol
=
1e5
)
def
test_2D
():
sampler
=
QuadratureSampler
(
lims
=
[(
0.
,
0.
),
(
3.
,
1.
)],
kind
=
"GAUSSLEGENDRE"
)
x
=
sampler
.
generatePoints
(
81
)
assert
sum
(
np
.
isclose
(
x
(
0
),
1.5
))
==
9
assert
sum
(
np
.
isclose
(
x
(
1
),
.
5
))
==
9
def
test_4D
():
sampler
=
RandomSampler
(
lims
=
[(
0.
,)
*
4
,
(
1.
,)
*
4
],
kind
=
"UNIFORM"
,
seed
=
1234
)
x
=
sampler
.
generatePoints
(
10
)
assert
x
.
shape
[
1
]
==
4
assert
checkParameter
([
x
[
0
]])
==
checkParameter
([(
0.191519450378892
,
0.622108771039832
,
0.437727739007115
,
0.785358583713769
)])
Event Timeline
Log In to Comment