Skip to content

Commit a9cd222

Browse files
committed
Fix the two piecewise-linear regression calculation
#66 The current implementation of the regression calculation has these flaws: When processing (x[0], y[0]), L1 must be any line through (x[0], y[0]) which meets L2 at a point (x’, y’) where x[0] < x' < x[1]. L1 has no error. When processing (x[n - 2], y[n - 2]), L2 must be any line through (x[n - 1], y[n - 1]) which meets L1 at a point (x’, y’) where x[n - 2] < x' < x[n - 1]. L2 has no error. The lambda calculation is incorrect. It includes a term called H which is equal to C - I. Looking at the algorithm of Kundu/Ubhaya, this should be just C. lambda should to be used with calculating L1 and (1 - lambda) should to be used with calculating L2. Currently (1 - lambda) is used in calculating L1 and L2. The current calculation has this condition if (t1 != t2) continue; This condition is almost always true even if t1 and t2 are essentiallyEqual.
1 parent 69140b5 commit a9cd222

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

MotionMark/resources/statistics.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,19 @@ Regression = Utilities.createClass(
244244
},
245245

246246
_areEssentiallyEqual: function(n1, n2) {
247-
const epsilon = 0.001;
247+
const epsilon = 0.0001;
248248
return Math.abs(n1 - n2) < epsilon;
249249
},
250250

251-
_setOptimal: function(segment1, segment2, xp, x, options) {
251+
_setOptimal: function(segment1, segment2, x, xn, options) {
252252
if (segment1.e + segment2.e > this.segment1.e + this.segment2.e)
253253
return false;
254254

255255
let complexity = this._complexity();
256256
if (!this._areEssentiallyEqual(this.segment1.t, this.segment2.t)) {
257257
// If segment1 and segment2 are not parallel, then they have to meet
258258
// at complexity such that xp < complexity < x.
259-
if (!(complexity >= xp && complexity <= x))
259+
if (!(complexity >= x && complexity <= xn))
260260
return false;
261261
} else {
262262
// If segment1 and segment2 are parallel, then they have to form one
@@ -395,7 +395,7 @@ Regression = Utilities.createClass(
395395
};
396396
}
397397

398-
if (this._setOptimal(segment1, segment2, xp, x, options))
398+
if (this._setOptimal(segment1, segment2, x, sortedSamples[j + 1][complexityIndex], options))
399399
continue
400400

401401
// These values remove the influence of this sample
@@ -426,7 +426,7 @@ Regression = Utilities.createClass(
426426
e: (k2 + a2 * s2 * s2 + c2 * t2 * t2 - 2 * d2 * s2 - 2 * h2 * t2 + 2 * b2 * s2 * t2) + lambda1 * Math.pow(y - (s2 + t2 * x), 2)
427427
};
428428

429-
this._setOptimal(segment1, segment2, xp, x, options);
429+
this._setOptimal(segment1, segment2, x, sortedSamples[j + 1][complexityIndex], options);
430430
}
431431
}
432432
});

0 commit comments

Comments
 (0)