Examples of TIntFloatHashMap


Examples of gnu.trove.TIntFloatHashMap

    it = cv.orderedIterator();
   
    int count = 0;
    ArrayList<Integer> pages = new ArrayList<Integer>();
           
    TIntFloatHashMap valueMap2 = new TIntFloatHashMap(1000);
    TIntFloatHashMap valueMap3 = new TIntFloatHashMap();
   
    ArrayList<Integer> npages = new ArrayList<Integer>();
   
    HashMap<Integer, Float> secondMap = new HashMap<Integer, Float>(1000);
   
   
    this.clean();
       
    // collect article objects
    while(it.next()){
      pages.add(it.getId());
      valueMap2.put(it.getId(),(float) it.getValue());
      count++;
    }
   
    // prepare inlink counts
    setInlinkCounts(pages);
       
    for(int pid : pages){     
      Collection<Integer> raw_links = getLinks(pid);
      if(raw_links.isEmpty()){
        continue;
      }
      ArrayList<Integer> links = new ArrayList<Integer>(raw_links.size());
     
      final double inlink_factor_p = Math.log(inlinkMap.get(pid));
                   
      float origValue = valueMap2.get(pid);
     
      setInlinkCounts(raw_links);
           
      for(int lid : raw_links){
        final double inlink_factor_link = Math.log(inlinkMap.get(lid));
       
        // check concept generality..
        if(inlink_factor_link - inlink_factor_p > 1){
          links.add(lid);
        }
      }
           
      for(int lid : links){       
        if(!valueMap2.containsKey(lid)){
          valueMap2.put(lid, 0.0f);
          npages.add(lid);
        }
      }
           
     
     
      float linkedValue = 0.0f;
                 
      for(int lid : links){
        if(valueMap3.containsKey(lid)){
          linkedValue = valueMap3.get(lid);
          linkedValue += origValue;
          valueMap3.put(lid, linkedValue);
        }
        else {
          valueMap3.put(lid, origValue);
        }
      }
     
    }
   
   
//    for(int pid : pages){     
//      if(valueMap3.containsKey(pid)){
//        secondMap.put(pid, (float) (valueMap2.get(pid) + ALPHA * valueMap3.get(pid)));
//      }
//      else {
//        secondMap.put(pid, (float) (valueMap2.get(pid) ));
//      }
//    }
   
    for(int pid : npages){     
      secondMap.put(pid, (float) (ALPHA * valueMap3.get(pid)));

    }
   
   
    //System.out.println("read links..");
View Full Code Here

