static Address mapLimit(final int units, final int heads) {
   // final int WORD_SIZE = ArchitecturalWord.getModel().bytesInWord();
   final int WORD_SIZE = 4;
   return baseAddress.plus(
       Math.floorDiv(((units + heads + 1) * WORD_SIZE * 2) + (PAGE_SIZE - 1), PAGE_SIZE)
           * PAGE_SIZE);
 }
Example #2
0
  @Test
  public void testInsertInstitucionNoExiste() {
    System.out.println("insertInstitucionExiste");
    Plantel plantel = null;
    PlantelDAO instance = new PlantelDAO();

    plantel = new Plantel();
    CInstitucion institucion = new CInstitucion();
    institucion.setIdCInstitucion((int) (Math.random() * 100));
    institucion.setNombre("No existente " + (int) (Math.random() * 100));
    institucion.setModificadoPor("system");
    institucion.setCreacion(new Date(System.currentTimeMillis()));
    institucion.setUltimaModif(new Date(System.currentTimeMillis()));

    plantel.setNombre("dsadsa 2" + (int) (Math.random() * 1000));
    plantel.setModificadoPor("system");
    plantel.setCreacion(new Date(System.currentTimeMillis()));
    plantel.setUltimaModif(new Date(System.currentTimeMillis()));
    //        plantel.setInstitucion(institucion);
    CInstitucionDAO cInstitucionDAO = new CInstitucionDAO();
    cInstitucionDAO.insert(institucion);

    int expResult = 1;
    // Insertar
    int result = instance.insert(plantel);
    assertEquals(expResult, result);
  }
Example #3
0
 @Test
 public void testBladeCount() {
   assertTrue(tGP4.getBladeCount() == Math.pow(2, 4));
   assertTrue(tGP8.getBladeCount() == Math.pow(2, 8));
   // assertTrue(tGP10.getBladeCount() == Math.pow(2, 10));
   assertTrue(tGP12.getBladeCount() == Math.pow(2, 12));
 }
 int integerBreak(int n) {
   if (n == 2 || n == 3) return n - 1;
   int div = n / 3;
   int reminder = n % 3;
   if (reminder == 1) return (int) Math.pow(3, div - 1) * 4;
   else if (reminder == 0) return (int) Math.pow(3, div);
   return (int) Math.pow(3, div) * 2;
 }
 int integerBreak(int n) {
   int[] dp = new int[n + 1];
   dp[1] = 1;
   for (int i = 2; i <= n; i++) {
     for (int j = 1; 2 * j <= i; j++) {
       dp[i] = Math.max(dp[i], (Math.max(j, dp[j])) * (Math.max(i - j, dp[i - j])));
     }
   }
   return dp[n];
 }
  // Returns are randomly generated email id, part before the domain name
  private String shuffleEmail(String email) {

    String shuffledString = "";

    while (email.length() != 0) {
      int index = (int) Math.floor(Math.random() * email.length());
      char c = email.charAt(index);
      email = email.substring(0, index) + email.substring(index + 1);
      shuffledString += c;
    }

    return shuffledString;
  }
  /** test of iva method of class CalculateIva */
  @Test
  public void testCalculateIva() {
    CalculateIva calculateIva = Mockito.mock(CalculateIva.class);
    Purchase p = BillingCalculator.calculateTotalPurchase(customer, "EL-003,FU-001");

    when(CalculateIva.iva(p.getCode())).thenReturn(new BigDecimal(Math.random() * 0.05));
  }
  private static double checkXorFitness(Function xorAttempt, int waveCount)
      throws CloneNotSupportedException {
    if (waveCount <= 0) throw new IllegalArgumentException("waveCount must be >0");

    // testing against xor at 4 points only (0,0 0,1 1,0 1,1)
    xorAttempt.setParameter(0, 0.0);
    xorAttempt.setParameter(1, 0.0);
    final double result00 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 1.0);
    xorAttempt.setParameter(1, 0.0);
    final double result10 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 0.0);
    xorAttempt.setParameter(1, 1.0);
    final double result01 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 1.0);
    xorAttempt.setParameter(1, 1.0);
    final double result11 = xorAttempt.calculate();

    // calculates the whole number portion of the fitness, should be between -4 and +4
    final int fitnessWhole =
        (result00 < 0.0 ? 1 : 0)
            + (result10 > 0.0 ? 1 : 0)
            + (result01 > 0.0 ? 1 : 0)
            + (result11 < 0.0 ? 1 : 0);

    // calculates the decimal portion of the fitness , should be >= 0 and < 1
    final double fitnessFine = 1.0 - Math.tanh(waveCount);

    return ((double) fitnessWhole) + fitnessFine;
  }
 @Test
 public void testConstructors() {
   ValueGene test = new DoubleValueGene(93947810231.0);
   Assert.assertTrue(
       "value constructor failed",
       Math.abs(test.getValue().getNumber().doubleValue() - 93947810231.0) < 1000);
   test = new DoubleValueGene(new MutableDouble(20237420342.0));
   Assert.assertTrue(
       "MutableDouble value constructor failed",
       Math.abs(test.getValue().getNumber().doubleValue() - 20237420342.0) < 1000);
   test = new DoubleValueGene(82649173937.0);
   Assert.assertTrue(
       "Number value constructor failed",
       Math.abs(test.getValue().getNumber().doubleValue() - 82649173937.0) < 1000);
   test = new DoubleValueGene();
   Assert.assertTrue(
       "default constructor failed", test.getValue().getNumber().doubleValue() == 0.0);
 }
