12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import numpy as np
- import matplotlib.pyplot as plt
- # f(x) = 1/(1+e(-z))
- def sigmoid(x, min_value=0.3, max_value=5, right_offset=5, span=10):
- """
- min_value: y最小值
- max_value: y最大值
- right_offset: 曲线右移
- span: y从接近最小到接近最大时,自变量x的跨度
- """
- # 右移
- x -= right_offset
- # 缩放
- x *= 10 / span
- # 振幅
- return (max_value - min_value) / (1 + np.exp(-x)) + min_value
- # def test():
- # plt.rcParams["font.family"] = "SimHei"
- # plt.rcParams["axes.unicode_minus"] = False
- # plt.rcParams["font.size"] = 12
- #
- # z = np.linspace(-10, 10, 200)
- # plt.plot(z, sigmoid(z))
- #
- # plt.axvline(x=0, ls="--", c="k")
- # plt.axhline(ls=":", c="k")
- # plt.axhline(y=0.5, ls=":", c="k")
- # plt.axhline(y=1, ls=":", c="k")
- # plt.xlabel("z值")
- # plt.ylabel("sigmoid(z)值")
- if __name__ == "__main__":
- for i in range(20):
- x = i + 1
- print(x, sigmoid(x, span=10))
- # cd grpc
- # mkdir -p cmake/build
- # pushd cmake/build
- # cmake -DgRPC_INSTALL=ON \
- # -DgRPC_BUILD_TESTS=OFF \
- # ../..
- # make -j 4
- # make install
- # popd
|