Advertisement
toweber

membership_tests_scratch

Sep 9th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import numpy as np
  2. import skfuzzy as fuzz
  3. import matplotlib.pyplot as plt
  4. import ipdb
  5.  
  6. def trimf(x, abc):
  7.     a, b, c = abc
  8.     y = np.zeros(len(x))
  9.     left_side_eq = (1/(b-a))*(x-a)
  10.     right_side_eq = (1/(c-b))*(-x+c)
  11.     y = np.minimum(left_side_eq,right_side_eq)    
  12.     y = np.maximum(y,0)
  13.     return y
  14.  
  15. def trapmf(x,abcd):
  16.     a, b, c, d = abcd
  17.     left_side_eq = (1/(b-a))*(x-a)
  18.     right_side_eq = (1/(d-c))*(-x+d)
  19.     y = np.minimum(left_side_eq,right_side_eq)    
  20.     y = np.maximum(y,0)
  21.     y = np.minimum(y,1)
  22.     return y
  23.  
  24.  
  25. x = np.linspace(0,10,110)
  26. mfx = trimf(x, [0, 5, 10])
  27. plt.plot(x,mfx)
  28. plt.show()
  29.  
  30. mfx = trapmf(x, [0, 3, 7 , 10])
  31. plt.plot(x,mfx)
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement