Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78067582
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
Sun, Aug 18, 05:33
Size
1 KB
Mime Type
text/x-python
Expires
Tue, Aug 20, 05:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19976774
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.utilities.parameter_sampling
import
(
ManualSampler
,
QuadratureSampler
,
RandomSampler
,
FFTSampler
)
def
test_manual
():
sampler
=
ManualSampler
(
lims
=
[
0
,
3
],
points
=
np
.
linspace
(
0
,
3
,
101
),
scaling
=
lambda
x
:
np
.
power
(
x
,
2.
),
scalingInv
=
lambda
x
:
np
.
power
(
x
,
.
5
))
assert
sampler
.
name
()
==
"ManualSampler"
x
,
w
=
sampler
.
generatePoints
(
10
)
assert
np
.
allclose
(
x
,
np
.
linspace
(
0
,
3
,
101
)[:
10
],
rtol
=
1e-5
)
assert
np
.
allclose
(
w
,
np
.
ones
(
10
)
*
.
9
,
rtol
=
1e-5
)
def
test_quadrature
():
sampler
=
QuadratureSampler
(
lims
=
[
0
,
3
],
kind
=
"CHEBYSHEV"
)
x
,
w
=
sampler
.
generatePoints
(
9
)
assert
np
.
isclose
(
x
[
2
],
1.5
,
rtol
=
1e-5
)
assert
np
.
allclose
(
w
,
np
.
ones
(
9
)
/
3.
,
rtol
=
1e-5
)
def
test_random
():
sampler
=
RandomSampler
(
lims
=
[
0
,
3
],
kind
=
"SOBOL"
)
x
,
w
=
sampler
.
generatePoints
(
100
,
seed
=
13432
)
assert
np
.
isclose
(
x
[
47
],
0.55609130859375
,
rtol
=
1e-5
)
assert
np
.
allclose
(
w
,
np
.
ones
(
100
)
*
.
03
,
rtol
=
1e-5
)
def
test_fft
():
sampler
=
FFTSampler
(
lims
=
[
-
1
,
1
])
x
,
w
=
sampler
.
generatePoints
(
100
)
assert
np
.
allclose
(
np
.
power
(
x
,
100
),
1.
,
rtol
=
1e-5
)
assert
np
.
allclose
(
w
,
np
.
ones
(
100
)
*
.
01
,
rtol
=
1e-5
)
Event Timeline
Log In to Comment