[关闭]
@Pigmon 2018-08-30T04:39:40.000000Z 字数 565 阅读 70

Day2-1

作业


1 问题:请用python实现sigmoid函数

  1. # -*- coding: utf-8 -*-
  2. """
  3. Udacity Lesson day2
  4. Sigmoid func
  5. Day2-1 Yuan Sheng
  6. """
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. def sigmoid(x):
  10. "Sigmoid(x) = 1 / (1 + e^{-x})"
  11. return 1. / (1. + np.e ** (-x))
  12. if __name__ == '__main__':
  13. # Plot sigmoid[-6, 6]
  14. x = np.linspace(-6, 6, 50)
  15. plt.plot(x, sigmoid(x))
  16. plt.show()

输出:
Day2-1.PNG-27.3kB

11 问题:计算感知机的结果Y ...

答案: y = 1.0

  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. def sum(_x1, _w1, _x2, _w2, _b, _w3):
  4. return _x1 * _w1 + _x2 * _w2 + _b * _w3
  5. def fun(x):
  6. "Sigmoid(x) = 1 / (1 + e^{-x})"
  7. return 1. / (1. + np.e ** (-x))
  8. if __name__ == '__main__':
  9. x1, x2, b, w1, w2, w3 = 7, -3, 0, 7, 6, 1
  10. print (fun(sum(x1, w1, x2, w2, b, w3)))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注