Advertisement
Guest User

Untitled

a guest
Dec 4th, 2020
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import scipy.optimize as sco
  4.  
  5. x = np.array([180, 300, 560, 1000, 2000, 4999, 10000, 20000])
  6. y = np.array([826.68, 1169.74, 1709.03, 2255.51, 2827.74, 3302.12, 3486.19, 3681.87])
  7.  
  8. def log(bla):
  9.     a, b, c = bla
  10.     return a * np.log(c*x) + b - y
  11.  
  12. def sigmoid(bla):
  13.     d, a, c, b = bla
  14.     return d + (a-d)/(1+(x/c)**b) - y
  15.  
  16. res_log = sco.least_squares(log, [1., 0., 10.], method='lm').x
  17. res_sigmoid = sco.least_squares(sigmoid, [4000., 0., 1., 1.], method='lm').x
  18.  
  19. plotty = np.geomspace(100, 30000)
  20. plt.plot(x, y, 'rx')
  21. plt.plot(plotty, res_log[0]*np.log(res_log[2]*plotty) + res_log[1], 'g-', label='log')
  22. plt.plot(plotty, res_sigmoid[0] + (res_sigmoid[1] - res_sigmoid[0]) / (1+(plotty/res_sigmoid[2])**res_sigmoid[3]), 'b--', label='sigmoid')
  23. plt.legend()
  24. plt.show()
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement