Examples of HMapIF


Examples of edu.umd.cloud9.util.map.HMapIF

    assertTrue(m1.get(3) == 5);
  }

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

    m1.put(1, 2.3f);
    m1.put(2, 1.9f);
    m1.put(3, 3.0f);

    HMapIF m2 = new HMapIF();

    m2.put(1, 1.2f);
    m2.put(2, 4.3f);
    m2.put(4, 5.0f);

    float s = m1.dot(m2);

    assertTrue(s == 10.93f);
  }
View Full Code Here

Examples of edu.umd.cloud9.util.map.HMapIF

    assertTrue(s == 10.93f);
  }

  @Test
  public void testLengthAndNormalize() throws IOException {
    HMapIF m1 = new HMapIF();

    m1.put(1, 2.3f);
    m1.put(2, 1.9f);
    m1.put(3, 3.0f);

    assertEquals(m1.length(), 4.2308393, 10E-6);

    m1.normalize();

    assertEquals(m1.get(1), 0.5436274, 10E-6);
    assertEquals(m1.get(2), 0.44908348, 10E-6);
    assertEquals(m1.get(3), 0.70907915, 10E-6);
    assertEquals(m1.length(), 1, 10E-6);

    HMapIF m2 = new HMapIF();

    m2.put(1, 1.2f);
    m2.put(2, 4.3f);
    m2.put(3, 5.0f);

    assertEquals(m2.length(), 6.7029843, 10E-6);

    m2.normalize();

    assertEquals(m2.get(1), 0.17902474, 10E-6);
    assertEquals(m2.get(2), 0.64150536, 10E-6);
    assertEquals(m2.get(3), 0.7459364, 10E-6);
    assertEquals(m2.length(), 1, 10E-6);
  }
View Full Code Here

Examples of edu.umd.cloud9.util.map.HMapIF

    assertEquals(m2.length(), 1, 10E-6);
  }

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

    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);

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

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

Examples of edu.umd.cloud9.util.map.HMapIF

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

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

    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);

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

    assertEquals(2, e.length);

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

Examples of edu.umd.cloud9.util.map.HMapIF

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

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

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

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

    assertEquals(2, e.length);

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

Examples of edu.umd.cloud9.util.map.HMapIF

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

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

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

Examples of edu.umd.cloud9.util.map.HMapIF

    assertTrue(e == null);
  }

  @Test
  public void testIncrement() {
    HMapIF m = new HMapIF();
    assertEquals(0.0f, m.get(1), 10E-6);

    m.increment(1, 0.5f);
    assertEquals(0.5f, m.get(1), 10E-6);

    m.increment(1, 1.0f);
    m.increment(2, 0.0f);
    m.increment(3, -0.5f);

    assertEquals(1.5f, m.get(1), 10E-6);
    assertEquals(0.0f, m.get(2), 10E-6);
    assertEquals(-0.5f, m.get(3), 10E-6);
  }
View Full Code Here

Examples of edu.umd.cloud9.util.map.HMapIF


  public static void addToTable(int curIndex, TreeSet<PairOfFloatString> topTrans, float cumProb, TTable_monolithic_IFAs table, Vocab trgVocab,
      float cumProbThreshold, HookaStats stats) {
    List<Integer> sortedIndices = new ArrayList<Integer>();
    HMapIF index2ProbMap = new HMapIF();

    float sumOfProbs = 0.0f;    //only extract the top K<15 if the mass prob. exceeds MAX_probThreshold
    while(!topTrans.isEmpty() && sumOfProbs < cumProbThreshold){
      PairOfFloatString e = topTrans.pollLast();
      String term = e.getRightElement();
      float pr = e.getLeftElement()/cumProb;    // normalize
      logger.debug(term+"-->"+pr);
      int trgIndex = trgVocab.addOrGet(term);
      sumOfProbs += e.getLeftElement();         // keep track of unnormalized cumulative prob for determining cutoff
      sortedIndices.add(trgIndex);
      index2ProbMap.put(trgIndex, pr);
    }

    // to enable faster access with binary search, we sort entries by vocabulary index.
    Collections.sort(sortedIndices);
    int numEntries = sortedIndices.size();

    // for statistics only
    stats.update(numEntries, sumOfProbs);

    // write translation list to TTable object
    int[] indices = new int[numEntries];
    float[] probs = new float[numEntries];
    int i=0;
    for(int sortedIndex : sortedIndices){
      indices[i]=sortedIndex;
      probs[i]=index2ProbMap.get(sortedIndex);
      i++;
    }     
    table.set(curIndex, new IndexedFloatArray(indices, probs, true));
  }
View Full Code Here

Examples of edu.umd.cloud9.util.map.HMapIF

  public static HMapIF loadIdf(RetrievalEnvironment env, HMapIV<String> parsedQueries)
    throws Exception {
    Preconditions.checkNotNull(env);
    Preconditions.checkNotNull(parsedQueries);

    HMapIF idfs = new HMapIF();

    for(int qid: parsedQueries.keySet()) {
      String[] tokens = env.tokenize(parsedQueries.get(qid));

      if(tokens == null) {
        continue;
      }

      for(String term: tokens) {
        float idf = (float) Math.log((env.getDocumentCount() - env.documentFrequency(term) + 0.5f) /
                                     (env.documentFrequency(term) + 0.5f));
        idfs.put(env.getIdFromTerm(term), idf);
      }
    }

    return idfs;
  }
View Full Code Here

Examples of edu.umd.cloud9.util.map.HMapIF

  public static HMapIF loadCf(RetrievalEnvironment env, String  queryPath)
    throws Exception {
    Preconditions.checkNotNull(env);
    Preconditions.checkNotNull(queryPath);

    HMapIF cfs = new HMapIF();
    HMapIV<String> parsedQueries = QueryUtility.loadQueries(Files.newInputStreamSupplier(new File(queryPath)));

    for(int qid: parsedQueries.keySet()) {
      String[] tokens = env.tokenize(parsedQueries.get(qid));

      if(tokens == null) {
        continue;
      }

      for(String term: tokens) {
        float cf = (float) env.collectionFrequency(term);
        cfs.put(env.getIdFromTerm(term), cf);
      }
    }

    return cfs;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.