Example #10
0
 protected boolean sufficientlyEqual(Object value1, Object value2) {
   if (value1 == null) return value2 == null;
   if (value1 instanceof Date && value2 instanceof Date) {
     // for dynamic dates.
     return Math.abs(((Date) value1).getTime() - ((Date) value2).getTime()) < 200L;
   } else {
     return value1.equals(value2);
   }
 }
  @Test
  public void testSquareRoot() {
    final double DELTA = 1e-15;
    a = 0;
    double result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 1;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 25;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 1544646;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);
  }
Example #12
0
 private void testRecoveryWithBadMessageSize(List<Record> records, int size) throws IOException {
   LogSegment seg = this.store.log().lastSegment();
   writeToOffset(seg.file(), seg.file().length(), ByteBuffer.allocate(4).putInt(size).array());
   // now add some message bytes, but not enough
   if (size > 0)
     writeToOffset(
         seg.file(), seg.file().length(), ByteBuffer.allocate(Math.min(size - 1, 256)).array());
   this.store.close();
   this.store = new HashStore(config);
   assertEquals("Same records should be present after close and re-open", records, records(store));
 }
  @Test
  public void testDistanceEuclidienne3() throws DataFormatException {
    List<Double> variables = new LinkedList<Double>();
    for (double d : p.getVariables()) variables.add(d + 1);

    InfinitePoint Point = new InfinitePoint(variables);

    assertTrue(
        p.distanceEuclidienne(Point) - Math.sqrt(Point.getDimension())
            < InfinitePoint.getEpsilon());
  }
Example #14
0
  @Test
  public void testProductResult() {
    int tS = (int) Math.pow(2, 12);
    int tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP12.getBladeCount(); k++) {
      short[] tSpot = tGP12.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }

    tS = (int) Math.pow(2, 8);
    tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP8.getBladeCount(); k++) {
      short[] tSpot = tGP8.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }

    tS = (int) Math.pow(2, 4);
    tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP4.getBladeCount(); k++) {
      short[] tSpot = tGP4.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }
  }
