Closed jbarnoud closed 6 years ago
I updated to numpy-1.14.5 and symfit-0.4.1 and the issue remains. The snippet has to be adapted to explicitly use the name
keyword argument for variables and parameters.
Interesting. Could you try to use the master branch instead of the latest release? I remember something related to this came up recently and was patched but I'm not sure it's in the latest release yet.
Some work arounds might be to call Fit
with sigma_length=None
or sigma_length=np.ones_like(length_data)
to see if this solves your problem.
Let me know if this problem persist in the current master branch.
I just tried the latest version on master (1344b80e7cf8d09ec0b2c777b17982ca9eaa98de) and got the same result. I also tried the two suggested workarounds and got the same exception.
Btw, I don't understand your remark "The snippet has to be adapted to explicitly use the name keyword argument for variables and parameters." Does that mean that if you do that, the problem is gone?
I have not had time yet to run your snippet, but hopefully I will have some next week.
I've seen the code and issue in action, and if you specify variable and parameter names it still breaks.
Ok, I've found the origin of the problem. Because this model has a single additive Parameter, symfit
is not able to determine the shape of the data on the level of the Model
. (Because Model
's don't have knowledge about the data.)
So in Model.elav_jacobian
there is some logic which makes sure all the components of the Jacobian have the same shape, but in this case the jacobian is only the derivative w.r.t shift
, which is 1
. Because there is no other component, the jacobian returned is therefore [[[1]]] (lists correspond to param, component, datapoints).
But that is not correct, it should be [[ 8 [1]]] in your example in order for it to be contracted with the weight matrix W
in the line
`cov_matrix_inv = np.tensordot(Wjac, jac, (range(1, jac.ndim), range(1, jac.ndim)))`
Now the question is, what to do about it in light of the plans for 1.0.0, which will upgrade Variables to indexed objects, which will make it easier to prevent these issues in the first place because Fit
can then work with a deepcopy of the Model
whose Variable
shapes have been set on the bases of the data. This will make such problems a thing of the past.
So I'm now unsure wether to add a quick try/except for this specific type of problem, or to set this to wontfix because it will be fixed in the future in a far more elegant way.
As a workaround for your immediate problems btw, I can now suggest using
k = symfit.Parameter('k', value=1, fixed=True)
model = {length: shift + 1 / (1 + symfit.exp(- k* temperature))}
instead. This way the shape can be correctly estimated.
Now the question is, what to do about it in light of the plans for 1.0.0, which will upgrade Variables to indexed objects, which will make it easier to prevent these issues in the first place because Fit can then work with a deepcopy of the Model whose Variable shapes have been set on the bases of the data. This will make such problems a thing of the past.
Sounds like a good solution, but it really depends on when you intend to release this. I it's more than a month away I think a quickfix is a good idea.
You are right. I could say soon but since no project in human history is ever delivered according to schedule, a quick fix is probably in order ;).
I try to run the following snippet but get an exception:
The exception:
According to
pip show
I am using version 0.3.3.dev487 of symfit, version 1.1.1 of sympy, and 1.14.3 of numpy.I try to simplify the model to
{length: shift - temperature}
and I get the same error.