sigmoid.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # f(x) = 1/(1+e(-z))
  4. def sigmoid(x, min_value=0.3, max_value=5, right_offset=5, span=10):
  5. """
  6. min_value: y最小值
  7. max_value: y最大值
  8. right_offset: 曲线右移
  9. span: y从接近最小到接近最大时,自变量x的跨度
  10. """
  11. # 右移
  12. x -= right_offset
  13. # 缩放
  14. x *= 10 / span
  15. # 振幅
  16. return (max_value - min_value) / (1 + np.exp(-x)) + min_value
  17. # def test():
  18. # plt.rcParams["font.family"] = "SimHei"
  19. # plt.rcParams["axes.unicode_minus"] = False
  20. # plt.rcParams["font.size"] = 12
  21. #
  22. # z = np.linspace(-10, 10, 200)
  23. # plt.plot(z, sigmoid(z))
  24. #
  25. # plt.axvline(x=0, ls="--", c="k")
  26. # plt.axhline(ls=":", c="k")
  27. # plt.axhline(y=0.5, ls=":", c="k")
  28. # plt.axhline(y=1, ls=":", c="k")
  29. # plt.xlabel("z值")
  30. # plt.ylabel("sigmoid(z)值")
  31. if __name__ == "__main__":
  32. for i in range(20):
  33. x = i + 1
  34. print(x, sigmoid(x, span=10))
  35. # cd grpc
  36. # mkdir -p cmake/build
  37. # pushd cmake/build
  38. # cmake -DgRPC_INSTALL=ON \
  39. # -DgRPC_BUILD_TESTS=OFF \
  40. # ../..
  41. # make -j 4
  42. # make install
  43. # popd