Examples of gnu.trove.TIntFloatHashMap

   
    String line;
    String prevTerm = null;
    int doc;
    float score;
    TIntFloatHashMap hmap = new TIntFloatHashMap(100);
   
    // for pruning
    int mark, windowMark;
      float first = 0, last = 0, highest = 0;
      float [] window = new float[WINDOW_SIZE];
     
    while((line = bir.readLine()) != null){
      final String [] parts = line.split("\t");
      term = parts[1];
     
      // prune and write the vector
      if(prevTerm != null && !prevTerm.equals(term)){
        int [] arrDocs = hmap.keys();
          float [] arrScores = hmap.getValues();
         
          HeapSort.heapSort(arrScores, arrDocs);
         
          // prune the vector
         
          mark = 0;
        windowMark = 0;
        highest = first = last = 0;
         
          ByteArrayOutputStream baos = new ByteArrayOutputStream(50000);
          DataOutputStream tdos = new DataOutputStream(baos);
         
          for(int j=arrDocs.length-1;j>=0;j--){
            score = arrScores[j];
           
            // sliding window
           
            window[windowMark] = score;
           
            if(mark == 0){
              highest = score;
              first = score;
            }
                   
            if(mark < WINDOW_SIZE){
              tdos.writeInt(arrDocs[j]);
              tdos.writeFloat(score);
            }
            else if( highest*WINDOW_THRES < (first - last) ){
              tdos.writeInt(arrDocs[j]);
              tdos.writeFloat(score);

              if(windowMark < WINDOW_SIZE-1){
                first = window[windowMark+1];
              }
              else {
                first = window[0];
              }
            }
           
            else {
              // truncate
              break;
           
           
            last = score;

            mark++;
            windowMark++;
           
            windowMark = windowMark % WINDOW_SIZE;
           
          }
                   
          ByteArrayOutputStream dbvector = new ByteArrayOutputStream();
          DataOutputStream dbdis = new DataOutputStream(dbvector);
          dbdis.writeInt(mark);
          dbdis.flush();
          dbvector.write(baos.toByteArray());
          dbvector.flush();
         
          dbdis.close();
                                       
          // write to DB
          pstmtVector.setString(1, prevTerm);
          pstmtVector.setBlob(2, new ByteArrayInputStream(dbvector.toByteArray()));
         
          pstmtVector.execute();
         
          tdos.close();
          baos.close();
       
        hmap.clear();
      }
     
      doc = Integer.valueOf(parts[2]);
      score = Float.valueOf(parts[3]);
     
      hmap.put(doc, score);
     
      prevTerm = term;
    }
   
      bir.close();
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

        return scoring;
    }

    public void onAttached(String vkey) {
        caches.put(vkey, new TIntFloatHashMap());
        caches.put("length:" + vkey, new TIntFloatHashMap());
    }
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

        return scoring;
    }

    public void onAttached(String vkey) {
        caches.put(vkey, new TIntFloatHashMap());
    }
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

        validateParams(vecid, pairs);
        if (!indexer.containsKey(vecid)) {
            _add(vecid, pairs);
        } else {
            TIntList indexes = new TIntArrayList();
            TIntFloatMap results = new TIntFloatHashMap();

            float max = Float.NEGATIVE_INFINITY;
            int cursor = indexer.get(vecid);
            int length = lengths.get(vecid);
            while (length > 0) {
                int pos = (int) data.get(cursor++);
                float val = data.get(cursor++);
                results.put(pos, val);
                if (val > max) {
                    max = val;
                }
                indexes.add(pos);
                length -= 2;
            }

            cursor = 0;
            while (cursor < pairs.length) {
                int pos = pairs[cursor++];
                float val = (float) pairs[cursor++];
                if (results.containsKey(pos)) {
                    val = results.get(pos) + val;
                    results.put(pos, val);
                    if (val > max) {
                        max = val;
                    }
                } else {
                    results.put(pos, val);
                    indexes.add(pos);
                }
            }
            indexes.sort();

            int start = data.size();
            indexer.put(vecid, start);
            lengths.put(vecid, indexes.size() * 2);
            TIntIterator iter = indexes.iterator();
            if (max < accumuFactor * sparseFactor) {
                while (iter.hasNext()) {
                    int key = iter.next();
                    float value = results.get(key);
                    data.add(key);
                    data.add(value);
                }
            } else {
                while (iter.hasNext()) {
                    int key = iter.next();
                    float value = results.get(key) * accumuFactor / max;
                    data.add(key);
                    data.add(value);
                }
            }

View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

      min = c1;
    }else{
      max = c1;
      min = c2;
    }
    TIntFloatHashMap map2 = wcc.get(min);
    if(map2==null){
      map2 = new TIntFloatHashMap();
      wcc.put(min, map2);
    }
    map2.put(max, w);
  }
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

    }else{
      max = c1;
      min = c2;
    }
    float w;
    TIntFloatHashMap map2 = wcc.get(min);
    if(map2==null){
      w = 0;
    }else
      w = map2.get(max);
    return w;
  }
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

          idx = -2;         
        }
        wordProb.adjustOrPutValue(idx, 1, 1);


        TIntFloatHashMap map = pcc.get(prechar);
        if(map==null){
          map = new TIntFloatHashMap();
          pcc.put(prechar, map);
        }       
        map.adjustOrPutValue(idx, 1, 1);

        TIntHashSet left = leftnodes.get(idx);
        if(left==null){
          left = new TIntHashSet();
          leftnodes.put(idx, left);
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

    }

    TIntObjectIterator<TIntFloatHashMap> it1 = pcc.iterator();
    while(it1.hasNext()){
      it1.advance();
      TIntFloatHashMap map = it1.value();
      TIntFloatIterator it2 = map.iterator();
      while(it2.hasNext()){
        it2.advance();
        it2.setValue(it2.value()/totalword);
      }
    }
View Full Code Here

Examples of gnu.trove.map.hash.TIntFloatHashMap

    return p;
  }

  private float getProb(int c1, int c2) {
    float p;
    TIntFloatHashMap map = pcc.get(c1);
    if(map == null){
      p = 0f;
    }else{
      p = pcc.get(c1).get(c2);           
    }
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.