Praktikum zu Vorlesung Modellreduktion parametrisierter Systeme

Mario Ohlberger, Felix Schindler, Tim Keil

Blatt 08, 03.07.2019

  • Aktivieren Sie wie gewohnt ihre Arbeitsumgebung und starten Sie den Jupyter Notebook server, siehe zB Blatt 1, Aufgabe 0.

  • Importieren Sie numpy und pymor.basic und machen Sie matplotlib für das Notebook nutzbar.

In [1]:
%matplotlib notebook
import numpy as np
from pymor.basic import *
from matplotlib import pyplot as plt

Wir betrachten das Diffusionsproblem von Blatt 04, Aufgabe 1 mit dem Ausgabe Funktional

$$ s(v) := \frac{1}{|\Omega_\text{out}|} \int_{\Omega_\text{out}} v\; \text{d}x \quad\quad\text{mit } \Omega_\text{out} := (0, 1) \times (0.9, 1) $$

und das folgende Minimierungsproblem: finde das Minimum

$$ \mu* := \underset{\mu \in \mathcal{P}}{\text{argmin}} J(\mu) $$

wobei $J(\mu) := s(u_\mu)$, und $u_\mu$ für $\mu \in \mathcal{P}$ die Lösung des Diffusionsproblems sei; $J$ wird oft Paramter-zu-Ausgabe Abbilding oder input-output map genannt.

Aufgabe 1: der schwache greedy Algorithmus

  1. Erstellen Sie ein analytisches Problem unter Verwedung von problem_B4_A1_parametric und fügen Sie dem Problem das Ausgabefunktional mit der id output hinzu (siehe auch API Dokumentation von StationaryProblem).
In [2]:
from problems import problem_B4_A1_parametric

problem = problem_B4_A1_parametric()
problem = problem.with_(functionals={'output': ('l2', ExpressionFunction('(x[..., 1] >= 0.9) * 10.', 2, ())) })
00:00 |WARNING|BitmapFunction: Image R.png not in grayscale mode. Convertig to grayscale.
00:00 |WARNING|BitmapFunction: Image B.png not in grayscale mode. Convertig to grayscale.
  1. Diskretisieren Sie das Problem mit Hilfe des cg discretizers und werten Sie $J$ für den Paramter $\mu = ${'R': 1, 'B': 1} aus.

    • extrahieren Sie dazu das Ausgabefunktional s aus dem operators-dict der Diskretisierung
    • definieren Sie $J$
In [3]:
d, _ = discretize_stationary_cg(problem)
print(d.operators.keys())
00:00 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:00 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:00 DiffusionOperatorP1: Determine global dofs ...
00:00 DiffusionOperatorP1: Boundary treatment ...
00:00 DiffusionOperatorP1: Assemble system matrix ...
00:00 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:00 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:00 DiffusionOperatorP1: Determine global dofs ...
00:00 DiffusionOperatorP1: Boundary treatment ...
00:00 DiffusionOperatorP1: Assemble system matrix ...
00:00 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:00 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:00 DiffusionOperatorP1: Determine global dofs ...
00:00 DiffusionOperatorP1: Boundary treatment ...
00:00 DiffusionOperatorP1: Assemble system matrix ...
00:00 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:00 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:00 DiffusionOperatorP1: Determine global dofs ...
00:00 DiffusionOperatorP1: Boundary treatment ...
00:00 DiffusionOperatorP1: Assemble system matrix ...
00:00 L2ProductP1: Integrate the products of the shape functions on each element
00:00 L2ProductP1: Determine global dofs ...
00:00 L2ProductP1: Boundary treatment ...
00:00 L2ProductP1: Assemble system matrix ...
00:00 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:01 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:01 DiffusionOperatorP1: Determine global dofs ...
00:01 DiffusionOperatorP1: Boundary treatment ...
00:01 DiffusionOperatorP1: Assemble system matrix ...
00:01 L2ProductP1: Integrate the products of the shape functions on each element
00:01 L2ProductP1: Determine global dofs ...
00:01 L2ProductP1: Boundary treatment ...
00:01 L2ProductP1: Assemble system matrix ...
00:01 DiffusionOperatorP1: Calulate gradients of shape functions transformed by reference map ...
00:01 DiffusionOperatorP1: Calculate all local scalar products beween gradients ...
00:01 DiffusionOperatorP1: Determine global dofs ...
00:01 DiffusionOperatorP1: Boundary treatment ...
00:01 DiffusionOperatorP1: Assemble system matrix ...
dict_keys(['output_functional', 'operator', 'rhs'])
In [4]:
s = d.operators['output_functional']

def J(mu):
    U = d.solve(mu)
    return s.apply(U).data[0][0]

print(J([1, 1]))
00:01 StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1, R: 1} ...
0.003584674108277644
  1. Erstellen Sie einen CoerciveRBReductor mit entsprechenden product und coercivity_estimator
In [5]:
reductor = CoerciveRBReductor(
        d, product=d.h1_0_semi_product,
        coercivity_estimator=ExpressionParameterFunctional('min([1, R, B])', d.parameter_type))
  1. Erstellen Sie eine reduzierte Basis mit Hilfe eines (weak discrete) greedy Algorithmus.

    • Machen Sie sich mit dem greedy Algorithmus in pyMOR vertraut. Dieser Nutzt den Residuenbasierten offline/online zerlegbaren Fehlerschätzer (weak) des CoerciveRBReductor, um den Modellreduktionsfehler online-effizient für eine große Menge an Trainingsparametern (discrete) zu schätzen. Es werden also für jedes Element der reduzierten Basis nur eine hochdimensionale Lösung der PDE benötigt.

    • Verwenden Sie eine Trainingsmenge von 10000 gleichverteilten Paramtern.

    • Stellen Sie sicher, dass der maximale geschätzte Modellreduktionsfehler (über die Trainingsmenge) 1e-3 nicht überschreitet.

    • Stellen Sie sicher, dass die reduzierte Basis mit Hilfe eines Gram-Schmidt Verfahrens orthonormalisiert wird, setzen Sie hierzu extension_params={'method': 'gram_schmidt'}.

