Package edu.umd.cloud9.io.map

Examples of edu.umd.cloud9.io.map.Int2FloatOpenHashMapWritable


  public void testUpdate() {
    int size = 100000;
    Random r = new Random();
    float[] floats = new float[size];

    Int2FloatMap map = new Int2FloatOpenHashMapWritable();
    for (int i = 0; i < size; i++) {
      float k = r.nextFloat() * size;
      map.put(i, k);
      floats[i] = k;
    }

    assertEquals(size, map.size());

    for (int i = 0; i < size; i++) {
      map.put(i, floats[i] + 1.0f);
    }

    assertEquals(size, map.size());

    for (int i = 0; i < size; i++) {
      assertEquals(floats[i] + 1.0f, map.get(i), 10e-6);
      assertTrue(map.containsKey(i));
    }

  }
View Full Code Here


  }

  @Test
  public void testPlus() throws IOException {
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(1, 5.0f);
    m1.put(2, 22.0f);

    Int2FloatOpenHashMapWritable m2 = new Int2FloatOpenHashMapWritable();

    m2.put(1, 4.0f);
    m2.put(3, 5.0f);

    m1.plus(m2);

    assertEquals(3, m1.size(), 3);
    assertEquals(9.0f, m1.get(1), 10e-6);
View Full Code Here

    assertEquals(5.0f, m1.get(3), 10e-6);
  }

  @Test
  public void testLazyPlus() throws IOException {
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(1, 5.0f);
    m1.put(2, 22.0f);

    Int2FloatOpenHashMapWritable m2 = new Int2FloatOpenHashMapWritable();

    m2.put(1, 4.0f);
    m2.put(3, 5.0f);

    Int2FloatOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2FloatOpenHashMapWritable m3 = Int2FloatOpenHashMapWritable.create(m2.serialize());

    assertEquals(0, m3.size());

    m1.lazyplus(m3);

    assertEquals(3, m1.size(), 3);
    assertEquals(9.0f, m1.get(1), 10e-6);
View Full Code Here

    assertEquals(5.0f, m1.get(3), 10e-6);
  }

  @Test
  public void testDot() throws IOException {
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(1, 2.0f);
    m1.put(2, 1.0f);
    m1.put(3, 3.0f);

    Int2FloatOpenHashMapWritable m2 = new Int2FloatOpenHashMapWritable();

    m2.put(1, 1.0f);
    m2.put(2, 4.0f);
    m2.put(4, 5.0f);

    float s = m1.dot(m2);

    assertEquals(6.0f, s, 10e-6);
  }
View Full Code Here

    assertEquals(6.0f, s, 10e-6);
  }

  @Test
  public void testSortedEntries1() {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

    m.put(1, 5.0f);
    m.put(2, 2.0f);
    m.put(3, 3.0f);
    m.put(4, 3.0f);
    m.put(5, 1.0f);

    Int2FloatMap.Entry[] e = m.getEntriesSortedByValue();
    assertEquals(5, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5.0f, e[0].getFloatValue(), 10e-6);
View Full Code Here

    assertEquals(1.0f, e[4].getFloatValue(), 10e-6);
  }

  @Test
  public void testSortedEntries2() {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

    m.put(1, 5.0f);
    m.put(2, 2.0f);
    m.put(3, 3.0f);
    m.put(4, 3.0f);
    m.put(5, 1.0f);

    Int2FloatMap.Entry[] e = m.getEntriesSortedByValue(2);

    assertEquals(2, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5.0f, e[0].getFloatValue(), 10e-6);
View Full Code Here

    assertEquals(3.0f, e[1].getFloatValue(), 10e-6);
  }

  @Test
  public void testSortedEntries3() {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

    m.put(1, 5.0f);
    m.put(2, 2.0f);

    Int2FloatMap.Entry[] e = m.getEntriesSortedByValue(5);

    assertEquals(2, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5.0f, e[0].getFloatValue(), 10e-6);
View Full Code Here

    assertEquals(2.0f, e[1].getFloatValue(), 10e-6);
  }

  @Test
  public void testSortedEntries4() {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

    Int2FloatMap.Entry[] e = m.getEntriesSortedByValue();
    assertTrue(e == null);
  }
View Full Code Here

      return null;
    }
    PriorityQueue<PairOfFloatInt> eS = f2eProbs.get(f).getTranslationsWithProbs(lexProbThreshold);

    if (!eS.isEmpty()) {
      PairOfFloatInt entry = eS.poll();
      int e = entry.getRightElement();
      String eTerm = eVocab_f2e.get(e);
      return eTerm;
    }
    return token;
  }
View Full Code Here

    float sumProbEF = 0;
    int numTrans = 0;
    //tf(e) = sum_f{tf(f)*prob(e|f)}
    while (numTrans < numTransPerToken && !eS.isEmpty()) {
      PairOfFloatInt entry = eS.poll();
      float probEF = entry.getLeftElement();
      int e = entry.getRightElement();
      String eTerm = eVocab_f2e.get(e);

      //      LOG.info("Pr("+eTerm+"|"+token+")="+probEF);

      if (probEF > 0 && e > 0 && !docLangTokenizer.isStopWord(eTerm) && (translateOnly == null || !translateOnly.equals("indri") || indriPuncPattern.matcher(eTerm).matches()) && (pairsInSCFG == null || pairsInSCFG.contains(new PairOfStrings(token,eTerm)))) {     
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.io.map.Int2FloatOpenHashMapWritable

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.