@Override public void update() { update(unfilteredVariable.getDoubleValue()); }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout=60000) public void testAlphaAndBreakFrequencyComputations() { double DT = 0.1; double randomAlpha = random.nextDouble(); double computedBreakFrequency = AlphaFilteredWrappingYoVariable.computeBreakFrequencyGivenAlpha(randomAlpha, DT); double computedAlpha = AlphaFilteredWrappingYoVariable.computeAlphaGivenBreakFrequencyProperly(computedBreakFrequency, DT); assertEquals(randomAlpha, computedAlpha, 1e-7); assertEquals(computedBreakFrequency, AlphaFilteredWrappingYoVariable.computeBreakFrequencyGivenAlpha(computedAlpha, DT), 1e-7); if(DEBUG) { System.out.println("Random Alpha: " + randomAlpha); System.out.println("Computed Alpha: " + AlphaFilteredWrappingYoVariable.computeAlphaGivenBreakFrequencyProperly(computedBreakFrequency, DT)); } } }
AlphaFilteredWrappingYoVariable alphaFilteredWrappingYoVariable = new AlphaFilteredWrappingYoVariable("alphaFilteredWrappingYoVariable", "", registry, positionVariable, alpha, -2.0, 8.0); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), -2.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), -2.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), 3.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), -2.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), 2.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), -2.0, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), 6.5, 1e-10)); alphaFilteredWrappingYoVariable.update(); assertTrue(MathTools.epsilonEquals(alphaFilteredWrappingYoVariable.getDoubleValue(), -2.0, 1e-10));
unfilteredVariableModulo(currentPosition); set(unfilteredInRangeVariable.getDoubleValue()); unfilteredVariableModulo(currentPosition); double standardError = unfilteredInRangeVariable.getDoubleValue() - getDoubleValue(); double wrappingError; if(unfilteredInRangeVariable.getDoubleValue() > getDoubleValue()) wrappingError = lowerLimit - getDoubleValue() + unfilteredInRangeVariable.getDoubleValue() - upperLimit; wrappingError = upperLimit - getDoubleValue() + unfilteredInRangeVariable.getDoubleValue() - lowerLimit; temporaryOutputVariable.set(getDoubleValue()); if ((getDoubleValue() + error.getDoubleValue()) >= upperLimit) temporaryOutputVariable.set(getDoubleValue() - range); if ((getDoubleValue() + error.getDoubleValue()) < lowerLimit) temporaryOutputVariable.set(getDoubleValue() + range); set(temporaryOutputVariable.getDoubleValue() - range); set(temporaryOutputVariable.getDoubleValue() + range); set(temporaryOutputVariable.getDoubleValue());
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout=60000) public void testNoisyFixedPosition() { // Use a reasonably large alpha for a reasonably large amount of noise YoVariableRegistry registry = new YoVariableRegistry("testRegistry"); YoDouble alpha = new YoDouble("alpha", registry); alpha.set(0.8); YoDouble positionVariable = new YoDouble("positionVariable", registry); AlphaFilteredWrappingYoVariable alphaFilteredWrappingYoVariable = new AlphaFilteredWrappingYoVariable("alphaFilteredWrappingYoVariable", "", registry, positionVariable, alpha, 0.0, 20.0); double pseudoNoise = 0; positionVariable.set(10.0); for (int i = 0; i < 10000; i++) { // Oscillate the position about some uniformly distributed fixed point slightly larger than 10 if (i % 2 == 0) { pseudoNoise = random.nextDouble(); } positionVariable.add(Math.pow(-1, i) * pseudoNoise); alphaFilteredWrappingYoVariable.update(); } assertEquals(10.0, alphaFilteredWrappingYoVariable.getDoubleValue(), 1.0); }
unfilteredVariableModulo(currentPosition); set(unfilteredInRangeVariable.getDoubleValue()); unfilteredVariableModulo(currentPosition); double standardError = unfilteredInRangeVariable.getDoubleValue() - getDoubleValue(); double wrappingError; if(unfilteredInRangeVariable.getDoubleValue() > getDoubleValue()) wrappingError = lowerLimit - getDoubleValue() + unfilteredInRangeVariable.getDoubleValue() - upperLimit; wrappingError = upperLimit - getDoubleValue() + unfilteredInRangeVariable.getDoubleValue() - lowerLimit; temporaryOutputVariable.set(getDoubleValue()); if ((getDoubleValue() + error.getDoubleValue()) >= upperLimit) temporaryOutputVariable.set(getDoubleValue() - range); if ((getDoubleValue() + error.getDoubleValue()) < lowerLimit) temporaryOutputVariable.set(getDoubleValue() + range); set(temporaryOutputVariable.getDoubleValue() - range); set(temporaryOutputVariable.getDoubleValue() + range); set(temporaryOutputVariable.getDoubleValue());
AlphaFilteredWrappingYoVariable alphaFilteredWrappingYoVariable = new AlphaFilteredWrappingYoVariable("alphaFilteredWrappingYoVariable", "", registry, positionVariable, alpha, lowerLimit, upperLimit); positionVariable.set(RandomNumbers.nextDouble(random, lowerLimit, upperLimit)); alphaFilteredWrappingYoVariable.update(); double lastError = getErrorConsideringWrap(alphaFilteredWrappingYoVariable.getDoubleValue(), positionVariable.getDoubleValue(),lowerLimit, upperLimit); for (int convergeAlphaCount = 0; convergeAlphaCount < 100; convergeAlphaCount++) alphaFilteredWrappingYoVariable.update(); double currentError = getErrorConsideringWrap(alphaFilteredWrappingYoVariable.getDoubleValue(), positionVariable.getDoubleValue(),lowerLimit, upperLimit); assertTrue(Math.abs(currentError) < Math.abs(lastError));
@Override public void update() { update(unfilteredVariable.getDoubleValue()); }