am_dot_com

IA 2022-12-07

Dec 7th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. def referencial():
  5. fig = plt.figure()
  6. #https://matplotlib.org/stable/api/figure_api.html?highlight=add_subplot#matplotlib.figure.Figure.add_subplot
  7. theAxes = fig.add_subplot(1, 1, 1) #controls the organization of the figure (e.g. 1x1, 2x2) and the index of the 1st contained sub figure, if not 1x1
  8. theAxes.spines['left'].set_position('center') #forces the left spine to be at the center
  9. theAxes.spines['bottom'].set_position('zero') #forces the bottom spine to be plotted at zero
  10. theAxes.spines['right'].set_color('none') #makes the right spine invisible
  11. theAxes.spines['top'].set_color('none') #makes the top spine invisible
  12. theAxes.xaxis.set_ticks_position('bottom') # controls where the x points' labels are written
  13. theAxes.yaxis.set_ticks_position('left') #controls where the y points' labels are written
  14. # def referencial
  15.  
  16. """
  17. rispid limit
  18. x<0 ; y=-1
  19. x>0 ; y=1
  20. """
  21. x_axis_xlt0 = np.linspace(-5, 0, 100)
  22. x_axis_xgt0 = np.linspace(0, 5, 100)
  23. y_axis_xlt0 = np.linspace(-1, -1, 100)
  24. y_axis_xgt0 = np.linspace(1, 1, 100)
  25. referencial()
  26. plt.plot(x_axis_xlt0, y_axis_xlt0)
  27. plt.plot(x_axis_xgt0, y_axis_xgt0)
  28. plt.show()
  29.  
  30.  
  31. # TODO 1
  32.  
  33. """
  34. ramp function = relu
  35. x<0 ; y=0
  36. 0<=x<=1 ; y=x
  37. x>1 ; y=1
  38. """
  39.  
  40. # TODO 2
  41.  
  42. """
  43. sigmoid
  44. y = 1/(1+e**-x)
  45. """
  46. x_axis = np.linspace(-5, 5, 100)
  47. y_axis = 1/(1+np.e**(-1*x_axis))
  48. referencial()
  49. plt.plot(x_axis, y_axis)
  50. plt.show()
  51.  
  52.  
  53. # TODO 3
  54.  
  55. """
  56. hyperbolic tangent
  57. (e**x - e**-x) / (e**x + e**-x)
  58. """
  59. x_axis = np.linspace (-10, 10, 1000)
  60. y_axis = (np.e**x_axis - np.e**(-1*x_axis)) / (np.e**x_axis + np.e**(-1*x_axis))
  61. referencial()
  62. plt.plot(x_axis, y_axis)
  63. plt.title("Hyperbolic tangent")
  64. plt.show()
  65.  
  66.  
  67.  
  68. # TODO 4
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment