-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
post_process uses full correlation, fix filter_atoms #284
Conversation
Fix filter_atoms
Co-authored-by: Jacob Wilkins <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a very quick test for a VAF value, as presumably we don't currently if none of the tests broke? Maybe even just modify an existing test where we do post processing, so it could be very light weight?
Also could you clarify the difference between "same" and "full" in this context? Am I right in thinking we could recover "same" from "full", if we wanted? Would we ever want to?
Yes I'll ad a VAF test in there for the values. On the same and full. Essentially it is due to how the signals are convolved. Full will perform a "full" convolution padding the edges of the array with 0's to do it. "same" will not. And so will be a subset, the "middle" of the full convolution. Not sure if we'd want to use that for correlations honestly. Also see the docs for
In detail, "full" will give you this (but twice over, symmetric about the middle value of the array) which is what the multi-tau correlator will also return (there is a factor of Same will do the same, but only up to the input size. The result is not a "full" correlation. It is the middle of it. import numpy as np
from typing import Iterable
def correlate(
x: Iterable[float], y: Iterable[float]) -> Iterable[float]:
"""Direct correlation of x and y."""
n = min(len(x), len(y))
cor = np.zeros(n)
for j in range(n):
for i in range(n - j):
cor[j] += x[i] * y[i + j]
return cor
n = 5
a = [i for i in range(n)]
same = np.correlate(a, a, 'same')
full = np.correlate(a, a, 'full')[n-1:]
print("same", same)
print("full", full)
print("direct", correlate(a, a))
# same [11 20 30 20 11]
# full [ 0 4 11 20 30 20 11 4 0]
# direct [30. 20. 11. 4. 0.] Going out to bigger inputs (n=64) it is more obvious
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, looks good!
np.correlate(x, x, "full")
otherwise we end up with correlations like so on the right, with the left being the output of the (forthcoming) online VAF calculation, see Adds Velocity, ShearStress, StressDiagonal, observables #285 for more details.((0, 2, 4, ...), (1, 3, 5, ...))
as is the case in the NaCl struct it converts it to(range(len(atoms)), (1, 3, 5, ...))
since0 and 0 === False
.