jlperla / continuous_time_methods

MIT License
23 stars 15 forks source link

Solving simple HJBE with non-uniform grid. #29

Closed jlperla closed 6 years ago

jlperla commented 6 years ago

@stevenzhangdx adding as observer. This depends on #28

jlperla commented 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.

stevenzhangdx commented 6 years ago

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.

jlperla commented 6 years ago

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$)

stevenzhangdx commented 6 years ago

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.

jlperla commented 6 years ago

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:

sevhou commented 6 years ago

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:

  1. GBM_adding_points_test:

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$.

  1. NUF_shift_point_test:

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$.

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?

sevhou commented 6 years ago

6a1ac0840365298bff4510db31d0cbeb80af5d73

jlperla commented 6 years ago

Tests look good to me. Thanks guys.