TrendLine[] polys = new TrendLine[5]; polys[0] = new PolyTrendLine(1); noisePoly = new PolyTrendLine(2); final double[] noise_polyys = PolyTrendLine.toPrimitiveFromList(noise_polyyList); final double[] noise_polyxs = PolyTrendLine.toPrimitiveFromList(noise_polyxList); noisePoly.setValues(noise_polyys, noise_polyxs); last_noise = noisePoly.errorVarience(); if (d) Log.d(TAG, "moment Poly list size: " + polyxList.size()); if (polyxList.size() > 1) { final double[] polyys = PolyTrendLine.toPrimitiveFromList(polyyList); final double[] polyxs = PolyTrendLine.toPrimitiveFromList(polyxList);
TrendLine[] polys = new TrendLine[5]; polys[0] = new PolyTrendLine(1); noisePoly = new PolyTrendLine(2); final double[] noise_polyys = PolyTrendLine.toPrimitiveFromList(noise_polyyList); final double[] noise_polyxs = PolyTrendLine.toPrimitiveFromList(noise_polyxList); noisePoly.setValues(noise_polyys, noise_polyxs); last_noise = noisePoly.errorVarience(); if (d) Log.d(TAG, "moment Poly list size: " + polyxList.size()); if (polyxList.size() > 1) { final double[] polyys = PolyTrendLine.toPrimitiveFromList(polyyList); final double[] polyxs = PolyTrendLine.toPrimitiveFromList(polyxList);
Forecast.PolyTrendLine.toPrimitiveFromList(polyxList), Forecast.PolyTrendLine.toPrimitiveFromList(polyyList));
} else { final TrendLine bg_to_raw = new Forecast.PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double all_varience = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance All: " + all_varience); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double this_variance = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance drop: " + i + " = " + JoH.qs(this_variance, 3)); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(lowest_bgs_set), PolyTrendLine.toPrimitiveFromList(lowest_raws_set));
} else { final TrendLine bg_to_raw = new Forecast.PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double all_varience = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance All: " + all_varience); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double this_variance = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance drop: " + i + " = " + JoH.qs(this_variance, 3)); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(lowest_bgs_set), PolyTrendLine.toPrimitiveFromList(lowest_raws_set));
} else { final TrendLine bg_to_raw = new Forecast.PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double all_varience = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance All: " + all_varience); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); final double this_variance = bg_to_raw.errorVarience(); Log.d(TAG, "Error Variance drop: " + i + " = " + JoH.qs(this_variance, 3)); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(lowest_bgs_set), PolyTrendLine.toPrimitiveFromList(lowest_raws_set));
Forecast.PolyTrendLine.toPrimitiveFromList(polyxList), Forecast.PolyTrendLine.toPrimitiveFromList(polyyList));
Forecast.PolyTrendLine.toPrimitiveFromList(polyxList), Forecast.PolyTrendLine.toPrimitiveFromList(polyyList));
} else { final TrendLine bg_to_raw = new PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience()); final double intercept = bg_to_raw.predict(0);
} else { final TrendLine bg_to_raw = new PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience()); final double intercept = bg_to_raw.predict(0);
} else { final TrendLine bg_to_raw = new PolyTrendLine(1); bg_to_raw.setValues(PolyTrendLine.toPrimitiveFromList(bgs), PolyTrendLine.toPrimitiveFromList(raws)); Log.d(TAG, "Error Variance: " + bg_to_raw.errorVarience()); final double intercept = bg_to_raw.predict(0);
@Test public void polyTrendLine_AdvancedForecast_SecondDegree() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); // Data set as y=x^2 trendLine.setValues(new double[]{1, 4, 9, 16}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(5); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(25); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test public void polyTrendLine_SimpleForecast_SecondDegree() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); trendLine.setValues(new double[]{1, 2, 3, 4}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(10); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(10); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test public void polyTrendLine_SimpleForecast() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(1); trendLine.setValues(new double[]{1, 2, 3, 4}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(10); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(10); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test public void polyTrendLine_AdvancedForecast_SecondDegree() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); // Data set as y=x^2 trendLine.setValues(new double[]{1, 4, 9, 16}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(5); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(25); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test public void polyTrendLine_SimpleForecast_SecondDegree() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); trendLine.setValues(new double[]{1, 2, 3, 4}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(10); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(10); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test public void polyTrendLine_SimpleForecast() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(1); trendLine.setValues(new double[]{1, 2, 3, 4}, new double[]{1, 2, 3, 4}); // :: Act double errorVarience = trendLine.errorVarience(); double prediction = trendLine.predict(10); // :: Verify Truth.assertThat(prediction) .isWithin(0.01) .of(10); Truth.assertThat(errorVarience) .isWithin(0.01) .of(0); }
@Test(expected = IllegalArgumentException.class) public void setValuesWithDifferentLengthXandY() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); // :: Act trendLine.setValues(new double[]{1, 2, 3}, new double[]{1, 2}); }
@Test(expected = IllegalArgumentException.class) public void setValuesWithDifferentLengthXandY() { // :: Setup Forecast.PolyTrendLine trendLine = new Forecast.PolyTrendLine(2); // :: Act trendLine.setValues(new double[]{1, 2, 3}, new double[]{1, 2}); }