package cs437.som.learningrate;

import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class HyperbolicLearningRateFunctionTest {
    private static final double MAXIMUM_DIFFERENCE = 0.0000000000000001;
    private static final int ITERATIONS = 1000;
    private static final double START_RATE = 0.7;
    private static final double END_RATE = 0.1;

    @Test
    public void testLearningRate() throws Exception {
        HyperbolicLearningRateFunction hlrf =
                new HyperbolicLearningRateFunction(START_RATE, END_RATE);
        hlrf.setExpectedIterations(ITERATIONS);
        assertEquals(hlrf.learningRate(0), START_RATE, MAXIMUM_DIFFERENCE);
        assertEquals(hlrf.learningRate(ITERATIONS), END_RATE, MAXIMUM_DIFFERENCE);

        double last = hlrf.learningRate(1);
        for (int i = 2; i < ITERATIONS; i += 10) {
            double current = hlrf.learningRate(i);
            assertTrue(current < last, "Should consistently decay.");
            last = current;
        }

        // todo check against perfect hyperbola
    }
}

@@ -372,17 +372,17 @@
 ATE = 0.
-7
+8
 ;%0A    pr
@@ -420,17 +420,295 @@
 ATE = 0.
-1
+01;%0A%0A    private static final int%5B%5D SAMPLES = %7B0,100,200,500,1000%7D;%0A    private static final double%5B%5D SAMPLE_RESULTS =%0A            %7B0.8, 0.516156, 0.333021, 0.0894427, 0.01%7D;%0A    private static final double%5B%5D SAMPLE_ACCURACY =%0A            %7B1.0e-1, 1.0e-6, 1.0e-6, 1.0e-7, 1.0e-2%7D
 ;%0A%0A    @
@@ -1364,44 +1364,223 @@
  // 
-todo check aga
+Verify the function fits known samples%0A        for (
 in
-s
 t 
-perfect hyperbola
+j = 0; j %3C SAMPLES.length; j++) %7B%0A            assertEquals(hlrf.learningRate(SAMPLES%5Bj%5D), SAMPLE_RESULTS%5Bj%5D,%0A                    SAMPLE_ACCURACY%5Bj%5D);%0A        %7D
 %0A   

Add sample-based testing to HyperbolicLearningRateFunctionTest.