In [6]:
greedy_data = greedy(
    d, reductor, d.parameter_space.sample_uniformly(100),
    atol=1e-3,
    extension_params={'method': 'gram_schmidt'}
)
00:01 greedy: Started greedy search on 10000 samples
00:01 greedy: Reducing ...
00:01 |   CoerciveRBReductor: RB projection ...
00:01 |   CoerciveRBReductor: Assembling error estimator ...
00:01 |   |   ResidualReductor: Estimating residual range ...
00:01 |   |   |   estimate_image_hierarchical: Estimating image for basis vector -1 ...
00:02 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:02 |   |   ResidualReductor: Projecting residual operator ...
00:02 greedy: Estimating errors ...
00:04 greedy: Maximum error after 0 extensions: 5199.189979573521 (mu = {B: 0.0001, R: 0.0001})
00:04 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.0001} ...
00:04 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.0001} ...
00:04 greedy: Extending basis with solution snapshot ...
      
00:04 greedy: Reducing ...
00:04 |   CoerciveRBReductor: RB projection ...
00:05 |   CoerciveRBReductor: Assembling error estimator ...
00:05 |   |   ResidualReductor: Estimating residual range ...
00:05 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 0 ...
00:05 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:05 |   |   |   |   gram_schmidt: Removing vector 1 of norm 3.713266607296652e-18
00:05 |   |   |   |   gram_schmidt: Removing linear dependent vector 4
00:05 |   |   ResidualReductor: Projecting residual operator ...
00:05 greedy: Estimating errors ...
00:08 greedy: Maximum error after 1 extensions: 3588.8146149577324 (mu = {B: 0.0001, R: 1.0})
00:08 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 1.0} ...
00:08 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 1.0} ...
00:08 greedy: Extending basis with solution snapshot ...
      
00:08 greedy: Reducing ...
00:08 |   CoerciveRBReductor: RB projection ...
00:08 |   CoerciveRBReductor: Assembling error estimator ...
00:08 |   |   ResidualReductor: Estimating residual range ...
00:08 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 1 ...
00:08 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:08 |   |   |   |   gram_schmidt: Removing vector 3 of norm 6.4911410267974024e-18
00:08 |   |   |   |   gram_schmidt: Orthonormalizing vector 4 again
00:08 |   |   |   |   gram_schmidt: Orthonormalizing vector 6 again
00:08 |   |   ResidualReductor: Projecting residual operator ...
00:08 greedy: Estimating errors ...
00:11 greedy: Maximum error after 2 extensions: 2764.7755366045512 (mu = {B: 1.0, R: 0.0001})
00:11 greedy: Computing solution snapshot for mu = {B: 1.0, R: 0.0001} ...
00:11 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1.0, R: 0.0001} ...
00:12 greedy: Extending basis with solution snapshot ...
      
00:12 greedy: Reducing ...
00:12 |   CoerciveRBReductor: RB projection ...
00:12 |   CoerciveRBReductor: Assembling error estimator ...
00:12 |   |   ResidualReductor: Estimating residual range ...
00:12 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 2 ...
00:12 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:12 |   |   |   |   gram_schmidt: Removing vector 6 of norm 2.710973310666844e-17
00:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 8 again
00:12 |   |   ResidualReductor: Projecting residual operator ...
00:12 greedy: Estimating errors ...
00:15 greedy: Maximum error after 3 extensions: 202.732922083436 (mu = {B: 0.0001, R: 0.22229999999999997})
00:15 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.22229999999999997} ...
00:15 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.22229999999999997} ...
00:15 greedy: Extending basis with solution snapshot ...
00:15 |   gram_schmidt: Orthonormalizing vector 3 again
      
00:15 greedy: Reducing ...
00:15 |   CoerciveRBReductor: RB projection ...
00:15 |   CoerciveRBReductor: Assembling error estimator ...
00:15 |   |   ResidualReductor: Estimating residual range ...
00:15 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 3 ...
00:15 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:15 |   |   |   |   gram_schmidt: Removing vector 9 of norm 1.290777571816372e-16
00:15 |   |   |   |   gram_schmidt: Orthonormalizing vector 11 again
00:15 |   |   |   |   gram_schmidt: Orthonormalizing vector 12 again
00:15 |   |   ResidualReductor: Projecting residual operator ...
00:15 greedy: Estimating errors ...
00:19 greedy: Maximum error after 4 extensions: 198.2312470568827 (mu = {B: 0.2728, R: 0.0001})
00:19 greedy: Computing solution snapshot for mu = {B: 0.2728, R: 0.0001} ...
00:19 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.2728, R: 0.0001} ...
00:19 greedy: Extending basis with solution snapshot ...
00:19 |   gram_schmidt: Orthonormalizing vector 4 again
      
00:19 greedy: Reducing ...
00:19 |   CoerciveRBReductor: RB projection ...
00:19 |   CoerciveRBReductor: Assembling error estimator ...
00:19 |   |   ResidualReductor: Estimating residual range ...
00:19 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 4 ...
00:19 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:19 |   |   |   |   gram_schmidt: Removing vector 12 of norm 2.1958436305627265e-16
00:19 |   |   |   |   gram_schmidt: Orthonormalizing vector 15 again
00:19 |   |   ResidualReductor: Projecting residual operator ...
00:19 greedy: Estimating errors ...
00:22 greedy: Maximum error after 5 extensions: 46.28371663457766 (mu = {B: 0.0708, R: 0.0001})
00:22 greedy: Computing solution snapshot for mu = {B: 0.0708, R: 0.0001} ...
00:22 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0708, R: 0.0001} ...
00:22 greedy: Extending basis with solution snapshot ...
00:22 |   gram_schmidt: Orthonormalizing vector 5 again
      
