Skip to content

Commit

Permalink
Fix the two piecewise-linear regression calculation
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
shallawa committed Aug 30, 2024
1 parent 69140b5 commit a9cd222
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions MotionMark/resources/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,19 @@ Regression = Utilities.createClass(
},

_areEssentiallyEqual: function(n1, n2) {
const epsilon = 0.001;
const epsilon = 0.0001;
return Math.abs(n1 - n2) < epsilon;
},

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

let complexity = this._complexity();
if (!this._areEssentiallyEqual(this.segment1.t, this.segment2.t)) {
// If segment1 and segment2 are not parallel, then they have to meet
// at complexity such that xp < complexity < x.
if (!(complexity >= xp && complexity <= x))
if (!(complexity >= x && complexity <= xn))
return false;
} else {
// If segment1 and segment2 are parallel, then they have to form one
Expand Down Expand Up @@ -395,7 +395,7 @@ Regression = Utilities.createClass(
};
}

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

// These values remove the influence of this sample
Expand Down Expand Up @@ -426,7 +426,7 @@ Regression = Utilities.createClass(
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)
};

this._setOptimal(segment1, segment2, xp, x, options);
this._setOptimal(segment1, segment2, x, sortedSamples[j + 1][complexityIndex], options);
}
}
});
Expand Down

0 comments on commit a9cd222

Please sign in to comment.