insaf021 opened a new pull request, #360:
URL: https://github.com/apache/commons-math/pull/360

   Reproduced on master, JDK 21:
   
       SimpleRegression r = new SimpleRegression();
       r.addData(1, 1);
       r.removeData(1, 1);                              // n == 0
       r.addData(0, 0); r.addData(1, 2); r.addData(2, 4);
       r.getSlope();                                    // NaN, expected 2.0
   
   `removeData` divides by `n - 1`, so removing the last observation sets 
`sumXX`, `sumYY` and `sumXY` to NaN (`0 * Infinity`) when the model has an 
intercept, which is the default. `addData` only resets `xbar` and `ybar` at `n 
== 0`, so the NaN sums survive and every later fit on the instance is NaN until 
`clear()`. The documented sliding-window use hits this whenever the window 
drains, `removeData(double[][])` included, and `append` of an emptied instance 
turns a healthy fit's slope into NaN too.
   
   Removing the last observation now clears the model, which is the state an 
empty model is in anyway. Removals that leave at least one observation are 
unchanged. The UnnecessaryParentheses suppression for `regress()` in 
`checkstyle-suppressions-legacy.xml` is pinned by line number, so it moves from 
823 to 827.
   
   `testRemoveToEmptyThenReuse` in `SimpleRegressionTest` fails on master 
(`expected:<0.0> but was:<NaN>`) and passes with the fix. `mvn clean verify 
javadoc:javadoc -pl commons-math-legacy` is green on JDK 21 (3266 tests, 0 
Checkstyle violations; the only reruns are the randomised optimizer tests).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to