Package edu.umd.cloud9.util.array

Examples of edu.umd.cloud9.util.array.ArrayListOfShorts


  @Test
  public void testToString2() {
    int size = 10;
    Random r = new Random();

    ArrayListOfShorts list = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
        list.add((short) r.nextInt(Short.MAX_VALUE + 1));
    }

    String out = list.toString();
    for (int i = 0; i < size; i++) {
      short v = list.get(i);

      // Make sure the first 10 elements are printed out.
      assertTrue(out.indexOf(new Short(v).toString()) != -1);
    }

    for (int i = 0; i < size; i++) {
        list.add((short) r.nextInt(Short.MAX_VALUE + 1));
    }

    out = list.toString();
    for (int i = size; i < size+size; i++) {
      short v = list.get(i);

      // Make sure these elements are not printed out.
      assertTrue(out.indexOf(new Short(v).toString()) == -1);
    }
View Full Code Here


  public void testIterable() {
    int size = 1000;
    Random r = new Random();
    short[] shorts = new short[size];

    ArrayListOfShorts list = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
      short k = (short) r.nextInt(size);
      list.add(k);
      shorts[i] = k;
    }

    int i=0;
    for ( Short v : list) {
View Full Code Here

  }

  @Test
  public void testSetSize() {
    ArrayListOfShorts list = new ArrayListOfShorts();

    list.add((short) 5);
    assertEquals(1, list.size);
    assertEquals(5, list.get(0));

    list.setSize(5);
    assertEquals(5, list.size);
    assertEquals(0, list.get(1));
    assertEquals(0, list.get(2));
    assertEquals(0, list.get(3));
    assertEquals(0, list.get(4));

    list.add((short) 12);
    assertEquals(6, list.size);
    assertEquals(12, list.get(5));
  }
View Full Code Here

    assertEquals(6, list.size);
    assertEquals(12, list.get(5));
  }
  @Test
  public void testSort() {
    ArrayListOfShorts a = new ArrayListOfShorts();
    assertEquals(0, a.size());

    a.add((short) 5);
    a.add((short) 6);
    a.add((short) 1);
    a.add((short) 4);
    assertEquals(4, a.size());

    a.sort();
    assertEquals(4, a.size());

    assertEquals(1, a.get(0));
    assertEquals(4, a.get(1));
    assertEquals(5, a.get(2));
    assertEquals(6, a.get(3));
  }
View Full Code Here

    assertEquals(6, a.get(3));
  }

  @Test
  public void testIntersection1() {
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add((short) 5);
    a.add((short) 3);
    a.add((short) 1);

    a.sort();

    ArrayListOfShorts b = new ArrayListOfShorts();
    b.add((short) 0);
    b.add((short) 1);
    b.add((short) 2);
    b.add((short) 3);

    ArrayListOfShorts c = a.intersection(b);

    assertEquals(1, c.get(0));
    assertEquals(3, c.get(1));
    assertEquals(2, c.size());
  }
View Full Code Here

    assertEquals(2, c.size());
  }

  @Test
  public void testIntersection2() {
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add((short) 5);

    ArrayListOfShorts b = new ArrayListOfShorts();
    b.add((short) 0);
    b.add((short) 1);
    b.add((short) 2);
    b.add((short) 3);

    ArrayListOfShorts c = a.intersection(b);
    assertTrue(c.size() == 0);
  }
View Full Code Here

    assertTrue(c.size() == 0);
  }

  @Test
  public void testIntersection3() {
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add((short) 3);
    a.add((short) 5);
    a.add((short) 7);
    a.add((short) 8);
    a.add((short) 9);

    ArrayListOfShorts b = new ArrayListOfShorts();
    b.add((short) 0);
    b.add((short) 1);
    b.add((short) 2);
    b.add((short) 3);

    ArrayListOfShorts c = a.intersection(b);

    assertEquals(3, c.get(0));
    assertEquals(1, c.size());
  }
View Full Code Here


  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

    DocumentVectorSlidingWindow generator = new DocumentVectorSlidingWindow(env, fs);

    //Parse queries, judgemnts and features
    HMapIV<String> parsedQueries = QueryUtility.loadQueries(queryPath);
    HMapIV<int[]> queries = QueryUtility.queryToIntegerCode(env, parsedQueries);
    HMapIF idfs = QueryUtility.loadIdf(env, parsedQueries);
    HMapIF cfs = QueryUtility.loadCf(env, parsedQueries);
    HMapIV<int[]> qrels = QrelUtility.parseQrelsFromTabDelimited(qrelPath);
    Map<String, Feature> featuresMap = FeatureUtility.parseFeatures(featurePath);
    Feature[] features = new Feature[featuresMap.size()];
    int index = 0;
    for(String key: featuresMap.keySet()) {
View Full Code Here

    DocumentVectorOnTheFlyIndexing generator = new DocumentVectorOnTheFlyIndexing(env, fs);

    //Parse queries, judgemnts and features
    HMapIV<String> parsedQueries = QueryUtility.loadQueries(queryPath);
    HMapIV<int[]> queries = QueryUtility.queryToIntegerCode(env, parsedQueries);
    HMapIF idfs = QueryUtility.loadIdf(env, parsedQueries);
    HMapIF cfs = QueryUtility.loadCf(env, parsedQueries);
    HMapIV<int[]> qrels = QrelUtility.parseQrelsFromTabDelimited(qrelPath);
    Map<String, Feature> featuresMap = FeatureUtility.parseFeatures(featurePath);
    Feature[] features = new Feature[featuresMap.size()];
    int index = 0;
    for(String key: featuresMap.keySet()) {
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.util.array.ArrayListOfShorts

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.