Example #15
0
  @Test
  public void test_inflate_impl() {
    for (int l = 0; l < 2; ++l) {
      NewChunk nc = new NewChunk(null, 0);

      // -32.767, 0.34, 0, 32.767, NA for l==0
      // NA, -32.767, 0.34, 0, 32.767, NA for l==1
      long[] man = new long[] {-32767, 34, 0, 32767};
      int[] exp = new int[] {-3, -2, 1, -3};
      if (l == 1) nc.addNA(); // -32768
      for (int i = 0; i < man.length; ++i) nc.addNum(man[i], exp[i]);
      nc.addNA();

      Chunk cc = nc.compress();
      Assert.assertEquals(man.length + 1 + l, cc.len());
      Assert.assertTrue(cc instanceof C2SChunk);
      if (l == 1) {
        Assert.assertTrue(cc.isNA0(0));
        Assert.assertTrue(cc.isNA(0));
      }
      for (int i = 0; i < man.length; ++i) {
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc.at0(l + i), 0);
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc.at(l + i), 0);
      }
      Assert.assertTrue(cc.isNA0(man.length + l));
      Assert.assertTrue(cc.isNA(man.length + l));

      nc = cc.inflate_impl(new NewChunk(null, 0));
      nc.values(0, nc.len());
      Assert.assertEquals(man.length + 1 + l, nc.len());
      Assert.assertEquals(man.length + 1 + l, nc.sparseLen());
      if (l == 1) {
        Assert.assertTrue(nc.isNA0(0));
        Assert.assertTrue(nc.isNA(0));
      }
      for (int i = 0; i < man.length; ++i) {
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) nc.at0(l + i), 0);
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) nc.at(l + i), 0);
      }
      Assert.assertTrue(nc.isNA0(man.length + l));
      Assert.assertTrue(nc.isNA(man.length + l));

      Chunk cc2 = nc.compress();
      Assert.assertEquals(man.length + 1 + l, cc.len());
      if (l == 1) {
        Assert.assertTrue(cc2.isNA0(0));
        Assert.assertTrue(cc2.isNA(0));
      }
      for (int i = 0; i < man.length; ++i) {
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc2.at0(l + i), 0);
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc2.at(l + i), 0);
      }
      Assert.assertTrue(cc2.isNA0(man.length + l));
      Assert.assertTrue(cc2.isNA(man.length + l));
      Assert.assertTrue(cc2 instanceof C2SChunk);

      Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    }
  }
 @Test
 public void calculateDiscountPoints() {
   String productsFlatFile = "EL-002,FU-007,FU-008";
   Purchase result = null;
   result = BillingCalculator.calculateTotalPurchase(customer, productsFlatFile);
   Customer client = Mockito.mock(Customer.class);
   client = result.getCustomer();
   when(client.calculateDiscountPoints())
       .thenReturn(result.getTotalPrice().multiply(new BigDecimal(Math.random() * 0.02)));
   when(client.discountPoints()).thenReturn(true);
   if ((client.getPoints().intValue()) > 1000) {
     client.discountPoints();
   }
 }
  @Test
  public void testscaleValues() {

    LinkedList<Double> variables = new LinkedList<Double>();
    double scale = 2;
    for (double d : p.getVariables()) variables.add(d);

    p.scale(scale);
    boolean equals = (p.getVariables().size() == variables.size());
    for (int i = 0; i < p.getVariables().size(); i++)
      equals =
          equals
              && (Math.abs(p.getVariables().get(i) - variables.get(i))
                  < InfinitePoint.getEpsilon());
  }
Example #18
0
  @Test
  public void test() {
    Frame frame = null;
    try {
      Futures fs = new Futures();
      Random random = new Random();
      Vec[] vecs = new Vec[1];
      AppendableVec vec = new AppendableVec(Vec.newKey(), Vec.T_NUM);
      for (int i = 0; i < 2; i++) {
        NewChunk chunk = new NewChunk(vec, i);
        for (int r = 0; r < 1000; r++) chunk.addNum(random.nextInt(1000));
        chunk.close(i, fs);
      }
      vecs[0] = vec.layout_and_close(fs);
      fs.blockForPending();
      frame = new Frame(Key.<Frame>make(), null, vecs);

      // Make sure we test the multi-chunk case
      vecs = frame.vecs();
      assert vecs[0].nChunks() > 1;
      long rows = frame.numRows();
      Vec v = vecs[0];
      double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY, mean = 0, sigma = 0;
      for (int r = 0; r < rows; r++) {
        double d = v.at(r);
        if (d < min) min = d;
        if (d > max) max = d;
        mean += d;
      }
      mean /= rows;
      for (int r = 0; r < rows; r++) {
        double d = v.at(r);
        sigma += (d - mean) * (d - mean);
      }
      sigma = Math.sqrt(sigma / (rows - 1));

      double epsilon = 1e-9;
      assertEquals(max, v.max(), epsilon);
      assertEquals(min, v.min(), epsilon);
      assertEquals(mean, v.mean(), epsilon);
      assertEquals(sigma, v.sigma(), epsilon);
    } finally {
      if (frame != null) frame.delete();
    }
  }
