Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: webrtc/modules/congestion_controller/theil_sen_estimator.cc

Issue 2512693002: Implement Theil-Sen's method for fitting a line to noisy data (used in bandwidth estimation). (Closed)
Patch Set: Use PercentileFilter to find median slope Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/congestion_controller/theil_sen_estimator.h"
12
13 #include <algorithm>
14 #include <vector>
15
16 #include "webrtc/base/logging.h"
17 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
19
20 namespace webrtc {
21
22 enum { kDeltaCounterMax = 1000 };
brandtr 2016/11/28 16:27:19 Can you use a constexpr size_t instead?
terelius 2016/12/02 16:45:52 Done, except using unsigned int.
23
24 TheilSenEstimator::TheilSenEstimator(size_t window_size, double threshold_gain)
25 : window_size_(window_size),
26 threshold_gain_(threshold_gain),
27 num_of_deltas_(0),
28 accumulated_delay_(0),
29 delay_hist_(),
30 median_filter_(0.5),
31 trendline_(0) {}
32
33 TheilSenEstimator::~TheilSenEstimator() {}
34
35 void TheilSenEstimator::Update(double recv_delta_ms,
36 double send_delta_ms,
37 double now_ms) {
38 const double delta_ms = recv_delta_ms - send_delta_ms;
39 ++num_of_deltas_;
40 if (num_of_deltas_ > kDeltaCounterMax) {
41 num_of_deltas_ = kDeltaCounterMax;
42 }
43
44 accumulated_delay_ += delta_ms;
45 BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", now_ms, accumulated_delay_);
46
47 // First remove the oldest N-1 slopes if the window is full.
brandtr 2016/11/28 16:27:19 This could be a computer science thing, but it's n
terelius 2016/12/02 16:45:52 Done.
48 if (delay_hist_.size() == window_size_) {
49 std::pair<double, double> old_delay = delay_hist_.front();
stefan-webrtc 2016/11/28 13:01:58 I think auto would be fine here if you'd prefer th
terelius 2016/12/02 16:45:52 This part of the code has changed, so the comment
50 delay_hist_.pop_front();
51 for (const auto& new_delay : delay_hist_) {
52 if (new_delay.first - old_delay.first != 0) {
53 double slope = (new_delay.second - old_delay.second) /
54 (new_delay.first - old_delay.first);
brandtr 2016/11/28 16:27:19 I see the problem here that you were discussing be
terelius 2016/12/02 16:45:52 A problem with the quantization approach is that I
brandtr 2016/12/05 12:34:44 Right. This comment, as well as the one on line 63
55 if (!median_filter_.Erase(slope))
stefan-webrtc 2016/11/28 13:01:58 {}
terelius 2016/12/02 16:45:52 Done.
56 LOG(LS_ERROR) << "Failed to erase previously inserted slope. This is "
57 "a bug, likely related to rounding.";
stefan-webrtc 2016/11/28 13:01:58 Should this happen? Otherwise a DCHECK might make
terelius 2016/12/02 16:45:52 Kept the error message but added an RTC_NOTREACHED
58 }
59 }
60 }
61 // Add N-1 new slopes.
62 for (const auto& old_delay : delay_hist_) {
63 if (now_ms - old_delay.first != 0) {
brandtr 2016/11/28 16:27:19 I guess that if (now_ms - old_delay.first) is clos
terelius 2016/12/02 16:45:52 The filter should be robust anyway, so I don't thi
64 double slope =
65 (accumulated_delay_ - old_delay.second) / (now_ms - old_delay.first);
66 median_filter_.Insert(slope);
67 }
68 }
69 delay_hist_.push_back(std::make_pair(now_ms, accumulated_delay_));
70 // Recompute the median slope.
71 if (delay_hist_.size() == window_size_) {
stefan-webrtc 2016/11/28 13:01:58 Feel free to remove {}
terelius 2016/12/02 16:45:52 Done.
72 trendline_ = median_filter_.GetPercentileValue();
73 }
74
75 BWE_TEST_LOGGING_PLOT(1, "trendline_slope", now_ms, trendline_);
76 }
77
78 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698