コード例 #1
0
  @Test
  public void testCalcJacobi() {
    final NNffbpAlphaTabFast tab = loadTestNet();

    final double[] nnInput = new double[] {1.0, 3.4, 6.988, 4.4, 7.0, 16.21};

    final NNCalc nnCalc = tab.calcJacobi(nnInput);

    final double[] expNnOutput = new double[] {0.9999546066706964};
    assertEquals(expNnOutput[0], nnCalc.getNnOutput()[0], 1.0e-6);

    final double[][] expJacobiMatrix =
        new double[][] {
          {
            -7.3325278006568306E-6, 3.2639459486171825E-6, 7.527711538784537E-6,
            -8.186466522910375E-6, 9.557482758745628E-6, 1.2507178214659703E-5
          }
        };
    final double[][] jacobiMatrix = nnCalc.getJacobiMatrix();
    for (int i = 0; i < jacobiMatrix.length; i++) {
      for (int j = 0; j < jacobiMatrix[i].length; j++) {
        assertEquals(expJacobiMatrix[i][j], jacobiMatrix[i][j], 1.0e-6);
      }
    }
  }
コード例 #2
0
  @Test
  public void testCalcPerformance() {
    final NNffbpAlphaTabFast tab = loadTestNet();

    final double[] nnInput = new double[] {1.0, 3.4, 6.988, 4.4, 7.0, 16.21};

    final long t1 = System.nanoTime();
    final int N = 100000;
    for (int i = 0; i < N; i++) {
      final double[] doubles = nnInput.clone();
      for (int j = 0; j < doubles.length; j++) {
        doubles[j] += 1.0e-5 * Math.random();
      }
      final double[] nnCalc = tab.calc(doubles);
      assertTrue(nnCalc[0] != 0.0);
    }
    final long t2 = System.nanoTime();
    final double seconds = (t2 - t1) / 1.0e9;
    System.out.println("testCalcPerformance: " + seconds + " seconds");
    assertTrue(seconds < 1.0);
  }
コード例 #3
0
  @SuppressWarnings({"CallToSystemGC"})
  // deactivated this test; it fails sometimes
  public void testCalcJacobiPerformance() {
    final NNffbpAlphaTabFast tab = loadTestNet();

    final double[] nnInput = new double[] {1.0, 3.4, 6.988, 4.4, 7.0, 16.21};
    System.gc(); // call gc in order to prevent garbage collection during performance test
    final long t1 = System.nanoTime();
    final int N = 100000;
    for (int i = 0; i < N; i++) {
      final double[] doubles = nnInput.clone();
      for (int j = 0; j < doubles.length; j++) {
        doubles[j] += 1.0e-5 * Math.random();
      }
      final NNCalc nnCalc = tab.calcJacobi(doubles);
      assertTrue(nnCalc.getNnOutput()[0] != 0.0);
    }
    final long t2 = System.nanoTime();
    final double duration = (t2 - t1) / 1.0e9;
    // using reference time in order to get rid of a constant time the duration is compared to
    System.gc(); // call gc in order to prevent garbage collection during performance test
    final double refTime = getReferenceTime(N);
    assertTrue(duration < refTime);
  }