Example #19
0
  /** Test of getVariance method, of class GeneralDiscrete. */
  @Test
  public void testnoise() {
    System.out.println("test noise");
    Map<Integer, Double> pdf = new HashMap<Integer, Double>(2);
    pdf.put(1, 0.7);
    pdf.put(3, 0.3);
    GeneralDiscrete dist = new GeneralDiscrete(pdf);

    int iters = 100000;
    double count1s = 0;
    double count3s = 0;
    for (int i = 0; i < iters; i++) {
      int n = (int) Math.round(dist.getNoise());
      if (n == 1) count1s++;
      else if (n == 3) count3s++;
      else fail("noise returned a value of zero probability!");
    }
    assertEquals(0.7, count1s / iters, 0.01);
    assertEquals(0.3, count3s / iters, 0.01);
  }
  /** Test method for {@link GroupElement#toRadix16(byte[])}. */
  @Test
  public void testToRadix16() {
    assertThat(GroupElement.toRadix16(BYTES_ZERO), is(RADIX16_ZERO));
    assertThat(GroupElement.toRadix16(BYTES_ONE), is(RADIX16_ONE));
    assertThat(GroupElement.toRadix16(BYTES_42), is(RADIX16_42));

    byte[] from1234567890 = GroupElement.toRadix16(BYTES_1234567890);
    int total = 0;
    for (int i = 0; i < from1234567890.length; i++) {
      assertThat(from1234567890[i], is(greaterThanOrEqualTo((byte) -8)));
      assertThat(from1234567890[i], is(lessThanOrEqualTo((byte) 8)));
      total += from1234567890[i] * Math.pow(16, i);
    }
    assertThat(total, is(1234567890));

    byte[] pkrR16 = GroupElement.toRadix16(BYTES_PKR);
    for (int i = 0; i < pkrR16.length; i++) {
      assertThat(pkrR16[i], is(greaterThanOrEqualTo((byte) -8)));
      assertThat(pkrR16[i], is(lessThanOrEqualTo((byte) 8)));
    }
  }
  @Test
  public void testNoise() {
    System.out.println("test noise generator");

    int iters = 100000;
    double mean = 0.2;
    double var = 1.0 / 11.0;
    CircularRandomVariable instance = new WrappedUniform(mean, var);

    double umean = instance.intrinsicMean();
    assertEquals(-0.3, umean, 0.000001);

    double sum = 0;
    double sum2 = 0;
    for (int i = 0; i <= iters; i++) {
      double noise = instance.noise();
      boolean result = noise >= -0.5 && noise < 0.5;
      sum2 += fracpart(noise - umean) * fracpart(noise - umean);
      assertEquals(true, result);
    }

    // test the unwrapped variance
    assertTrue(Math.abs(sum2 / iters - instance.intrinsicVariance()) < 0.01);
  }