00:22 greedy: Reducing ...
00:22 |   CoerciveRBReductor: RB projection ...
00:22 |   CoerciveRBReductor: Assembling error estimator ...
00:22 |   |   ResidualReductor: Estimating residual range ...
00:22 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 5 ...
00:22 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:22 |   |   |   |   gram_schmidt: Removing vector 15 of norm 4.856513302966699e-16
00:22 |   |   |   |   gram_schmidt: Orthonormalizing vector 17 again
00:22 |   |   |   |   gram_schmidt: Orthonormalizing vector 18 again
00:22 |   |   ResidualReductor: Projecting residual operator ...
00:22 greedy: Estimating errors ...
00:26 greedy: Maximum error after 6 extensions: 41.35728288180628 (mu = {B: 0.0001, R: 0.060700000000000004})
00:26 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.060700000000000004} ...
00:26 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.060700000000000004} ...
00:26 greedy: Extending basis with solution snapshot ...
00:26 |   gram_schmidt: Orthonormalizing vector 6 again
      
00:26 greedy: Reducing ...
00:26 |   CoerciveRBReductor: RB projection ...
00:26 |   CoerciveRBReductor: Assembling error estimator ...
00:26 |   |   ResidualReductor: Estimating residual range ...
00:26 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 6 ...
00:26 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:26 |   |   |   |   gram_schmidt: Removing vector 18 of norm 3.7264021444657053e-16
00:26 |   |   |   |   gram_schmidt: Orthonormalizing vector 21 again
00:26 |   |   ResidualReductor: Projecting residual operator ...
00:26 greedy: Estimating errors ...
00:29 greedy: Maximum error after 7 extensions: 18.96832142909099 (mu = {B: 0.0001, R: 0.596})
00:29 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.596} ...
00:29 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.596} ...
00:29 greedy: Extending basis with solution snapshot ...
00:29 |   gram_schmidt: Orthonormalizing vector 7 again
      
00:29 greedy: Reducing ...
00:29 |   CoerciveRBReductor: RB projection ...
00:29 |   CoerciveRBReductor: Assembling error estimator ...
00:29 |   |   ResidualReductor: Estimating residual range ...
00:29 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 7 ...
00:29 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:29 |   |   |   |   gram_schmidt: Removing vector 21 of norm 1.0456690646094309e-15
00:29 |   |   |   |   gram_schmidt: Orthonormalizing vector 23 again
00:29 |   |   |   |   gram_schmidt: Orthonormalizing vector 24 again
00:29 |   |   ResidualReductor: Projecting residual operator ...
00:29 greedy: Estimating errors ...
00:33 greedy: Maximum error after 8 extensions: 15.670922798571622 (mu = {B: 0.6364, R: 0.0001})
00:33 greedy: Computing solution snapshot for mu = {B: 0.6364, R: 0.0001} ...
00:33 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.6364, R: 0.0001} ...
00:33 greedy: Extending basis with solution snapshot ...
00:33 |   gram_schmidt: Orthonormalizing vector 8 again
      
00:33 greedy: Reducing ...
00:33 |   CoerciveRBReductor: RB projection ...
00:33 |   CoerciveRBReductor: Assembling error estimator ...
00:33 |   |   ResidualReductor: Estimating residual range ...
00:33 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 8 ...
00:33 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:33 |   |   |   |   gram_schmidt: Removing vector 24 of norm 2.3435484491542996e-15
00:33 |   |   |   |   gram_schmidt: Orthonormalizing vector 25 again
00:33 |   |   |   |   gram_schmidt: Orthonormalizing vector 26 again
00:33 |   |   |   |   gram_schmidt: Orthonormalizing vector 27 again
00:33 |   |   ResidualReductor: Projecting residual operator ...
00:33 greedy: Estimating errors ...
00:36 greedy: Maximum error after 9 extensions: 6.281860618858695 (mu = {B: 0.0203, R: 0.0001})
00:36 greedy: Computing solution snapshot for mu = {B: 0.0203, R: 0.0001} ...
00:36 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0203, R: 0.0001} ...
00:37 greedy: Extending basis with solution snapshot ...
00:37 |   gram_schmidt: Orthonormalizing vector 9 again
      
00:37 greedy: Reducing ...
00:37 |   CoerciveRBReductor: RB projection ...
00:37 |   CoerciveRBReductor: Assembling error estimator ...
00:37 |   |   ResidualReductor: Estimating residual range ...
00:37 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 9 ...
00:37 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:37 |   |   |   |   gram_schmidt: Removing vector 27 of norm 2.986575844722279e-15
00:37 |   |   |   |   gram_schmidt: Orthonormalizing vector 29 again
00:37 |   |   |   |   gram_schmidt: Orthonormalizing vector 30 again
00:37 |   |   ResidualReductor: Projecting residual operator ...
00:37 greedy: Estimating errors ...
00:40 greedy: Maximum error after 10 extensions: 4.646201879884575 (mu = {B: 0.0001, R: 0.0203})
00:40 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.0203} ...
00:40 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.0203} ...
00:40 greedy: Extending basis with solution snapshot ...
00:40 |   gram_schmidt: Orthonormalizing vector 10 again
      
00:40 greedy: Reducing ...
00:40 |   CoerciveRBReductor: RB projection ...
00:40 |   CoerciveRBReductor: Assembling error estimator ...
00:40 |   |   ResidualReductor: Estimating residual range ...
00:40 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 10 ...
00:40 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:40 |   |   |   |   gram_schmidt: Removing vector 30 of norm 1.204864401430773e-15
00:40 |   |   |   |   gram_schmidt: Orthonormalizing vector 32 again
00:40 |   |   |   |   gram_schmidt: Orthonormalizing vector 33 again
00:40 |   |   ResidualReductor: Projecting residual operator ...
00:40 greedy: Estimating errors ...
00:43 greedy: Maximum error after 11 extensions: 1.0355654795488056 (mu = {B: 0.010199999999999999, R: 0.0001})
00:43 greedy: Computing solution snapshot for mu = {B: 0.010199999999999999, R: 0.0001} ...
00:43 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.010199999999999999, R: 0.0001} ...
00:43 greedy: Extending basis with solution snapshot ...
00:43 |   gram_schmidt: Orthonormalizing vector 11 again
      
