Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ public void append(SimpleRegression reg) {
* @param y dependent variable value
*/
public void removeData(final double x,final double y) {
if (n > 0) {
if (n == 1) {
// Removing the last observation empties the model; the updating
// formulas below would divide by n - 1 = 0.
clear();
} else if (n > 0) {
if (hasIntercept) {
final double fact1 = n - 1.0;
final double fact2 = n / (n - 1.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,29 @@ public void testRemoveMultiplePastEmpty() {
regression.removeData(removeMultiple);
Assert.assertEquals(regression.getN(), 0);
}

// Remove multiple observations to empty, then reuse the instance
@Test
public void testRemoveToEmptyThenReuse() {
final SimpleRegression expected = new SimpleRegression();
expected.addData(infData);

final SimpleRegression regression = new SimpleRegression();
regression.addData(removeMultiple);
regression.removeData(removeMultiple);
Assert.assertEquals(0, regression.getN());
Assert.assertEquals(0, regression.getSumOfCrossProducts(), 0);

// Appending the emptied instance must not change the target
final SimpleRegression appended = new SimpleRegression();
appended.addData(infData);
appended.append(regression);
Assert.assertEquals(expected.getSlope(), appended.getSlope(), 0);
Assert.assertEquals(expected.getIntercept(), appended.getIntercept(), 0);

regression.addData(infData);
Assert.assertEquals(expected.getSlope(), regression.getSlope(), 0);
Assert.assertEquals(expected.getIntercept(), regression.getIntercept(), 0);
Assert.assertEquals(expected.getRSquare(), regression.getRSquare(), 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleCurveFitter\.java$" lines="321-322" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]LevenbergMarquardtOptimizer\.java$" lines="525,739" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]EnumeratedDistribution\.java$" lines="128-129" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleRegression\.java$" lines="823" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]SimpleRegression\.java$" lines="827" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]MillerUpdatingRegression\.java$" lines="172-173" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]GraggBulirschStoerIntegrator\.java$" lines="638-639,679,767" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]MultiDirectionalTransform\.java$" lines="94" />
Expand Down
Loading