Page MenuHomec4science

greedy_pivoted_rational_2d.py
No OneTemporary

File Metadata

Created
Mon, Jun 10, 06:58

greedy_pivoted_rational_2d.py

# 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.greedy import (
RationalInterpolantPivotedGreedy as RIPG,
RationalInterpolantGreedyPivotedGreedy as RIGPG)
from rrompy.parameter.parameter_sampling import QuadratureSampler as QS
from rrompy.parameter import localSparseGrid as LSG
def test_greedy_pivoted():
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"),
"MMarginal": 1, "SMarginal": 3, "greedyTolMarginal": 1e-2,
"radialDirectionalWeightsMarginal": 2.,
"polybasisMarginal": "MONOMIAL_GAUSSIAN",
"matchingWeight": 1., "samplerMarginalGrid":LSG([6.75, 7.25])}
approx = RIPG([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_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"),
"trainSetGenerator": QS([4.75, 5.25], "CHEBYSHEV"),
"MMarginal": 1, "SMarginal": 3, "greedyTolMarginal": 1e-2,
"radialDirectionalWeightsMarginal": 2.,
"polybasisMarginal": "MONOMIAL_GAUSSIAN",
"matchingWeight": 1., "samplerMarginalGrid":LSG([6.75, 7.25])}
approx = RIGPG([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)

Event Timeline