Package gnu.trove.map.hash

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


        return scoring;
    }

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

        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

      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

    }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

          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

    }

    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

    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

  protected void merge(int c1, int c2) {
    int newid = lastid++;
    heads.put(c1, newid);
    heads.put(c2, newid);
    TIntFloatHashMap newpcc = new TIntFloatHashMap();
    TIntFloatHashMap inewpcc = new TIntFloatHashMap();
    TIntFloatHashMap newwcc = new TIntFloatHashMap();
    float pc1 = wordProb.get(c1);
    float pc2 = wordProb.get(c2);   
    //新类的概率
    float pc = pc1+pc2;

    float w;
    {
      float pcc1 = getProb(c1,c1);
      float pcc2 = getProb(c2,c2);
      float pcc3 = getProb(c1,c2);
      float pcc4 = getProb(c2,c1);
      float pcc = pcc1 + pcc2 + pcc3 + pcc4;
      if(pcc!=0.0f)
        newpcc.put(newid, pcc);
      w = clacW(pcc,pc,pc);
      if(w!=0.0f)
        newwcc.put(newid, w);
    }
    TIntIterator it = slots.iterator();
    while(it.hasNext()){
      int k = it.next();

      float pck = wordProb.get(k);     
      if (c1==k||c2==k) {     
        continue;
      } else {       
        float pcc1 = getProb(c1,k);
        float pcc2 = getProb(c2,k);
        float pcc12 = pcc1 + pcc2;
        if(pcc12!=0.0f)
          newpcc.put(newid, pcc12);
        float p1 = clacW(pcc12,pc,pck);

        float pcc3 = getProb(k,c1);
        float pcc4 = getProb(k,c2);     
        float pcc34 = pcc3 + pcc4;
        if(pcc34!=0.0f)
          inewpcc.put(k, pcc34)
        float p2 = clacW(pcc34,pck,pc);
        w =  p1 + p2;
        if(w!=0.0f)
          newwcc.put(newid, w);
      }
    }

    //更新slots
    slots.remove(c1);
    slots.remove(c2);
    slots.add(newid);
    pcc.put(newid, newpcc);
    pcc.remove(c1);
    pcc.remove(c2);
    TIntFloatIterator it2 = inewpcc.iterator();
    while(it2.hasNext()){
      it2.advance();
      TIntFloatHashMap pmap = pcc.get(it2.key());
      //            if(pmap==null){
      //              pmap = new TIntFloatHashMap();
      //              pcc.put(it2.key(), pmap);
      //            }
      pmap.put(newid, it2.value());
      pmap.remove(c1);
      pmap.remove(c2);
    }


    //
    //newid 永远大于 it3.key;
    wcc.put(newid, new TIntFloatHashMap());
    wcc.remove(c1);
    wcc.remove(c2);
    TIntFloatIterator it3 = newwcc.iterator();
    while(it3.hasNext()){
      it3.advance();
      TIntFloatHashMap pmap = wcc.get(it3.key());
      pmap.put(newid, it3.value());
      pmap.remove(c1);
      pmap.remove(c2);
    }

    wordProb.remove(c1);
    wordProb.remove(c2);
    wordProb.put(newid, pc);
View Full Code Here

  public HashSparseVector() {

  }

  public HashSparseVector(HashSparseVector v) {
    data = new TIntFloatHashMap(v.data);
  }
View Full Code Here

TOP

Related Classes of gnu.trove.map.hash.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.