00:43 greedy: Reducing ...
00:43 |   CoerciveRBReductor: RB projection ...
00:44 |   CoerciveRBReductor: Assembling error estimator ...
00:44 |   |   ResidualReductor: Estimating residual range ...
00:44 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 11 ...
00:44 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:44 |   |   |   |   gram_schmidt: Removing vector 33 of norm 5.647768467057802e-15
00:44 |   |   |   |   gram_schmidt: Orthonormalizing vector 35 again
00:44 |   |   |   |   gram_schmidt: Orthonormalizing vector 36 again
00:44 |   |   ResidualReductor: Projecting residual operator ...
00:44 greedy: Estimating errors ...
00:47 greedy: Maximum error after 12 extensions: 0.854208469990706 (mu = {B: 0.0001, R: 0.010199999999999999})
00:47 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.010199999999999999} ...
00:47 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.010199999999999999} ...
00:47 greedy: Extending basis with solution snapshot ...
00:47 |   gram_schmidt: Orthonormalizing vector 12 again
      
00:47 greedy: Reducing ...
00:47 |   CoerciveRBReductor: RB projection ...
00:47 |   CoerciveRBReductor: Assembling error estimator ...
00:47 |   |   ResidualReductor: Estimating residual range ...
00:47 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 12 ...
00:47 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:47 |   |   |   |   gram_schmidt: Removing vector 36 of norm 6.701795057817819e-15
00:47 |   |   |   |   gram_schmidt: Orthonormalizing vector 38 again
00:47 |   |   |   |   gram_schmidt: Orthonormalizing vector 39 again
00:47 |   |   ResidualReductor: Projecting residual operator ...
00:47 greedy: Estimating errors ...
00:51 greedy: Maximum error after 13 extensions: 0.5521868085655179 (mu = {B: 0.0001, R: 0.38389999999999996})
00:51 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.38389999999999996} ...
00:51 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.38389999999999996} ...
00:51 greedy: Extending basis with solution snapshot ...
00:51 |   gram_schmidt: Orthonormalizing vector 13 again
      
00:51 greedy: Reducing ...
00:51 |   CoerciveRBReductor: RB projection ...
00:51 |   CoerciveRBReductor: Assembling error estimator ...
00:51 |   |   ResidualReductor: Estimating residual range ...
00:51 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 13 ...
00:51 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:51 |   |   |   |   gram_schmidt: Removing vector 39 of norm 2.423114965037598e-14
00:51 |   |   |   |   gram_schmidt: Orthonormalizing vector 41 again
00:51 |   |   |   |   gram_schmidt: Orthonormalizing vector 42 again
00:51 |   |   ResidualReductor: Projecting residual operator ...
00:51 greedy: Estimating errors ...
00:55 greedy: Maximum error after 14 extensions: 0.4929653071445868 (mu = {B: 0.15159999999999998, R: 0.0001})
00:55 greedy: Computing solution snapshot for mu = {B: 0.15159999999999998, R: 0.0001} ...
00:55 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.15159999999999998, R: 0.0001} ...
00:55 greedy: Extending basis with solution snapshot ...
00:55 |   gram_schmidt: Orthonormalizing vector 14 again
      
00:55 greedy: Reducing ...
00:55 |   CoerciveRBReductor: RB projection ...
00:55 |   CoerciveRBReductor: Assembling error estimator ...
00:55 |   |   ResidualReductor: Estimating residual range ...
00:55 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 14 ...
00:55 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:55 |   |   |   |   gram_schmidt: Removing vector 42 of norm 2.0323787240387254e-14
00:55 |   |   |   |   gram_schmidt: Orthonormalizing vector 44 again
00:55 |   |   |   |   gram_schmidt: Orthonormalizing vector 45 again
00:55 |   |   ResidualReductor: Projecting residual operator ...
00:55 greedy: Estimating errors ...
00:59 greedy: Maximum error after 15 extensions: 0.2316359088110416 (mu = {B: 0.010199999999999999, R: 1.0})
00:59 greedy: Computing solution snapshot for mu = {B: 0.010199999999999999, R: 1.0} ...
00:59 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.010199999999999999, R: 1.0} ...
00:59 greedy: Extending basis with solution snapshot ...
00:59 |   gram_schmidt: Orthonormalizing vector 15 again
      
00:59 greedy: Reducing ...
00:59 |   CoerciveRBReductor: RB projection ...
00:59 |   CoerciveRBReductor: Assembling error estimator ...
00:59 |   |   ResidualReductor: Estimating residual range ...
00:59 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 15 ...
00:59 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
00:59 |   |   |   |   gram_schmidt: Removing vector 45 of norm 1.7420316366544852e-15
00:59 |   |   |   |   gram_schmidt: Orthonormalizing vector 47 again
00:59 |   |   |   |   gram_schmidt: Orthonormalizing vector 48 again
00:59 |   |   ResidualReductor: Projecting residual operator ...
00:59 greedy: Estimating errors ...
01:03 greedy: Maximum error after 16 extensions: 0.17317119859004293 (mu = {B: 1.0, R: 0.010199999999999999})
01:03 greedy: Computing solution snapshot for mu = {B: 1.0, R: 0.010199999999999999} ...
01:03 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1.0, R: 0.010199999999999999} ...
01:03 greedy: Extending basis with solution snapshot ...
01:03 |   gram_schmidt: Orthonormalizing vector 16 again
      
01:03 greedy: Reducing ...
01:03 |   CoerciveRBReductor: RB projection ...
01:03 |   CoerciveRBReductor: Assembling error estimator ...
01:03 |   |   ResidualReductor: Estimating residual range ...
01:03 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 16 ...
01:03 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:03 |   |   |   |   gram_schmidt: Removing vector 48 of norm 2.406556260774081e-15
01:03 |   |   |   |   gram_schmidt: Orthonormalizing vector 50 again
01:03 |   |   |   |   gram_schmidt: Orthonormalizing vector 51 again
01:03 |   |   ResidualReductor: Projecting residual operator ...
01:03 greedy: Estimating errors ...
01:06 greedy: Maximum error after 17 extensions: 0.13487844931103896 (mu = {B: 0.8484999999999999, R: 0.0001})
01:06 greedy: Computing solution snapshot for mu = {B: 0.8484999999999999, R: 0.0001} ...
01:06 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.8484999999999999, R: 0.0001} ...
01:06 greedy: Extending basis with solution snapshot ...
01:06 |   gram_schmidt: Orthonormalizing vector 17 again
      
01:07 greedy: Reducing ...
01:07 |   CoerciveRBReductor: RB projection ...
01:07 |   CoerciveRBReductor: Assembling error estimator ...
01:07 |   |   ResidualReductor: Estimating residual range ...
01:07 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 17 ...
01:07 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:07 |   |   |   |   gram_schmidt: Orthonormalizing vector 52 again
01:07 |   |   |   |   gram_schmidt: Orthonormalizing vector 53 again
01:07 |   |   |   |   gram_schmidt: Orthonormalizing vector 54 again
01:07 |   |   ResidualReductor: Projecting residual operator ...
01:07 greedy: Estimating errors ...
01:12 greedy: Maximum error after 18 extensions: 0.10537984401529059 (mu = {B: 0.0001, R: 0.1112})
01:12 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.1112} ...
01:12 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.1112} ...
01:12 greedy: Extending basis with solution snapshot ...
01:12 |   gram_schmidt: Orthonormalizing vector 18 again
      
01:12 greedy: Reducing ...
01:12 |   CoerciveRBReductor: RB projection ...
01:12 |   CoerciveRBReductor: Assembling error estimator ...
01:12 |   |   ResidualReductor: Estimating residual range ...
01:12 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 18 ...
01:12 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 57 again
01:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 58 again
01:12 |   |   ResidualReductor: Projecting residual operator ...
01:12 greedy: Estimating errors ...
01:17 greedy: Maximum error after 19 extensions: 0.04232345508114265 (mu = {B: 0.0001, R: 0.8484999999999999})
01:17 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.8484999999999999} ...
01:17 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.8484999999999999} ...
01:17 greedy: Extending basis with solution snapshot ...
01:18 |   gram_schmidt: Orthonormalizing vector 19 again
      
01:18 greedy: Reducing ...
01:18 |   CoerciveRBReductor: RB projection ...
01:18 |   CoerciveRBReductor: Assembling error estimator ...
01:18 |   |   ResidualReductor: Estimating residual range ...
01:18 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 19 ...
01:18 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:18 |   |   |   |   gram_schmidt: Orthonormalizing vector 60 again
01:18 |   |   |   |   gram_schmidt: Orthonormalizing vector 61 again
01:18 |   |   |   |   gram_schmidt: Orthonormalizing vector 62 again
01:18 |   |   ResidualReductor: Projecting residual operator ...
01:18 greedy: Estimating errors ...
01:23 greedy: Maximum error after 20 extensions: 0.036465300659745424 (mu = {B: 0.0405, R: 0.0001})
01:23 greedy: Computing solution snapshot for mu = {B: 0.0405, R: 0.0001} ...
01:23 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0405, R: 0.0001} ...
01:23 greedy: Extending basis with solution snapshot ...
01:23 |   gram_schmidt: Orthonormalizing vector 20 again
      
01:24 greedy: Reducing ...
01:24 |   CoerciveRBReductor: RB projection ...
01:24 |   CoerciveRBReductor: Assembling error estimator ...
01:24 |   |   ResidualReductor: Estimating residual range ...
01:24 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 20 ...
01:24 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:24 |   |   |   |   gram_schmidt: Orthonormalizing vector 65 again
01:24 |   |   |   |   gram_schmidt: Orthonormalizing vector 66 again
01:24 |   |   ResidualReductor: Projecting residual operator ...
01:24 greedy: Estimating errors ...
01:30 greedy: Maximum error after 21 extensions: 0.034676333520369265 (mu = {B: 1.0, R: 0.18189999999999998})
01:30 greedy: Computing solution snapshot for mu = {B: 1.0, R: 0.18189999999999998} ...
01:30 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1.0, R: 0.18189999999999998} ...
01:30 greedy: Extending basis with solution snapshot ...
01:30 |   gram_schmidt: Orthonormalizing vector 21 again
      
01:30 greedy: Reducing ...
01:30 |   CoerciveRBReductor: RB projection ...
01:30 |   CoerciveRBReductor: Assembling error estimator ...
01:30 |   |   ResidualReductor: Estimating residual range ...
01:30 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 21 ...
01:30 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:30 |   |   |   |   gram_schmidt: Orthonormalizing vector 67 again
01:30 |   |   |   |   gram_schmidt: Orthonormalizing vector 68 again
01:30 |   |   |   |   gram_schmidt: Orthonormalizing vector 69 again
01:30 |   |   |   |   gram_schmidt: Orthonormalizing vector 70 again
01:30 |   |   ResidualReductor: Projecting residual operator ...
01:30 greedy: Estimating errors ...
01:36 greedy: Maximum error after 22 extensions: 0.0211620887810872 (mu = {B: 1.0, R: 0.0405})
01:36 greedy: Computing solution snapshot for mu = {B: 1.0, R: 0.0405} ...
01:36 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1.0, R: 0.0405} ...
01:36 greedy: Extending basis with solution snapshot ...
01:36 |   gram_schmidt: Orthonormalizing vector 22 again
      
01:36 greedy: Reducing ...
01:36 |   CoerciveRBReductor: RB projection ...
01:36 |   CoerciveRBReductor: Assembling error estimator ...
01:36 |   |   ResidualReductor: Estimating residual range ...
01:36 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 22 ...
01:36 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:36 |   |   |   |   gram_schmidt: Removing vector 71 of norm 5.832003254848112e-14
01:36 |   |   |   |   gram_schmidt: Orthonormalizing vector 73 again
01:36 |   |   |   |   gram_schmidt: Orthonormalizing vector 74 again
01:36 |   |   ResidualReductor: Projecting residual operator ...
01:36 greedy: Estimating errors ...
01:42 greedy: Maximum error after 23 extensions: 0.014536586870023361 (mu = {B: 0.1011, R: 1.0})
01:42 greedy: Computing solution snapshot for mu = {B: 0.1011, R: 1.0} ...
01:42 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.1011, R: 1.0} ...
01:42 greedy: Extending basis with solution snapshot ...
01:42 |   gram_schmidt: Orthonormalizing vector 23 again
      
01:42 greedy: Reducing ...
01:42 |   CoerciveRBReductor: RB projection ...
01:42 |   CoerciveRBReductor: Assembling error estimator ...
01:42 |   |   ResidualReductor: Estimating residual range ...
01:42 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 23 ...
01:42 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:42 |   |   |   |   gram_schmidt: Orthonormalizing vector 74 again
01:42 |   |   |   |   gram_schmidt: Orthonormalizing vector 76 again
01:42 |   |   |   |   gram_schmidt: Orthonormalizing vector 77 again
01:42 |   |   ResidualReductor: Projecting residual operator ...
01:42 greedy: Estimating errors ...
01:48 greedy: Maximum error after 24 extensions: 0.013329432239524012 (mu = {B: 0.2829, R: 0.010199999999999999})
01:48 greedy: Computing solution snapshot for mu = {B: 0.2829, R: 0.010199999999999999} ...
01:48 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.2829, R: 0.010199999999999999} ...
01:48 greedy: Extending basis with solution snapshot ...
01:48 |   gram_schmidt: Orthonormalizing vector 24 again
      
01:48 greedy: Reducing ...
01:48 |   CoerciveRBReductor: RB projection ...
01:48 |   CoerciveRBReductor: Assembling error estimator ...
01:48 |   |   ResidualReductor: Estimating residual range ...
01:48 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 24 ...
01:48 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:48 |   |   |   |   gram_schmidt: Removing vector 78 of norm 8.229241952026786e-14
01:48 |   |   |   |   gram_schmidt: Orthonormalizing vector 81 again
01:48 |   |   ResidualReductor: Projecting residual operator ...
01:48 greedy: Estimating errors ...
01:53 greedy: Maximum error after 25 extensions: 0.008296328595144847 (mu = {B: 0.0001, R: 0.0304})
01:53 greedy: Computing solution snapshot for mu = {B: 0.0001, R: 0.0304} ...
01:53 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0001, R: 0.0304} ...
01:53 greedy: Extending basis with solution snapshot ...
01:53 |   gram_schmidt: Orthonormalizing vector 25 again
      
01:53 greedy: Reducing ...
01:53 |   CoerciveRBReductor: RB projection ...
01:54 |   CoerciveRBReductor: Assembling error estimator ...
01:54 |   |   ResidualReductor: Estimating residual range ...
01:54 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 25 ...
01:54 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
01:54 |   |   |   |   gram_schmidt: Orthonormalizing vector 83 again
01:54 |   |   |   |   gram_schmidt: Orthonormalizing vector 84 again
01:54 |   |   ResidualReductor: Projecting residual operator ...
01:54 greedy: Estimating errors ...
01:59 greedy: Maximum error after 26 extensions: 0.008246202641230882 (mu = {B: 0.42429999999999995, R: 0.0001})
01:59 greedy: Computing solution snapshot for mu = {B: 0.42429999999999995, R: 0.0001} ...
01:59 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.42429999999999995, R: 0.0001} ...
01:59 greedy: Extending basis with solution snapshot ...
01:59 |   gram_schmidt: Orthonormalizing vector 26 again
      
01:59 greedy: Reducing ...
01:59 |   CoerciveRBReductor: RB projection ...
01:59 |   CoerciveRBReductor: Assembling error estimator ...
01:59 |   |   ResidualReductor: Estimating residual range ...
01:59 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 26 ...
01:59 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:00 |   |   |   |   gram_schmidt: Orthonormalizing vector 87 again
02:00 |   |   |   |   gram_schmidt: Orthonormalizing vector 88 again
02:00 |   |   ResidualReductor: Projecting residual operator ...
02:00 greedy: Estimating errors ...
02:05 greedy: Maximum error after 27 extensions: 0.0058066040836533585 (mu = {B: 0.0203, R: 0.3132})
02:05 greedy: Computing solution snapshot for mu = {B: 0.0203, R: 0.3132} ...
02:05 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0203, R: 0.3132} ...
02:05 greedy: Extending basis with solution snapshot ...
02:05 |   gram_schmidt: Orthonormalizing vector 27 again
      
02:05 greedy: Reducing ...
02:05 |   CoerciveRBReductor: RB projection ...
02:05 |   CoerciveRBReductor: Assembling error estimator ...
02:05 |   |   ResidualReductor: Estimating residual range ...
02:05 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 27 ...
02:05 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:05 |   |   |   |   gram_schmidt: Orthonormalizing vector 89 again
02:05 |   |   |   |   gram_schmidt: Orthonormalizing vector 92 again
02:06 |   |   ResidualReductor: Projecting residual operator ...
02:06 greedy: Estimating errors ...
02:12 greedy: Maximum error after 28 extensions: 0.0016575362490125064 (mu = {B: 0.6162, R: 0.010199999999999999})
02:12 greedy: Computing solution snapshot for mu = {B: 0.6162, R: 0.010199999999999999} ...
02:12 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.6162, R: 0.010199999999999999} ...
02:12 greedy: Extending basis with solution snapshot ...
02:12 |   gram_schmidt: Orthonormalizing vector 28 again
      
