NumEconCopenhagen / lectures-2020

MIT License
12 stars 29 forks source link

Error in L11 6.2 #15

Open pth577 opened 4 years ago

pth577 commented 4 years ago

We get an error running the code in L11 under 6.2. It seems that the problem is the bounds and that for the first value of m2, the upper and lower bounds are the same - [1e-8, 1e-8].

We are able to solve the problem if we add 0.001 to the upper bound but as we are not sure what implications that might have to other problems, we hope that we can get a clarification of why this problem arises.

L11,1 L11,2

AskerNC commented 4 years ago

This is an error that appeared in the 1.4.1 version of Scipy, it is fixed in the master-version on Github so future versions shouldn't have this problem. As you've correctly noted this happens when the bounds are the same or extremely close. In this case, the optimizer should simply return 1e-8 as the optimal x (as it is the only available option due to the bounds) but the way the code is written it throws an error. Adding 0,001 is theoretically (if you're being very stringent) not correct as it allows the consumer to spend 0,0001 more than was saved. But it will fix the problem and be numerically close to correct. A more stringent thing to do would be to increase the lower bound of the solved space, f.x. 1e-4: m2_vec = np.linspace(1e-4,5,500) This is still arbitrarily close enough to zero for the plot to look the same. Further, in this particular problem, savings can't be negative so m2 will newer be lower than y2=1-delta=0.5, so it won't cause any disturbances for the interpolater. It's a bit unfortunate to have a version-dependent error in the Scipy package, but I hope this explanation helps