packages <- c('tidyverse', 'ggthemes', 'knitr', 'kableExtra', 'Matrix', 'reticulate',
"plotly")
sapply(packages, require, character.only = TRUE, quietly = TRUE)
use_condaenv("r-reticulate")
theme_set(theme_tufte(base_size = 14) +
theme(panel.border = element_rect(fill = NA),
panel.grid.major = element_line(color = "gray78"),
legend.background = element_rect(),
legend.position = "top",
axis.text.x = element_text(angle = 30, hjust = 1),
strip.background = element_rect(fill = "grey90", linetype = "blank")))Let \(S \subset \mathbb R\) and denote by C the set of all Cauchy-sequences \((a_n)_{n\in\mathbb N} \in S\). Show that
\[ (a_n)_{n\in\mathbb N} \sim (b_n)_{n\in\mathbb N}, \text{ if and only if } (c_n)_{n\in\mathbb N} \in C \text{ for } c_n = \begin{cases} a_{n/2}, \text{ n even,} \\ b_{(n+1)/2}, \text{ n odd,} \end{cases} \]
defines an equivalence relation on C.
Solution: For this to be an equivalence relation it must satisfy three constraints.
1. \((a_n)_{n\in\mathbb N} \sim (a_n)_{n\in\mathbb N}\):
2. \((a_n)_{n\in\mathbb N} \sim (b_n)_{n\in\mathbb N} \rightarrow (b_n)_{n\in\mathbb N} \sim (a_n)_{n\in\mathbb N}\)
3. \((a_n)_{n\in\mathbb N} \sim (b_n)_{n\in\mathbb N} \wedge (b_n)_{n\in\mathbb N} \sim (k_n)_{n\in\mathbb N} \rightarrow (a_n)_{n\in\mathbb N} \sim (k_n)_{n\in\mathbb N}\)
If you have an almost scalar-product on a vector-space X over \(\mathbb R\), the only property not being fulfilled being that \(\langle x, x \rangle\) might be 0, even though \(x \neq 0\), how could you construct a scalar-product from this and on which set? What is the equivalence relation?
Let \(\Omega\) be a non-empty set. A function \(K:\Omega \times \Omega \rightarrow \mathbb R\) is said to be symmetric if \(K(x,y) = K(y,x)\) for all \(x,y\in \Omega\). It is said to be positive semi-definite if for all \(\{x_1, x_2, ..., x_N\} \subset \Omega, x_i \neq x_j\) if \(i \neq j\) and all \(c_1, c_2, ..., c_N \in \mathbb R\) we have
\[ \sum_{i,j=1}^Nc_ic_jK(x_i,x_j) \geq 0. \tag{*} \]
It is said to be positive definite if additionally \((*) = 0\) implies \(c_1 = c_2 = ... = c_N = 0\)
Consider \(K: \mathbb R^n \times \mathbb R^n \rightarrow \mathbb R, K(x, y) := \Phi(x - y)\) for a continuous function \(\Phi: \mathbb R^n \rightarrow \mathbb R\).
Show that if K is symmetric and positive semidefinite, then \(\Phi(0) \geq 0, \Phi(x) = \Phi(-x), |\Phi(x)| \leq \Phi(0), x \in \mathbb R^n\).
Solution: Let \(x \in \mathbb R^n\)
(1) \(\Phi(0) \geq 0\)
\[ \begin{aligned} \Phi(0) &= K(x, x) \geq 0 \end{aligned} \]
(2) \(\Phi(x) = \Phi(-x)\)
\[ \begin{aligned} \Phi(x) &= K(x, 0) \\ &= K(0, x) \\ &= \phi(-x) \end{aligned} \]
(3) \(|\Phi(x)| \leq \Phi(0)\)
\[ \begin{aligned} |\Phi(x)| &= |K(x, 0)| \\ &= |K(0, x)| \end{aligned} \]
Show that if \(\Phi(x) = \Phi(-x)\) and
\[ \begin{align} \Phi(x) &= \frac{1}{(2\pi)^n}\int_{\mathbb R^n} \tilde \Phi(\omega)e^{i\omega\cdot x}d^n\omega, \text{ where } \\ \tilde \Phi(\omega) &= \int_{\mathbb R^n}\Phi(x)e^{-i\omega\cdot x}d^mx \end{align} \]
then \(\tilde\Phi(\omega) \geq 0\) for all \(\omega \in \mathbb R^n\) implies that K is symmetric and positive semidefinite.
Solution:
Write a program to approximate the function
\[ W(x, y) = \frac{1}{1+x^2+y^2}sin(x^2+y^2) \]
on \([-3,3]^2\) with
\[ I_s(x) = \sum_{k=1}^N\alpha_kK_s(x, x_k), \ s = 1,2,3. \]
You should choose an appropriate grid \(X = \{x_1, x_2, ..., x_n\} \subset \mathbb R^2\) and plot \(I_s\) using different points than the grid points. It might be useful to copy the plot commands from the Crank-Nicolson program.
Press the Code tick to see the full code implemented with tensorflow. The others tabs contain plots of W(x, y), the radial basis approximation and the error at each (x, y) pair. To test the \(\alpha\) parameters I create a new grid and randomly perturb the coordinates with gaussian noise.
import tensorflow as tf
import numpy as np
n_points = tf.placeholder("int32")
phi_1 = lambda r: tf.nn.relu(1 - r)**4 * (4 * r + 1)
phi_2 = lambda r: tf.pow(1 + r**2, -1./2)
phi_3 = lambda r: tf.exp(-r**2)
x = tf.linspace(start = -3., stop = 3., num = n_points)
X = tf.meshgrid(x, x)
X = tf.stack(X)
a, b = x[None, :, None], x[:, None, None]
cart = tf.concat([a + tf.zeros_like(b), tf.zeros_like(a) + b], axis = 2)
cart = tf.reshape(cart, (n_points**2, 2))
A = tf.map_fn(lambda y: tf.map_fn(lambda x: phi_1(tf.norm(x - y)), elems = cart), elems = cart)
beta_plot = tf.map_fn(lambda y: 1 / (1 + y**2 + x**2) * tf.sin(y**2 + x**2), elems = x)
beta = tf.reshape(beta_plot, (n_points**2, 1))
alpha = tf.linalg.solve(A, beta)
alpha_plot = tf.reshape(alpha, (n_points, n_points))
x_hat = tf.linspace(start = -3., stop = 3., num = n_points)
x_hat += tf.random_normal(mean=0, stddev= tf.to_float(1 / (n_points)), shape = tf.shape(x_hat))
a_hat, b_hat = x_hat[None, :, None], x_hat[:, None, None]
cart_hat = tf.concat([a_hat + tf.zeros_like(b_hat), tf.zeros_like(a_hat) + b_hat], axis = 2)
cart_hat = tf.reshape(cart_hat, (n_points**2, 2))
A_hat = tf.map_fn(lambda y: tf.map_fn(lambda x: phi_1(tf.norm(x - y)), elems = cart_hat), elems = cart_hat)
beta_hat = tf.reshape(tf.matmul(A_hat, alpha), (n_points, n_points))
error = beta_plot - beta_hat
out = (error, beta_hat, beta_plot)