Surface NMR processing and inversion GUI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nonlinearinv.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import numpy as np
  2. import scipy.optimize as so
  3. def phid(Wd, K, m, d_obs):
  4. """
  5. Wd = data weighting matrix
  6. K = complex valued forward model kernel
  7. m = model
  8. d_obs = observed data
  9. """
  10. #print("phid=", np.linalg.norm(np.dot(Wd, np.abs(np.dot(K,m)) - d_obs))**2 / len(d_obs) )
  11. return np.linalg.norm(np.dot(Wd, np.abs(np.dot(K,m)) - d_obs))**2
  12. def phim(Wm, m):
  13. """
  14. Wm = model weighting matrix
  15. x = model
  16. """
  17. return np.linalg.norm(np.dot(Wm, m))**2
  18. def PHI(m, Wd, K, d_obs, Wm, alphastar):
  19. """
  20. Global objective function
  21. m = model to be fit, unknown 'x'
  22. Wd = data weighting matrix
  23. K = complex forward modelling kernel
  24. d_obs = observed data (modulus)
  25. Wm = model weighting matrix
  26. alphastar = regularisation to use
  27. """
  28. return phid(Wd, K, m, d_obs) + alphastar*phim(Wm, m)
  29. # main
  30. def nonlinearinversion( x0, Wd, K, d_obs, Wm, alphastar):
  31. print("Performing non-linear inversion")
  32. args = (Wd, K, d_obs, Wm, alphastar)
  33. #return so.minimize(PHI, np.zeros(len(x0)), args, 'Nelder-Mead')
  34. bounds = np.zeros((len(x0),2))
  35. bounds[:,0] = x0*0.75
  36. bounds[:,1] = x0*1.25
  37. #bounds[:,0] = 0
  38. #bounds[:,1] = np.max(x0)*1.25
  39. return so.minimize(PHI, x0, args, 'L-BFGS-B', bounds=bounds) # Works well
  40. #return so.minimize(PHI, x0, args, 'Powell', bounds=bounds) # Slow but works
  41. #return so.minimize(PHI, x0, args, 'trust-constr', bounds=bounds) # very Slow
  42. #return so.minimize(PHI, x0, args, 'TNC', bounds=bounds) # slow
  43. #return so.minimize(PHI, x0, args, 'SLSQP', bounds=bounds) # slow