[SciPy-user] OdrPack and complex model

Gerard Vermeulen gav451@gmail....
Mon Jun 2 13:52:29 CDT 2008

On Mon, 02 Jun 2008 16:35:17 +0200
Fabrice Silva <silva@lma.cnrs-mrs.fr> wrote:

> Hi, 
> I would like to use odr to fit a complex model on reference values as
> causality issues occur when trying to adjust separately modulus and
> argument.
> Is it possible with odr ?

I have adjusted real and imaginary values at the same time.
Pseudo-code looks like:

import numpy as np

def f(parameters, omega, data=0, sigma=1.0):
    # len(data) = 2*len(omega)
    # data[:len(omega)] contains the "real" experimental data
    # data[len(omega):] contains the "imaginary" experimental data
    zs = np.zeros(len(omega), np.complex_)
    # calculate zs here, using parameters and omega
    xsys = np.zeros(2*len(omega), np.float64)
    xsys[:len(omega)] = zs.real
    xsys[len(omega):] = ys.real
    return (xsys-data)/sigma

# f()

Regards -- Gerard

PS: if data can be complex, then f() can return (zs-data)/sigma.
I have forgotten whether I have tried that.

PPS: same idea works with leastsq()

More information about the SciPy-user mailing list