I would like to put ellipsometric data in a complex model using lmfit. The two measured parameters, psi and delta , are variables in the complex function rho .
I could try to separate the problem into the real and imaginary parts using general parameters or picewise , but is there a way to do this directly with a complex function? Setting only the real part of the function works beautifully, but when I define a complex residual function, I get:
TypeError: An order relation is not defined for complex numbers.
Below is my code for installing a real function and my attempt to solve a complex problem:
from __future__ import division from __future__ import print_function import numpy as np from pylab import * from lmfit import minimize, Parameters, Parameter, report_errors
Edit: I solved the problem with separated variables for the imaginary and real parts. The data must be in the form [[imaginary_data], [real_data]], the target function must return a 1D array.
def objective(params, th_data, data): eps_re = params['eps_re'].value eps_im = params['eps_im'].value d = params['d'].value residual_delta = data[0,:] - delta(eps_re - eps_im*1j, d, frac, lambd, th_data) residual_psi = data[1,:] - psi(eps_re - eps_im*1j, d, frac, lambd, th_data) return np.append(residual_delta,residual_psi) # create a set of Parameters params = Parameters() params.add('eps_re', value= 1.5, min=1.0, max=5 ) params.add('eps_im', value= 1.0, min=0.0, max=5 ) params.add('d', value= 10.0, min=5.0, max=100.0 ) # All available methods methods=['leastsq','nelder','lbfgsb','anneal','powell','cobyla','slsqp'] # Chosen method #metoda='leastsq' # run the global fit to all the data sets result = minimize(objective, params, args=(th_data,data),method=metoda)) .... return ...