import numpy as np
import matplotlib.pyplot as plt
Sharktooth Functions in 1-dimension
def max_conv_operator(samples, f_samples, input, L):
return np.max(f_samples - L * np.abs(input - samples))
def sharktooth_function(function, x_start, x_stop, number_of_sharkteeth, L, plot_arg):
= np.random.uniform(x_start,x_stop, number_of_sharkteeth)
samples = function(samples)
f_samples = np.linspace(x_start, x_stop, 10000)
x = []
approximate_y for i in range(len(x)):
approximate_y.append(max_conv_operator(samples, f_samples, x[i], L))= np.max(np.abs(f(x) - approximate_y))
error if plot_arg == 1:
plt.plot(x,approximate_y)else:
return error
def f(x):
return x/(x+2)
= [1,4,8,16]
L =(17,5))
plt.figure(figsizefor L in L:
= []
errors for i in range(1,50):
0,1,i,L,0))
errors.append(sharktooth_function(f,import matplotlib.pyplot as plt
=L)
plt.plot(errors, label
"Number of teeth")
plt.xlabel(r"$\sup_{x\in x_i} | f(x)- \mathfrak{R}_{\mathfrak{r}} ( \mathsf{P})|$")
plt.ylabel(
plt.legend()"Sup of deviance from f(x) as the number of teeth increase and as we get closer to L") plt.title(
Text(0.5, 1.0, 'Sup of deviance from f(x) as the number of teeth increase and as we get closer to L')