Package edu.umd.cloud9.io.map

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


      sLogger = logger;
    }

    //sLogger.setLevel(Level.DEBUG);

    HMapSFW v = new HMapSFW();
    float normalization=0;
    for(int e : tfTable.keySet()){
      // retrieve term string, tf and df
      String eTerm = eVocab.get(e);
      float tf = tfTable.get(e);
      float df = dfTable.get(e);

      // compute score via scoring model
      float score = ((Bm25) scoringModel).computeDocumentWeight(tf, df, docLen);

      sLogger.debug(eTerm+" "+tf+" "+df+" "+score);
      if(score>0){
        v.put(eTerm, score);
        if(isNormalize){
          normalization+=Math.pow(score, 2);
        }   
      }
    }

    // length-normalize doc vector
    if(isNormalize){
      normalization = (float) Math.sqrt(normalization);
      for(Entry<String> e : v.entrySet()){
        v.put(e.getKey(), e.getValue()/normalization);
      }
    }
    return v;
  }
View Full Code Here


      sLogger = logger;
    }

    //sLogger.setLevel(Level.DEBUG);

    HMapSFW v = new HMapSFW();
    float normalization=0;
    for(int e : tfTable.keySet()){
      // retrieve term string, tf and df
      String eTerm = eVocab.get(e);
      float tf = tfTable.get(e);
      float df = dfTable.get(eTerm);

      // compute score via scoring model
      float score = ((Bm25) scoringModel).computeDocumentWeight(tf, df, docLen);

      sLogger.debug(eTerm+" "+tf+" "+df+" "+score);
      if(score>0){
        v.put(eTerm, score);
        if(isNormalize){
          normalization+=Math.pow(score, 2);
        }  
      }
    }

    // length-normalize doc vector
    if(isNormalize){
      normalization = (float) Math.sqrt(normalization);
      for(Entry<String> e : v.entrySet()){
        v.put(e.getKey(), e.getValue()/normalization);
      }
    }
    return v;
  }
View Full Code Here

    Map<String,HMapSFW> scfgDist = new HashMap<String,HMapSFW>();

    // phrase2count table is a set of (source_phrase --> X) maps, where X is a set of (phrase_trans --> count) maps
    HMapSFW phraseDist = new HMapSFW();

    HMapSIW srcTokenCnt = new HMapSIW();

    Set<String> bagOfTargetTokens = new HashSet<String>();

    try {
      FSDataInputStream fis = fs.open(new Path(grammarFile));
View Full Code Here

public class Int2FloatOpenHashMapWritableTest {

  @Test
  public void testBasic() throws IOException {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

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

    float value;

    assertEquals(2, m.size());

    value = m.get(2);
    assertEquals(5.0f, value, 10e-6);

    value = m.remove(2);
    assertEquals(1, m.size());

    value = m.get(1);
    assertEquals(22.0f, value, 10e-6);
  }
View Full Code Here

    assertEquals(22.0f, value, 10e-6);
  }

  @Test
  public void testIncrement() throws IOException {
    Int2FloatOpenHashMapWritable m = new Int2FloatOpenHashMapWritable();

    m.put(2, 7.0f);
    m.put(1, 29.0f);

    assertEquals(7, m.get(2), 10e-6);
    assertEquals(29, m.get(1), 10e-6);

    m.increment(2);
    m.increment(1);
    m.increment(3);

    assertEquals(8, m.get(2), 10e-6);
    assertEquals(30, m.get(1), 10e-6);
    assertEquals(1, m.get(3), 10e-6);

    m.increment(1, 3.0f);
    m.increment(3, 5.0f);

    assertEquals(8, m.get(2), 10e-6);
    assertEquals(33, m.get(1), 10e-6);
    assertEquals(6, m.get(3), 10e-6);
  }
View Full Code Here

  }

  @Test
  public void testSerialize1() throws IOException {
    Int2FloatOpenHashMapWritable.setLazyDecodeFlag(false);
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    Int2FloatOpenHashMapWritable n2 = Int2FloatOpenHashMapWritable.create(m1.serialize());

    float value;

    assertEquals(2, n2.size());

    value = n2.get(3);
    assertEquals(5.0f, value, 10e-6);

    value = n2.remove(3);
    assertEquals(1, n2.size());

    value = n2.get(4);
    assertEquals(22.0f, value, 10e-6);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy1() throws IOException {
    Int2FloatOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(3, 5);
    m1.put(4, 22);

    Int2FloatOpenHashMapWritable m2 = Int2FloatOpenHashMapWritable.create(m1.serialize());

    assertEquals(0, m2.size());
    assertFalse(m2.hasBeenDecoded());

    int[] keys = m2.getKeys();
    float[] values = m2.getValues();

    assertEquals(3, keys[0]);
    assertEquals(4, keys[1]);

    assertEquals(5.0f, values[0], 10e-6);
    assertEquals(22.0f, values[1], 10e-6);

    m2.decode();
    assertTrue(m2.hasBeenDecoded());

    float value;
    assertEquals(2, m2.size());

    value = m2.get(3);
    assertEquals(5.0f, value, 10e-6);

    value = m2.remove(3);
    assertEquals(1, m2.size());

    value = m2.get(4);
    assertEquals(22.0f, value, 10e-6);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy2() throws IOException {
    Int2FloatOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2FloatOpenHashMapWritable m1 = new Int2FloatOpenHashMapWritable();

    m1.put(3, 5);
    m1.put(4, 22);

    // Object m2 should not have been decoded, size lazy decode flag is
    // true.
    Int2FloatOpenHashMapWritable m2 = Int2FloatOpenHashMapWritable.create(m1.serialize());

    // Even though m2 hasn't be decoded, we should be able to properly
    // serialize it.
    Int2FloatOpenHashMapWritable m3 = Int2FloatOpenHashMapWritable.create(m2.serialize());

    assertEquals(0, m3.size());
    assertFalse(m3.hasBeenDecoded());

    int[] keys = m3.getKeys();
    float[] values = m3.getValues();

    assertEquals(3, keys[0]);
    assertEquals(4, keys[1]);

    assertEquals(5.0f, values[0], 10e-6);
    assertEquals(22.0f, values[1], 10e-6);

    m3.decode();
    assertTrue(m3.hasBeenDecoded());

    float value;
    assertEquals(2, m3.size());

    value = m3.get(3);
    assertEquals(5.0f, value, 10e-6);

    value = m3.remove(3);
    assertEquals(1, m3.size());

    value = m3.get(4);
    assertEquals(22.0f, value, 10e-6);
  }
View Full Code Here

    assertEquals(22.0f, value, 10e-6);
  }

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

    // Make sure this does nothing.
    m1.decode();

    assertEquals(0, m1.size());

    Int2FloatMap m2 = Int2FloatOpenHashMapWritable.create(m1.serialize());

    assertEquals(0, m2.size());
  }
View Full Code Here

  public void testBasic1() {
    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;
    }

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

  }
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.