02:12 greedy: Reducing ...
02:12 |   CoerciveRBReductor: RB projection ...
02:12 |   CoerciveRBReductor: Assembling error estimator ...
02:12 |   |   ResidualReductor: Estimating residual range ...
02:12 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 28 ...
02:12 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 93 again
02:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 94 again
02:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 95 again
02:12 |   |   |   |   gram_schmidt: Orthonormalizing vector 96 again
02:12 |   |   ResidualReductor: Projecting residual operator ...
02:12 greedy: Estimating errors ...
02:20 greedy: Maximum error after 29 extensions: 0.0015271039860315994 (mu = {B: 1.0, R: 0.8282999999999999})
02:20 greedy: Computing solution snapshot for mu = {B: 1.0, R: 0.8282999999999999} ...
02:20 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 1.0, R: 0.8282999999999999} ...
02:20 greedy: Extending basis with solution snapshot ...
02:20 |   gram_schmidt: Orthonormalizing vector 29 again
      
02:20 greedy: Reducing ...
02:20 |   CoerciveRBReductor: RB projection ...
02:20 |   CoerciveRBReductor: Assembling error estimator ...
02:20 |   |   ResidualReductor: Estimating residual range ...
02:20 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 29 ...
02:20 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:20 |   |   |   |   gram_schmidt: Orthonormalizing vector 97 again
02:20 |   |   |   |   gram_schmidt: Orthonormalizing vector 98 again
02:21 |   |   |   |   gram_schmidt: Orthonormalizing vector 99 again
02:21 |   |   |   |   gram_schmidt: Orthonormalizing vector 100 again
02:21 |   |   ResidualReductor: Projecting residual operator ...
02:21 greedy: Estimating errors ...
02:27 greedy: Maximum error after 30 extensions: 0.001579610532117633 (mu = {B: 0.0304, R: 1.0})
02:27 greedy: Computing solution snapshot for mu = {B: 0.0304, R: 1.0} ...
02:27 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0304, R: 1.0} ...
02:28 greedy: Extending basis with solution snapshot ...
02:28 |   gram_schmidt: Orthonormalizing vector 30 again
      
02:28 greedy: Reducing ...
02:28 |   CoerciveRBReductor: RB projection ...
02:28 |   CoerciveRBReductor: Assembling error estimator ...
02:28 |   |   ResidualReductor: Estimating residual range ...
02:28 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 30 ...
02:28 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:28 |   |   |   |   gram_schmidt: Orthonormalizing vector 101 again
02:28 |   |   |   |   gram_schmidt: Orthonormalizing vector 103 again
02:28 |   |   |   |   gram_schmidt: Orthonormalizing vector 104 again
02:28 |   |   ResidualReductor: Projecting residual operator ...
02:28 greedy: Estimating errors ...
02:35 greedy: Maximum error after 31 extensions: 0.0013002145648843286 (mu = {B: 0.0304, R: 0.0001})
02:35 greedy: Computing solution snapshot for mu = {B: 0.0304, R: 0.0001} ...
02:35 |   StationaryDiscretization: Solving Blatt4_Aufgabe_1_parametric_CG for {B: 0.0304, R: 0.0001} ...
02:35 greedy: Extending basis with solution snapshot ...
02:35 |   gram_schmidt: Orthonormalizing vector 31 again
      
02:35 greedy: Reducing ...
02:35 |   CoerciveRBReductor: RB projection ...
02:35 |   CoerciveRBReductor: Assembling error estimator ...
02:35 |   |   ResidualReductor: Estimating residual range ...
02:35 |   |   |   estimate_image_hierarchical: Estimating image for basis vector 31 ...
02:35 |   |   |   estimate_image_hierarchical: Orthonormalizing ...
02:35 |   |   |   |   gram_schmidt: Orthonormalizing vector 105 again
02:35 |   |   |   |   gram_schmidt: Orthonormalizing vector 107 again
02:35 |   |   |   |   gram_schmidt: Orthonormalizing vector 108 again
02:36 |   |   ResidualReductor: Projecting residual operator ...
02:36 greedy: Estimating errors ...
02:43 greedy: Maximum error after 32 extensions: 0.0008611643216361232 (mu = {B: 0.0001, R: 0.16169999999999998})
02:43 greedy: Absolute error tolerance (0.001) reached! Stoping extension loop.
02:43 greedy: Greedy search took 161.71575474739075 seconds
  1. Stellen Sie den Fehlerabfall während der Basisgenerierung mit Hilfe der vom greedy Algorithmus zurück gegebenen Daten grafisch dar.
In [7]:
max_errs = greedy_data['max_errs']
plt.figure()
plt.semilogy(max_errs)
plt.xlabel('RB size')
plt.ylabel('max estimated error')
plt.title('Error decay (over training set) during greedy basis generation')
Out[7]:
Text(0.5, 1.0, 'Error decay (over training set) during greedy basis generation')

Aufgabe 2: PDE-constrained minimization

  1. Definieren Sie eine Funktione

    def parameter_to_output(R, B):
        ...

    welche mit Hilfe der reduzierten Diskretisierung und des reduzierten Ausgabefunktionals eine RB-Approximation von $J$ berechnet.

    • Extrahieren Sie dazu die reduzierte Diskretisierung aus den vom greedy Algorithmus übergebenen Daten.
In [8]:
rd = greedy_data['rd']
J = rd.operators['output_functional']

def parameter_to_output(R, B):
    u = rd.solve({'R': R, 'B': B})
    return J.apply(u).data[0][0]
In [9]:
def plot_3d(x, y, f, xlabel='X', ylabel='Y'):
    # compute_value_matrix
    f_of_x = np.zeros((len(x), len(y)))
    import time
    t = time.time()
    for ii in range(len(x)):
        for jj in range(len(y)):
            f_of_x[jj][ii] = f(x[ii], y[jj]) # ii and jj are switched on purpose!
    x, y = np.meshgrid(x, y)
    print('{} evaluations took {}s'.format(len(x)*len(y), time.time() - t))
    # plot
    from mpl_toolkits.mplot3d import Axes3D # required for 3d plots
    from matplotlib import cm # required for colormaps
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.plot_surface(x, y, f_of_x, cmap=cm.viridis)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.invert_xaxis()
    return ax

