Merge branch 'MATH-1477__chee'

Closes #104.
This commit is contained in:
Gilles Sadowski 2019-04-10 03:10:43 +02:00
commit 8694f8478b
3 changed files with 40 additions and 10 deletions

View File

@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release> </release>
<release version="4.0" date="XXXX-XX-XX" description=""> <release version="4.0" date="XXXX-XX-XX" description="">
<action dev="erans" type="add" issue="MATH-1477" due-to="Chee Sing Lee">
"MillerUpdatingRegression": Fixed "ArrayIndexOutOfBounds" exception.
</action>
<action dev="erans" type="fix" issue="MATH-1463"> <action dev="erans" type="fix" issue="MATH-1463">
"IntegerSequence.incrementor": Throw "NoSuchElementException" from "next" method. "IntegerSequence.incrementor": Throw "NoSuchElementException" from "next" method.
</action> </action>

View File

@ -1063,7 +1063,7 @@ public class MillerUpdatingRegression implements UpdatingMultipleLinearRegressio
} }
boolean needsReorder = false; boolean needsReorder = false;
for (int i = 0; i < this.nvars; i++) { for (int i = 0; i < series.length; i++) {
if (this.vorder[i] != series[i]) { if (this.vorder[i] != series[i]) {
needsReorder = true; needsReorder = true;
break; break;

View File

@ -1051,19 +1051,27 @@ public class MillerUpdatingRegressionTest {
} }
@Test private void subsetRegression(int i_exclude, boolean constant){
public void testSubsetRegression() { int[] indices = new int[2];
int j = 0;
MillerUpdatingRegression instance = new MillerUpdatingRegression(3, true); for (int i = 0; i < 3; i++){
MillerUpdatingRegression redRegression = new MillerUpdatingRegression(2, true); if (i != i_exclude){
indices[j] = i;
j++;
}
}
int i0 = indices[0];
int i1 = indices[1];
MillerUpdatingRegression instance = new MillerUpdatingRegression(3, constant);
MillerUpdatingRegression redRegression = new MillerUpdatingRegression(2, constant);
double[][] x = new double[airdata[0].length][]; double[][] x = new double[airdata[0].length][];
double[][] xReduced = new double[airdata[0].length][]; double[][] xReduced = new double[airdata[0].length][];
double[] y = new double[airdata[0].length]; double[] y = new double[airdata[0].length];
for (int i = 0; i < airdata[0].length; i++) { for (int i = 0; i < airdata[0].length; i++) {
x[i] = new double[3]; x[i] = new double[3];
x[i][0] = FastMath.log(airdata[3][i]); x[i][i0] = FastMath.log(airdata[3][i]);
x[i][1] = FastMath.log(airdata[4][i]); x[i][i1] = FastMath.log(airdata[4][i]);
x[i][2] = airdata[5][i]; x[i][i_exclude] = airdata[5][i];
xReduced[i] = new double[2]; xReduced[i] = new double[2];
xReduced[i][0] = FastMath.log(airdata[3][i]); xReduced[i][0] = FastMath.log(airdata[3][i]);
@ -1075,7 +1083,17 @@ public class MillerUpdatingRegressionTest {
instance.addObservations(x, y); instance.addObservations(x, y);
redRegression.addObservations(xReduced, y); redRegression.addObservations(xReduced, y);
RegressionResults resultsInstance = instance.regress( new int[]{0,1,2} ); int includedIndices[];
if (constant){
includedIndices = new int[3];
includedIndices[0] = 0;
includedIndices[1] = i0 + 1;
includedIndices[2] = i1 + 1;
} else {
includedIndices = indices;
}
RegressionResults resultsInstance = instance.regress( includedIndices );
RegressionResults resultsReduced = redRegression.regress(); RegressionResults resultsReduced = redRegression.regress();
TestUtils.assertEquals(resultsInstance.getParameterEstimates(), resultsReduced.getParameterEstimates(), 1.0e-12); TestUtils.assertEquals(resultsInstance.getParameterEstimates(), resultsReduced.getParameterEstimates(), 1.0e-12);
@ -1083,4 +1101,13 @@ public class MillerUpdatingRegressionTest {
} }
@Test
public void testSubsetRegression() {
for (int i=0; i < 3; i++){
subsetRegression(i, true);
subsetRegression(i, false);
}
}
} }