Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64483306
greedy_pivoted_rational_2d.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, May 27, 05:12
Size
3 KB
Mime Type
text/x-python
Expires
Wed, May 29, 05:12 (2 d)
Engine
blob
Format
Raw Data
Handle
17911021
Attached To
R6746 RationalROMPy
greedy_pivoted_rational_2d.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
matrix_random
import
matrixRandom
from
rrompy.reduction_methods
import
(
RationalInterpolantPivotedGreedyPoleMatch
as
RIPG
,
RationalInterpolantGreedyPivotedGreedyPoleMatch
as
RIGPG
)
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
SparseGridSampler
as
SGS
)
def
test_pivoted_greedy
():
mu
=
[
5.05
,
7.1
]
mu0
=
[
5.
,
7.
]
solver
=
matrixRandom
()
uh
=
solver
.
solve
(
mu
)[
0
]
params
=
{
"POD"
:
True
,
"S"
:
5
,
"polybasis"
:
"CHEBYSHEV"
,
"samplerPivot"
:
QS
([
4.75
,
5.25
],
"CHEBYSHEV"
),
"SMarginal"
:
3
,
"greedyTolMarginal"
:
1e-2
,
"radialDirectionalWeightsMarginal"
:
2.
,
"polybasisMarginal"
:
"MONOMIAL_GAUSSIAN"
,
"paramsMarginal"
:{
"MMarginal"
:
1
,
"radialDirectionalWeightsMarginalAdapt"
:
[
1e9
,
1e12
]},
"errorEstimatorKindMarginal"
:
"LOOK_AHEAD_RECOVER"
,
"matchingWeight"
:
1.
,
"samplerMarginal"
:
SGS
([
6.75
,
7.25
])}
approx
=
RIPG
([
0
],
solver
,
mu0
,
approxParameters
=
params
,
verbosity
=
0
)
approx
.
setupApprox
()
uhP1
=
approx
.
getApprox
(
mu
)[
0
]
errP
=
approx
.
getErr
(
mu
)[
0
]
errNP
=
approx
.
normErr
(
mu
)[
0
]
myerrP
=
uhP1
-
uh
assert
np
.
allclose
(
np
.
abs
(
errP
-
myerrP
),
0.
,
rtol
=
1e-3
)
assert
np
.
isclose
(
solver
.
norm
(
errP
),
errNP
,
rtol
=
1e-3
)
resP
=
approx
.
getRes
(
mu
)[
0
]
resNP
=
approx
.
normRes
(
mu
)
assert
np
.
isclose
(
solver
.
norm
(
resP
),
resNP
,
rtol
=
1e-3
)
assert
np
.
allclose
(
np
.
abs
(
resP
-
(
solver
.
b
(
mu
)
-
solver
.
A
(
mu
)
.
dot
(
uhP1
))),
0.
,
rtol
=
1e-3
)
assert
np
.
isclose
(
errNP
/
solver
.
norm
(
uh
),
6.0631706e-04
,
rtol
=
1
)
def
test_greedy_pivoted_greedy
():
mu
=
[
5.05
,
7.1
]
mu0
=
[
5.
,
7.
]
solver
=
matrixRandom
()
uh
=
solver
.
solve
(
mu
)[
0
]
params
=
{
"POD"
:
True
,
"nTestPoints"
:
100
,
"greedyTol"
:
1e-3
,
"S"
:
2
,
"polybasis"
:
"CHEBYSHEV"
,
"samplerPivot"
:
QS
([
4.75
,
5.25
],
"CHEBYSHEV"
),
"samplerTrainSet"
:
QS
([
4.75
,
5.25
],
"CHEBYSHEV"
),
"SMarginal"
:
3
,
"maxIterMarginal"
:
10
,
"greedyTolMarginal"
:
1e-2
,
"radialDirectionalWeightsMarginal"
:
2.
,
"polybasisMarginal"
:
"MONOMIAL_GAUSSIAN"
,
"paramsMarginal"
:{
"MMarginal"
:
1
},
"errorEstimatorKindMarginal"
:
"LOOK_AHEAD_RECOVER"
,
"matchingWeight"
:
1.
,
"samplerMarginal"
:
SGS
([
6.75
,
7.25
])}
approx
=
RIGPG
([
0
],
solver
,
mu0
,
approxParameters
=
params
,
verbosity
=
0
)
approx
.
setupApprox
()
uhP1
=
approx
.
getApprox
(
mu
)[
0
]
errP
=
approx
.
getErr
(
mu
)[
0
]
errNP
=
approx
.
normErr
(
mu
)[
0
]
myerrP
=
uhP1
-
uh
assert
np
.
allclose
(
np
.
abs
(
errP
-
myerrP
),
0.
,
rtol
=
1e-3
)
assert
np
.
isclose
(
solver
.
norm
(
errP
),
errNP
,
rtol
=
1e-3
)
resP
=
approx
.
getRes
(
mu
)[
0
]
resNP
=
approx
.
normRes
(
mu
)
assert
np
.
isclose
(
solver
.
norm
(
resP
),
resNP
,
rtol
=
1e-3
)
assert
np
.
allclose
(
np
.
abs
(
resP
-
(
solver
.
b
(
mu
)
-
solver
.
A
(
mu
)
.
dot
(
uhP1
))),
0.
,
rtol
=
1e-3
)
assert
np
.
isclose
(
errNP
/
solver
.
norm
(
uh
),
.
106066
,
rtol
=
1
)
Event Timeline
Log In to Comment