Note to self: it appears that these errors are preventable by swapping the timelines to single-precision floats, but I am not knowledgeable enough to predict whether this will prevent these issues in all cases. In case anyone can comment on this I would be happy to hear it.
How to increase the tolerance for comparing time points when synchronizing timetables?
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi,
TL;DR: I am suffering from floating-point errors in time comparisons when synchronizing timetables and I am hoping that there exist a simple way to increase the tolerance of the comparison to mitigate the problem. Thanks in advance!
---
The following code generates two timetables with timelines that are supposed to be identical besides a shift in their initial values:
N = 9;
dt = .3;
mkTime = @(t0) seconds(t0+dt : dt : t0+N*dt);
t1 = mkTime(0);
t2 = mkTime(4*dt);
v1 = (1:N)';
v2 = (1:N)';
tt1 = timetable(v1, 'RowTimes', t1)
tt2 = timetable(v2, 'RowTimes', t2)
However, when tt1 and tt2 are synchronized, the resulting timetable contains multiple 'duplicates' of time points that are on the order of 1e-16 apart from each other (in this case at times 1.8 and 2.1):
tt = synchronize(tt1, tt2)
tt.Time(7) - tt.Time(6)
I would very much like for these duplicates to be recognized as having identical times instead, hence my question: How can the tolerance for comparing time points be increased, so that it does not suffer from these precision errors?
---
Some remarks:
The older version of synchronize for timeseries offered this possibility via the 'tolerance' keyword, which leads me to assume that something similar should be available for timetable.
The documentation for synchronize offers multiple interpolation and resampling strategies for dealing with overlapping but misaligned time data:
tt_wrong = synchronize(tt1, tt2, 'regular', 'linear', TimeStep = seconds(dt))
However, it seems like overkill to employ such methods for mere precision errors and, moreover, they do unfortunately not apply in the current scenario, since the result pads the nonoverlapping pieces of each timetable with nonsense values.
---
Any help will be much appreciated, thanks in advance!
Julius
댓글 수: 2
Star Strider
2023년 9월 2일
I am not certain what the exact problem is (since this seems to be a proxy problem). Consider using the ismembertol function.
답변 (2개)
Les Beckham
2023년 9월 1일
편집: Les Beckham
2023년 9월 1일
Based on this section of the documentation: Synchronize Timetables to Arbitrary Time Vector
N = 9;
dt = .3;
mkTime = @(t0) seconds(t0+dt : dt : t0+N*dt);
t1 = mkTime(0);
t2 = mkTime(4*dt);
v1 = (1:N)';
v2 = (1:N)';
tt1 = timetable(v1, 'RowTimes', t1);
tt2 = timetable(v2, 'RowTimes', t2);
% create the time vector for synchronizing with a new time vector
t = seconds(uniquetol(seconds(union(t1, t2)), 1e-4)) % this is the tricky/messy bit
TT = synchronize(tt1, tt2, t, 'linear')
Seth Furman
2023년 9월 13일
If possible, please provide more detail about the actual data so that I can try to provide better guidance. For example,
- Where are the row-times coming from?
- Are the row-times regular?
- Do the data only need to be precise to second?
In this particular case, simply creating the time vectors using duration arithmetic instead of double arithmetic avoids the precision issue.
N = 9;
dt = seconds(.3);
mkTime = @(t0) t0+dt : dt : t0+N*dt;
t1 = mkTime(seconds(0));
t2 = mkTime(4*dt);
v1 = (1:N)';
v2 = (1:N)';
tt1 = timetable(v1, 'RowTimes', t1)
tt2 = timetable(v2, 'RowTimes', t2)
tt = synchronize(tt1, tt2)
tt.Time(7) - tt.Time(6)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!