区间[0,1]的各种函数图像(不定更)

对称轴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()

区间[0,1]的各种函数图像(不定更)_第1张图片

对称轴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()

区间[0,1]的各种函数图像(不定更)_第2张图片

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()

区间[0,1]的各种函数图像(不定更)_第3张图片

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()

区间[0,1]的各种函数图像(不定更)_第4张图片

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()

区间[0,1]的各种函数图像(不定更)_第5张图片

你可能感兴趣的:(Python可视化)