Example #22
0
  @Test
  public void test_inflate_impl() {
    final int K = 1 << 16;
    for (Double d :
        new Double[] {
          3.14159265358,
          Double.POSITIVE_INFINITY,
          Double.NEGATIVE_INFINITY,
          Double.MAX_VALUE,
          Double.NaN
        }) {
      NewChunk nc = new NewChunk(null, 0);
      for (int i = 0; i < K; ++i) nc.addNum(d);
      Assert.assertEquals(K, nc.len());
      Assert.assertEquals(K, nc.sparseLen());

      Chunk cc = nc.compress();
      Assert.assertEquals(K, cc.len());
      Assert.assertTrue(cc instanceof C0DChunk);
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, cc.at0(i), Math.ulp(d));
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, cc.at(i), Math.ulp(d));

      nc = cc.inflate_impl(new NewChunk(null, 0));
      nc.values(0, nc.len());
      Assert.assertEquals(K, nc.len());
      Assert.assertEquals(K, nc.sparseLen());
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, nc.at0(i), Math.ulp(d));
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, nc.at(i), Math.ulp(d));

      Chunk cc2 = nc.compress();
      Assert.assertEquals(K, cc2.len());
      Assert.assertTrue(cc2 instanceof C0DChunk);
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, cc2.at0(i), Math.ulp(d));
      for (int i = 0; i < K; ++i) Assert.assertEquals(d, cc2.at(i), Math.ulp(d));

      Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    }
  }
