Package ivory.lsh.data

Examples of ivory.lsh.data.NBitSignature


  @Test
  public void testPermuteBlk() throws IOException {
    PermutationByBlock p = new PermutationByBlock(64);
    int tempD = D;
    D = 64;
    NBitSignature s = getRandomSignature();
    System.out.println(s + "\n========================");

    int cntBits = s.countSetBits();
    System.out.println(s.countSetBits());

    int loopcnt = 0;
    NBitSignature permutedS = new NBitSignature(D);
    while (true) {
      try {
        ArrayListOfIntsWritable a = p.nextPermutation();
        s.perm(a, permutedS);
        System.out.println((loopcnt++) + "\n" + permutedS);
        assertTrue(cntBits == permutedS.countSetBits());
        // System.out.println(permutedS);
      } catch (RuntimeException e) {
        D = tempD;
        return;
      }
View Full Code Here


    }
  }

  @Test
  public void testReadWrite() throws IOException {
    NBitSignature s = getRandomSignature();
    NBitSignature s2 = getRandomSignature();

    FileSystem fs;
    SequenceFile.Writer w;
    Configuration conf = new Configuration();

    fs = FileSystem.get(conf);
    w = SequenceFile.createWriter(fs, conf, new Path(TMP_FILENAME1),
          IntWritable.class, NBitSignature.class);
    w.append(new IntWritable(1), s);
    w.append(new IntWritable(2), s2);
    w.close();

    List<PairOfWritables<WritableComparable, Writable>> listOfKeysPairs =
        SequenceFileUtils.readFile(new Path(TMP_FILENAME1));
    fs.delete(new Path(TMP_FILENAME1), true);

    NBitSignature read1 = (NBitSignature) listOfKeysPairs.get(0).getRightElement();
    NBitSignature read2 = (NBitSignature) listOfKeysPairs.get(1).getRightElement();

    assertTrue(read1.toString().equals(s.toString()));
    assertTrue(read2.toString().equals(s2.toString()));

    // System.out.println(read1.toString());
    // System.out.println(read2.toString());
  }
View Full Code Here

    fs = FileSystem.get(conf);
    w = SequenceFile.createWriter(fs, conf, new Path(TMP_FILENAME1),
          IntWritable.class, NBitSignature.class);
    for (int i = 0; i < 100; i++) {
      NBitSignature s = new NBitSignature(64);
      w.append(new IntWritable(1), s);
    }
    w.close();

    fs.delete(new Path(TMP_FILENAME1), true);
View Full Code Here

    fs.delete(new Path(TMP_FILENAME1), true);
  }

  public void testWrite() throws IOException {
    NBitSignature s = new NBitSignature(1000);

    FileSystem fs;
    SequenceFile.Writer w;
    Configuration conf = new Configuration();
View Full Code Here

  }

  @Test
  public void testBasic() {
    NBitSignature s = new NBitSignature(D);
    s.set(0, true);
    s.set(1, false);
    assertTrue(s.get(0));
    assertTrue(!s.get(1));

    s.set(0, false);
    assertTrue(!s.get(0));
  }
View Full Code Here

  }

  @Test
  public void testHammingDistance() {
    Bits b1 = new Bits("11100011010111101010");// 11000001011100011110001111100000101001011110111111010111101100101111101100110001110000101000011010001000001001111010111001101001100100011100101010111100000110001101001001010000100001111000000110011110001010101110001001001111010111010111100011001111111000110110000010001100111000001010010000110000000010100101110011001110111011110011010001000110110100111000001001111000111110111111100101011000010110000110100101001101000001110001110110010101000101001001000000000110110101001011111010111010101010001010010000111000001100100101110001111111011100001101011101000011110011111111010001001100001100111110000010111110101010000000101100011110011000010100001011101011001111111011011110010011110101000010001110011100111100101000110111010100011111101000100111010111111100001110110001011010110000000011100000001011101100000001100110010100100000011111001110010101111100100100000110010100010011110111001101110010111010001101110110001010000000000101010010011111010110000110110111100101110010100111");
    NBitSignature s1 = new NBitSignature(b1);
    Bits b2 = new Bits("11101111111111110000");// 01110010110000000101011111000000101001011111111000000110011010111100100111110000010010010101001101101000100100010111111101101001000010010101111110111100010110000100100000010101100010001000100110110110001001100100000111000100010111000101101001001011110001110011000000000010100100001011001110100010001100000100100000111110111110101011000101000111111010001000001101011110100001110110110111110100000010011100000100101101000010110001100110110111000001001000011110000100011001010100100011111110101010000100110000100010000000100101110100011111101110101001011001100100010011111011000110101000010101110000101111100100101001011111110110100110011010000111111001001010100111100111000100000000010011000010101110001101011110110000110011010111000110100100000111001111110101011010110110001000111011111010100010011001100110001000110110111100011101011111001111100101000000010000010111011011011101101100100110111010101111010101110010111011101100011111110010110110010010101010000101101000111100010110");
    NBitSignature s2 = new NBitSignature(b2);

    assertTrue(7 == s1.hammingDistance(s2));
    assertTrue(7 == s2.hammingDistance(s1));
  }
View Full Code Here

  }

  public void benchmark() {
    int origD = this.D;
    this.D = 1000;
    NBitSignature s1 = this.getRandomSignature();
    NBitSignature s2 = this.getRandomSignature();
    long time = System.currentTimeMillis();
    int i = 0;
    while (i++ < 15000000) {
      s1.hammingDistance(s2, 400);
    }
View Full Code Here

  }

  @Test
  public void testCompare() {
    Bits b1 = new Bits("01111111111111111111111111111110");
    Signature s1 = new NBitSignature(b1);
    Bits b2 = new Bits("10000000000000000000000000000001");
    Signature s2 = new NBitSignature(b2);

    assertTrue(s1.compareTo(s2) + "", s1.compareTo(s2) < 0);
    assertTrue(s2.compareTo(s1) + "", s2.compareTo(s1) > 0);
    assertTrue(s1.compareTo(s1) + "", s1.compareTo(s1) == 0);
    assertTrue(s2.compareTo(s2) + "", s2.compareTo(s2) == 0);

  }
View Full Code Here

              + "/part-00000"), FileSystem.getLocal(job));
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      signature = new NBitSignature(D);

      if (localFiles.length > 1) {
        dotProductThresholds = new float[D];
        int i = 0;
        try {
View Full Code Here

TOP

Related Classes of ivory.lsh.data.NBitSignature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.