Updated derivation with improved numerical stability - #1180
Conversation
|
Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1180 |
|
@NimaSarajpoor Would you mind taking a look when you have some time? Thanks in advance! You may need to download the file in order to get the LaTex to render properly |
NimaSarajpoor
left a comment
There was a problem hiding this comment.
@seanlaw
It was great to see all the steps involved in deriving equation (91). Thanks for putting them together so clearly! I have shared a few comments for your consideration.
| "3. $dg^{T}_{i,m} = \\left( t_{i+m-1} - M_{T_{i,m}} \\right) + \\left( t_{i-1} - M_{T_{i-1,m}} \\right)$\n", | ||
| "4. $dg^{Q}_{i,m} = \\left( q_{i+m-1} - \\mu_{Q_{i,m}} \\right) + \\left( q_{i-1} - \\mu_{Q_{i-1,m}} \\right)$\n", | ||
| "\n", | ||
| "Then our equation simply becomes:\n", |
There was a problem hiding this comment.
It should be worth it to better demonstrate/explain the benefit of achieving this new equation. We can show that the new equation (91) has LARGER UPDATE and therefore should be more stable as it has less catastrophic cancelation.
Let's start with the equation (40), i.e.
Let's multiply both sides by m:
Recall that m * cov is basically the summation part of "centered sum-of-products". So, this means the update term in the equation (91), i.e. m * update (NOT update). This quickly shows that the new equation has LARGER UPDATE.
There was a problem hiding this comment.
Let's see what else we can get from the relationship between equation (40) and (91). Let's start from equation (40) again:
where
Let's multiply both sides of equation (40) by
Again, recall that m * cov is basically the summation part of "centered sum-of-products". So, if I compare the equation above with the equation (91), I can see:
Note that
Can we simply use the update term
There was a problem hiding this comment.
Maybe it's an issue on my end when things are being rendered in my Jupyter notebook but I'm only seeing a single equation number for a block of related/multiline equations:
If you are seeing the same thing, maybe we can refer to the lines as (14.1) - (14.5) (to mean lines 1-5 in equation block 14)? Otherwise, I am counting equations one-by-one each time :(
Or maybe you have a different workflow?
There was a problem hiding this comment.
Can we simply use the update term
$\frac{m−1}{m}U$ when we use the summation part of "centered sum-of-products"?
I've tried reading your comments a few times but I am unable to get your point.
Therefore, if we say that
$U$ involves the subtraction of two nearby numbers and that can lead to catastrophic cancellation, then, in that scenario, we will have "catastrophic cancellation" on the right hand side too as that is even smaller!
I feel like I'm only reading this as a statement of fact but I am getting the sense that you have a much stronger point/argument that I am overlooking :(
You started with:
It should be worth it to better demonstrate/explain the benefit of achieving this new equation.
Maybe I've been staring at the equations too long but I'm not able to see "how" this is demonstrating the benefit any further (i.e., what is the special insight that "proves" the benefit clearly). I know you so I can feel that there is something (intuition?) there. I'm just not smart enough to infer your intuition but I would like to hear more.
There was a problem hiding this comment.
Or maybe you have a different workflow?
I didn't download the notebook. I just opened the file on Github from your branch. It renders the file differently and I didn't know that it affects the equations numbers! Apologies for the inconvenience.
Please allow me to download the updated notebook and read it again to see the added information. I will use the equation numbers from there.
There was a problem hiding this comment.
I downloaded and read the (updated) notebook. I opened the file in notebook this time and cannot see equation numbers. Strange!
I've tried reading your comments a few times but I am unable to get your point.
If I understand correctly, the gist of this PR is that:
- The correction term
$[(q_{i+m-1} - \mu_{Q_{i,m-1}})(t_{i+m-1} - M_{T_{i,m-1}}) - (q_{i-1} - \mu_{Q_{i,m-1}}) (t_{i-1} - M_{T_{i,m-1}})]$ , which involves the subtraction of two nearby numbers, is small and can lead to catastrophic cancellation. - The proposal is to use
$df^{T}.dg^{Q} + df^{Q}.dg^{T}$ instead (in a new recurrence relation).
HOWEVER, it can be shown that
So, we might be better off using the original correction term when updating the
There was a problem hiding this comment.
Hmm, I see your point and do not yet have a good answer...
There was a problem hiding this comment.
I have been thinking about conducting an experiment that can demonstrate empirically which option works better when updating
If we can compute the actual values directly with higher precision, we can see which option works better.
What do you think?
There was a problem hiding this comment.
What do you think?
I am certainly not opposed to it. Perhaps, the statement about "catastrophic cancellation" was not correct and that language can be softened. From a PR perspective, at what point is the derivation "correct" and what we need to do is adjust the language (maybe as a separate PR)?
There was a problem hiding this comment.
Perhaps, the statement about "catastrophic cancellation" was not correct
Probably...If "a - b" has catastrophic cancellation, then the issue might be addressed if we change it to subtraction-free operations (with positive-only elements). However, this is not achieved here.
From a PR perspective, at what point is the derivation "correct"
I think the moment we obtained the original correction term, i.e.
And that's it (unless we can show the reformulated version is better)
But, something is still bothering me. If the equation above is better (i.e., numerically more stable), then what about the following?
So, we compute
Pull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directory and ensured that all tests are passing locallyPlease do not commit any code to avoid/circumvent a failing test and, instead, engage in a discussion (below) to determine the best course of action.
Only request a review after the checklist above is fully completed!