def plot_point(ax, point, color):
    x, y = point[0], point[1]
    ax.plot([x, x], [y, y], ax.get_zlim(), color, zorder=10)
  1. Erstellen Sie einen 3d Plot der RB-Approximation von $J$ mit Hilfe von plot_3d.

    • Geben Sie als x-Werte 100 gleichverteilte Werte im Definitionsbereich der Parameterkomponente R an, entsprechend als y-Werte B. Nutzen Sie dazu den Parameterraum der reduzierten Diskretisierung.
In [10]:
ax = plot_3d(np.linspace(*rd.parameter_space.ranges['R'], 100),
             np.linspace(*rd.parameter_space.ranges['B'], 100),
             parameter_to_output, xlabel='R', ylabel='B')
xlocs, xlabels = plt.xticks()
ylocs, ylabels = plt.yticks()
10000 evaluations took 3.9125216007232666s
  1. Machen Sie sich mit der minimize Funktion in scipy vertraut und vervollständigen Sie die Definition von find_minimum, um das Minimierungsproblem zu lösen.

    • wählen Sie als Minimierer den BFGS Algorithmus für "Bound-Constrained minimization"

    • lassen Sie den Gradienten von $J$ mit Hilfe von Finiten Differenzen Approximieren

    • nutzen Sie den Paramterraum der reduzierten Diskretisierung um das "Bound-Constrained" zu definieren

    • übergeben Sie options={'ftol': 1e-15}

In [11]:
def find_minimum(initial_guess):
    from scipy.optimize import minimize
    return minimize(lambda mu: parameter_to_output(mu[0], mu[1]),
                    initial_guess,
                    method='L-BFGS-B', jac=False,
                    bounds=(rd.parameter_space.ranges['R'], rd.parameter_space.ranges['B']),
                    options={'ftol': 1e-15})

def print_report(result):
    if result.success:
        print('succeded after {} iterations (required {} PDE solves)'.format(result.nit, result.nfev))
        print('J({}) = {}'.format(result.x, result.fun))
    else:
        print('failed!')
  1. Lassen Sie die Minimierung für vier verschiedene Anfangswerte mit Hilfe des folgenden Codes druchlaufen. Was können Sie beobachten?
In [12]:
for mu, color in zip(rd.parameter_space.sample_uniformly(2), ('red', 'yellow', 'orange', 'purple')):
    initial_guess = [mu['R'], mu['B']]    
    print('minimizing from {}...'.format(initial_guess))
    result = find_minimum(initial_guess)
    print_report(result)
    plot_point(ax, result.x, color)
    print('')
minimizing from [array(0.0001), array(0.0001)]...
succeded after 7 iterations (required 24 PDE solves)
J([0.0001     0.07097346]) = 0.002849831289926982

minimizing from [array(1.), array(0.0001)]...
succeded after 9 iterations (required 39 PDE solves)
J([0.0001     0.07093573]) = 0.0028498314120881576

minimizing from [array(0.0001), array(1.)]...
succeded after 3 iterations (required 51 PDE solves)
J([0.0001     0.07163161]) = 0.0028498319014712424

minimizing from [array(1.), array(1.)]...
succeded after 10 iterations (required 69 PDE solves)
J([0.4280417  0.01167548]) = 0.0031462490223433167

  1. Erstellen Sie einen 3d plot der RB-Approximation von $J$ wie oben, wobei die $x$ und $y$ Punkte nicht gleichverteilt, sonder mit Hilfe des Logarithmus zur Basis 10 verteilt sind.
In [15]:
ax = plot_3d(np.log10(np.linspace(*rd.parameter_space.ranges['R'], 100)),
             np.log10(np.linspace(*rd.parameter_space.ranges['B'], 100)),
             lambda x, y: parameter_to_output(10**x, 10**y), xlabel='R', ylabel='B')
xlocs, _ = plt.xticks()
ylocs, _ = plt.yticks()
plt.xticks(np.linspace(min(xlocs), max(xlocs), len(xlabels)), xlabels)
plt.yticks(np.linspace(min(ylocs), max(ylocs), len(ylabels)), ylabels)
10000 evaluations took 3.5173699855804443s
Out[15]:
([<matplotlib.axis.XTick at 0x7f68492632b0>,
  <matplotlib.axis.XTick at 0x7f6849463a90>,
  <matplotlib.axis.XTick at 0x7f6849328da0>,
  <matplotlib.axis.XTick at 0x7f68496cd978>,
  <matplotlib.axis.XTick at 0x7f684926a2b0>,
  <matplotlib.axis.XTick at 0x7f684926a7b8>,
  <matplotlib.axis.XTick at 0x7f684926acc0>,
  <matplotlib.axis.XTick at 0x7f6843833208>],
 <a list of 8 Text yticklabel objects>)
  1. Wiederholen Sie auch die Minimierung und grafische Darstellung der gefundenen Minima. Passen Sie letzteren entsprechend an.
In [16]:
for mu, color in zip(rd.parameter_space.sample_uniformly(2), ('red', 'yellow', 'orange', 'purple')):
    initial_guess = [mu['R'], mu['B']]    
    print('minimizing from {}...'.format(initial_guess))
    result = find_minimum(initial_guess)
    print_report(result)
    plot_point(ax, np.log10(result.x), color)
    print('')
minimizing from [array(0.0001), array(0.0001)]...
succeded after 7 iterations (required 24 PDE solves)
J([0.0001     0.07097346]) = 0.002849831289926982

minimizing from [array(1.), array(0.0001)]...
succeded after 9 iterations (required 39 PDE solves)
J([0.0001     0.07093573]) = 0.0028498314120881576

minimizing from [array(0.0001), array(1.)]...
succeded after 3 iterations (required 51 PDE solves)
J([0.0001     0.07163161]) = 0.0028498319014712424

minimizing from [array(1.), array(1.)]...
succeded after 10 iterations (required 69 PDE solves)
J([0.4280417  0.01167548]) = 0.0031462490223433167