Package gnu.trove

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


   
    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

TOP

Related Classes of gnu.trove.TIntFloatHashMap

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.