Example #23
0
  /**
   * Test to make sure that chunking does not change the results.
   *
   * @throws ClassNotFoundException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  @Test
  public void testNoCache()
      throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    ProblemSet ps =
        new ProblemSet(
            Paths.get(JSANConstants.JSAN_PROBLEMSETS_PREFIX, "drexel_1_small.xml").toString());
    Document d = ps.trainDocAt("a", "a_01.txt");
    Assert.assertNotNull("No document a_01.txt found.", d);
    ps.removeTrainDocAt("a", d);
    ps.addTestDoc("a", d);
    Path path =
        Paths.get(JSANConstants.JSAN_FEATURESETS_PREFIX, "writeprints_feature_set_limited.xml");
    FullAPI test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .useCache(false)
            .build();
    long bef1 = System.currentTimeMillis();
    test.prepareInstances();
    test.run();
    long aft1 = System.currentTimeMillis();
    String results1 = test.getStatString();
    System.out.println(results1);

    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .useCache(false)
            .build();
    long bef2 = System.currentTimeMillis();
    test.prepareInstances();
    test.run();
    long aft2 = System.currentTimeMillis();
    String results2 = test.getStatString();
    System.out.println(results2);

    long time1 = aft1 - bef1;
    long time2 = aft2 - bef2;

    // This assertion may be too lenient. Just trying to make sure that the time it takes the
    // second time is close to the time it takes the first time (in other words, so we know for sure
    // it did not use any extracted features)
    double percentDiff = (double) (Math.abs(time1 - time2)) / time2;
    System.out.println("Percent difference between two runs: " + percentDiff);

    File cache = Paths.get(JSANConstants.JSAN_CACHE).toFile();
    File[] contents = cache.listFiles();
    Assert.assertNotNull("No files in cache. Chunking directory should be there.", contents);
    boolean foundChunkingDirectory = false;
    for (File f : contents) {
      if (f.isDirectory() && f.getName().equals(CacheTests.CHUNKED_DIR_NAME))
        foundChunkingDirectory = true;
      else {
        Assert.fail("The caching system made directories/files when caching was turned off.");
      }
    }
    Assert.assertTrue(
        "Chunking was turned on, but no chunking directory was found.", foundChunkingDirectory);
  }
  public static int randomNumber() {

    return (int) (Math.random() * 10) + 0;
  }
  /**
   * Run the test in the flipped or unflipped case.
   *
   * @param f -1 for the flipped case, or +1 for the unflipped case.
   */
  private static void runTest(final int f) {
    // Test identity
    final AffineTransform tr = new AffineTransform();
    tr.setToScale(1, f);
    assertEquals(1, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(1, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(0, XAffineTransform.getRotation(tr), EPS);
    assertEquals(1, XAffineTransform.getSwapXY(tr));
    assertEquals(f, XAffineTransform.getFlip(tr));
    assertEquals(f, getFlipFromType(tr));

    // Tests rotation (< 45°)
    double r = Math.toRadians(25);
    tr.rotate(r);
    assertEquals(1, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(1, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(r, XAffineTransform.getRotation(tr), EPS);
    assertEquals(1, XAffineTransform.getSwapXY(tr));
    assertEquals(f, XAffineTransform.getFlip(tr));
    assertEquals(f, getFlipFromType(tr));

    // Tests more rotation (> 45°)
    r = Math.toRadians(65);
    tr.rotate(Math.toRadians(40));
    assertEquals(1, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(1, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(r, XAffineTransform.getRotation(tr), EPS);
    assertEquals(-1, XAffineTransform.getSwapXY(tr));
    assertEquals(f, XAffineTransform.getFlip(tr));
    assertEquals(f, getFlipFromType(tr));

    // Tests scale
    tr.setToScale(2, 3 * f);
    assertEquals(2, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(3, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(0, XAffineTransform.getRotation(tr), EPS);
    assertEquals(1, XAffineTransform.getSwapXY(tr));
    assertEquals(f, XAffineTransform.getFlip(tr));
    assertEquals(f, getFlipFromType(tr));

    // Tests rotation + scale
    tr.rotate(r);
    assertEquals(2, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(3, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(r, XAffineTransform.getRotation(tr), EPS);
    assertEquals(-1, XAffineTransform.getSwapXY(tr));
    assertEquals(f, XAffineTransform.getFlip(tr));
    assertEquals(1, getFlipFromType(tr)); // Always unflipped according Java 1.5.0_09...

    // Tests axis swapping
    r = Math.toRadians(-90 * f);
    tr.setTransform(0, 1, f, 0, 0, 0);
    assertEquals(1, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(1, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(r, XAffineTransform.getRotation(tr), EPS);
    assertEquals(-1, XAffineTransform.getSwapXY(tr));
    assertEquals(-f, XAffineTransform.getFlip(tr));
    assertEquals(-f, getFlipFromType(tr));

    // Tests axis swapping + scale
    tr.scale(2, 3);
    assertEquals(3, XAffineTransform.getScaleX0(tr), EPS);
    assertEquals(2, XAffineTransform.getScaleY0(tr), EPS);
    assertEquals(r, XAffineTransform.getRotation(tr), EPS);
    assertEquals(-1, XAffineTransform.getSwapXY(tr));
    assertEquals(-f, XAffineTransform.getFlip(tr));
    assertEquals(-f, getFlipFromType(tr));
  }
Example #26
0
 @Test
 public void testCovariance() {
   DataFrame df = context.table("testData2");
   Double result = df.stat().cov("a", "b");
   Assert.assertTrue(Math.abs(result) < 1.0e-6);
 }
Example #27
0
 @Test
 public void testCorrelation() {
   DataFrame df = context.table("testData2");
   Double pearsonCorr = df.stat().corr("a", "b", "pearson");
   Assert.assertTrue(Math.abs(pearsonCorr) < 1.0e-6);
 }
 private String getUniqueId() {
   return Long.toHexString(Double.doubleToLongBits(Math.random()));
 }
Example #29
0
  /**
   * Test to make sure that chunking does not change the results of the cache. It's a long test, but
   * it's very important.
   *
   * @throws ClassNotFoundException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  @Test
  public void testWithChunking()
      throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    // the max difference allowed between chunked / non-chunked.
    double maxDifferential = 0.05;

    ProblemSet ps =
        new ProblemSet(
            Paths.get(JSANConstants.JSAN_PROBLEMSETS_PREFIX, "drexel_1_small.xml").toString());
    Document d = ps.trainDocAt("a", "a_01.txt");
    Assert.assertNotNull("No document a_01.txt found.", d);
    ps.removeTrainDocAt("a", d);
    ps.addTestDoc("a", d);
    Path path =
        Paths.get(JSANConstants.JSAN_FEATURESETS_PREFIX, "writeprints_feature_set_limited.xml");
    FullAPI test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results1 = test.getStatString();
    System.out.println(results1);

    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results2 = test.getStatString();
    System.out.println(results2);

    Assert.assertEquals("Cached results different from non-cached results", results1, results2);

    // make it rechunk, then test to make sure the results are the same.
    deleteRecursive(Paths.get(JSANConstants.JSAN_CHUNK_DIR).toFile(), true);
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results3 = test.getStatString();
    System.out.println(results3);
    Assert.assertEquals("Cached results different from non-cached results", results2, results3);

    // now, keep the chunks, but delete the cache, and try again.
    File cacheDir = Paths.get(JSANConstants.JSAN_CACHE).toFile();
    for (File f : cacheDir.listFiles()) {
      if (f.getName() != "chunked") {
        deleteRecursive(f, true);
      }
    }
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results4 = test.getStatString();
    System.out.println(results4);
    Assert.assertEquals("Cached results different from non-cached results", results3, results4);

    // ----------------------------------------------------------------------------
    // Turn off chunking and make sure the results are the same
    // There is good reason to test to make sure the results for this test are
    // (close to) the same, regardless of whether chunking is on or not.
    // ----------------------------------------------------------------------------
    deleteRecursive(Paths.get(JSANConstants.JSAN_CACHE).toFile(), true);
    Chunker.shouldChunkTrainDocs(false);
    ps =
        new ProblemSet(
            Paths.get(JSANConstants.JSAN_PROBLEMSETS_PREFIX, "drexel_1_small.xml").toString());
    d = ps.trainDocAt("a", "a_01.txt");
    Assert.assertNotNull("No document a_01.txt found.", d);
    ps.removeTrainDocAt("a", d);
    ps.addTestDoc("a", d);
    path = Paths.get(JSANConstants.JSAN_FEATURESETS_PREFIX, "writeprints_feature_set_limited.xml");
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();

    results4 = results4.trim();
    String res4 = results4.substring(results4.lastIndexOf("\n") + 1);
    String[] allRes4 = Pattern.compile("|", Pattern.LITERAL).split(res4);
    String results5 = test.getStatString();
    System.out.println(results5);
    String res5 = results5.trim().substring(results5.trim().lastIndexOf("\n") + 1);
    String[] allRes5 = Pattern.compile("|", Pattern.LITERAL).split(res5);
    for (int i = 1; i < allRes4.length; i++) {
      double num = Double.parseDouble(allRes4[i].trim().replace(" +", ""));
      double num2 = Double.parseDouble(allRes5[i].trim().replace(" +", ""));
      Assert.assertTrue(
          "There was a large difference between results for chunked / non-chunked."
              + " \nChunked: "
              + num
              + "; Non-chunked: "
              + num2,
          (Math.abs((num - num2)) / num2 <= maxDifferential));
    }

    // Changed test to the one above.. since there WILL be differences between chunked/non-chunked,
    // we should just make sure that the difference isn't huge.
    // Assert.assertEquals("Chunked results different from non-chunked results", results4,
    // results5);

    // now do it again with the cache
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results6 = test.getStatString();
    System.out.println(results6);

    Assert.assertEquals("Cached results different from non-cached results", results5, results6);

    // make it rechunk, then test to make sure the results are the same.
    deleteRecursive(Paths.get(JSANConstants.JSAN_CHUNK_DIR).toFile(), true);
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results7 = test.getStatString();
    System.out.println(results7);
    Assert.assertEquals("Cached results different from non-cached results", results6, results7);

    // now, keep the chunks, but delete the cache, and try again.
    for (File f : cacheDir.listFiles()) {
      if (f.getName() != "chunked") {
        deleteRecursive(f, true);
      }
    }
    test =
        new FullAPI.Builder()
            .cfdPath(path.toString())
            .ps(ps)
            .setAnalyzer(
                new WekaAnalyzer(Class.forName("weka.classifiers.functions.SMO").newInstance()))
            .numThreads(4)
            .analysisType(FullAPI.analysisType.TRAIN_TEST_UNKNOWN)
            .build();
    test.prepareInstances();
    test.run();
    String results8 = test.getStatString();
    System.out.println(results8);
    Assert.assertEquals("Cached results different from non-cached results", results7, results8);
  }