Closed jlperla closed 6 years ago
See the new test file HJBE_discretized_nonuniform_univariate_test.m
as a starting point.
I am not 100% sure that this is working. When I add in points to the problem (i.e. see GBM_adding_points_test
) the tolerance changes more than I would expect... but maybe there isn't a problem.
Add a few extra points on the test to make sure that you think the setup is correct. For example, you could take the uniform grid, and just shift all but one or two few points around by a tiny number (so it is no longer uniform, but is pretty close). If the result is extremely close for the new $v$, then maybe there isn't an issue. If there is a problem, it is probably in using the wrong $\Delta_{+}$, etc. somewhere.
I created a non-uniform grid and tried to compare the new v with the one previously saved. However, the largest difference is around 0.12, which seems that there is a problem. I will keep thinking about this problem to see if I can come up with any idea.
Sounds good. My guess is that, if there is an error, it is at the corners.
I think the key is to first ensure that a uniform grid works (calling the nonuniform code), then check that you can add only a single point and that it gives the same some, etc. The other thing to do is verify that if you change the number of gridpoints with a uniform grid that it gives a close solution. If not, then 0.12 may be within the error region (though I doubt it if you are using a large $I$)
I manually checked uniform grid with small $I$ and shift one point by $\epsilon$. The results are quite close with difference around $5\times 10^{-5}$. Then I tried the example with a large $I$ and shift most points by iid $\epsilon$'s. Since shifts are randomly generated, I generated two non-uniform grids (very close to each other) and compared the results. The max difference decreases to $3\times 10^5$. But values still do not match for cases with added points.
Sure sounds like there is a bug in the code or the algebra. An epsilon change to one grid point should only have a tiny effect on the L-infinity norm.
Here are a few suggestions:
Steven and I checked the code on test file _HJBE_discretized_nonuniform_univariatetest.m and found there's some issue with the comparison of previous version. So I create three different tests here:
It's the same as original one, where the baseline results is generated by uniform grid with $I=1500$ and then add 20 points onto the grid, and use nonuniform grid to solve for $v$. The test compares the interpolated $v$ from nonuniform result with $v$ from uniform result. This gives the largest difference of magnitude $1e-4$.
This test generates uniform grid $I=1500$, then shift all points by random $\epsilon$, then use this nonuniform grid compute $v$. The test compares interpolated nonuniform $v$ with the uniform $v$, this gives a largest diff in level of $1e-8$.
3.NUF_shift_point_2_test:
This is similar to 2, I use the add_point nonuniform grid that is generated in 1, then shift it by random $\epsilon$ and compare the two results from nonuniform grid, the maximum difference is $1e-7$.
For all the experiments above $\epsilon\sim 1e-9$.
Another thing I did is checking whether the difference is induced by interpolation, as the add_point grid contains all the points in the uniform grid, I locate the corresponding $v$ values from the nonuniform result. It turns out not an issue of interpolation, as the interpolated results are the same as the corresponding nonuniform result.
From these results it seems the nonuniform code is probably not completely off? @jlperla Are you expecting the $v$ for uniform and nonuniform to be exactly the same? Or differs at a smaller magnitude?
6a1ac0840365298bff4510db31d0cbeb80af5d73
Tests look good to me. Thanks guys.
@stevenzhangdx adding as observer. This depends on #28