Using PyMC3 in a model with complex variables inside

Hi! I am trying to use estimate the parameters of a surface given reflectance data using a physical scattering model (mostly a complicated function). Everything works fine until the sampling, in which this error raises,

TypeError: Elemwise{real,no_inplace}.grad illegally  returned an integer-valued variable. (Input index 0, dtype complex128)

I only found one reference here in which is stated that this error raises when Theano founds a complex number, even if the resulting value is real (as is this case, in which I am computing the reflectivity and not its phase). Their solution (to bypass complex numbers) is not possible in my case. Is there any other work around?

Thank you for the feedback.

1 Like

I know you mentioned that you don’t care about the phase - would it be possible to convert the complex number into two real valued variables? Also, would you be able to provide a short(er) script that can generate the issue?

Thank you for the feedback!

I can implement all the complex calculus as vectorial, but I have to give up all the already builder numpy machinery for complex analysis. I prefeer not to do that.

I am trying to produce a nontrivial implementation to share with you, I will have it in the following days.