Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86471454
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
Sun, Oct 6, 16:51
Size
4 KB
Mime Type
text/x-python
Expires
Tue, Oct 8, 16:51 (2 d)
Engine
blob
Format
Raw Data
Handle
21428896
Attached To
R6746 RationalROMPy
pivoted_rational_2d.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
matrix_random
import
matrixRandom
from
rrompy.reduction_methods.pivoted
import
(
RationalInterpolantPivoted
as
RIP
,
RationalInterpolantGreedyPivoted
as
RIGP
)
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
ManualSampler
as
MS
)
def
test_pivoted_uniform
():
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"
:
5
,
"polybasisMarginal"
:
"MONOMIAL"
,
"matchingWeight"
:
1.
,
"samplerMarginal"
:
QS
([
6.75
,
7.25
],
"UNIFORM"
)}
approx
=
RIP
([
0
],
solver
,
mu0
,
approx_state
=
True
,
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_pivoted_manual_grid
(
capsys
):
mu
=
[
5.05
,
7.1
]
mu0
=
[
5.
,
7.
]
solver
=
matrixRandom
()
uh
=
solver
.
solve
(
mu
)[
0
]
params
=
{
"POD"
:
False
,
"S"
:
5
,
"polybasis"
:
"MONOMIAL"
,
"samplerPivot"
:
MS
([
4.75
,
5.25
],
np
.
array
([
5.
])),
"SMarginal"
:
5
,
"polybasisMarginal"
:
"MONOMIAL"
,
"matchingWeight"
:
1.
,
"samplerMarginal"
:
MS
([
6.75
,
7.25
],
np
.
linspace
(
6.75
,
7.25
,
5
)),
"robustTol"
:
1e-6
,
"interpRcond"
:
1e-3
,
"cutOffTolerance"
:
1.
}
approx
=
RIP
([
0
],
solver
,
mu0
,
approx_state
=
True
,
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
),
.
4763489
,
rtol
=
1
)
out
,
err
=
capsys
.
readouterr
()
assert
(
"poorly conditioned"
not
in
out
)
assert
len
(
err
)
==
0
def
test_pivoted_greedy
():
mu
=
[
5.05
,
7.1
]
mu0
=
[
5.
,
7.
]
solver
=
matrixRandom
()
uh
=
solver
.
solve
(
mu
)[
0
]
params
=
{
"POD"
:
True
,
"nTestPoints"
:
100
,
"greedyTol"
:
1e-4
,
"collinearityTol"
:
1e8
,
"errorEstimatorKind"
:
"DISCREPANCY"
,
"S"
:
5
,
"polybasis"
:
"CHEBYSHEV"
,
"samplerPivot"
:
QS
([
4.75
,
5.25
],
"UNIFORM"
),
"trainSetGenerator"
:
QS
([
4.75
,
5.25
],
"CHEBYSHEV"
),
"SMarginal"
:
5
,
"polybasisMarginal"
:
"MONOMIAL"
,
"samplerMarginal"
:
QS
([
6.75
,
7.25
],
"UNIFORM"
),
"matchingWeight"
:
1.
,
"cutOffTolerance"
:
1.5
}
approx
=
RIGP
([
0
],
solver
,
mu0
,
approx_state
=
True
,
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
),
1.181958e-02
,
rtol
=
1
)
Event Timeline
Log In to Comment