对称轴x=0.5凹
from matplotlib import pyplot as mp
def quadratic(x, n=2):
return (2 * x - 1) ** n
w = [i / 400 for i in range(401)]
mp.figure(figsize=(5, 5))
mp.scatter([0, .5, 1], [1, 0, 1], s=75, color='b', alpha=.3)
mp.plot(w, [quadratic(i) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 4) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 8) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 16) for i in w], color='b', alpha=.2)
mp.show()
对称轴x=0.5凸
from matplotlib import pyplot as mp
def quadratic(x, n=2):
return 1 - (2 * x - 1) ** n
w = [i / 400 for i in range(401)]
mp.figure(figsize=(5, 5))
mp.scatter([0, .5, 1], [0, 1, 0], s=75, color='b', alpha=.3)
mp.plot(w, [quadratic(i) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 4) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 8) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 16) for i in w], color='b', alpha=.2)
mp.show()
x0>x0.5>x1凹
from matplotlib import pyplot as mp
def quadratic(x, n=2):
return (1 - x) ** n
w = [i / 400 for i in range(401)]
mp.figure(figsize=(5, 5))
mp.scatter([0, 1], [1, 0], s=75, color='b', alpha=.3)
mp.plot(w, [quadratic(i) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 4) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 8) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 16) for i in w], color='b', alpha=.2)
mp.show()
x1>x0.5>x0凹
from matplotlib import pyplot as mp
def quadratic(x, n):
return x ** n
w = [i / 400 for i in range(401)]
mp.figure(figsize=(5, 5))
mp.scatter([0, 1], [0, 1], s=75, color='b', alpha=.3)
mp.plot(w, [quadratic(i, 1/16) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 1/8) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 1/4) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 1/2) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 1) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 2) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 4) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 8) for i in w], color='b', alpha=.2)
mp.plot(w, [quadratic(i, 16) for i in w], color='b', alpha=.2)
mp.show()
Gaussian Process Regression
from sklearn.gaussian_process import GaussianProcessRegressor
from matplotlib import pyplot as mp
X = [[0], [.1], [.2], [.3], [.4], [.5], [.6], [.7], [.8], [.9], [1]]
Y1 = [[1], [.2], [.04], [.02], [.01], [0], [0], [.01], [.03], [.1], [.5]]
Y2 = [[.5], [.1], [.03], [.01], [0], [0], [.01], [.02], [.04], [.2], [1]]
def g1():
"""start > end > middle"""
return GaussianProcessRegressor().fit(X, Y1)
def g2():
"""end > start > middle"""
return GaussianProcessRegressor().fit(X, Y2)
w = [[i / 400] for i in range(401)]
mp.scatter(X, Y1, s=75, color='g', alpha=.3)
mp.scatter(w, g1().predict(w), s=6, color='g', alpha=.2)
mp.scatter(X, Y2, s=75, color='r', alpha=.3)
mp.scatter(w, g2().predict(w), s=6, color='r', alpha=.2)
mp.show()