Examples of HashSparseVector


Examples of org.fnlp.ml.types.sv.HashSparseVector

    this.docNum = docNum;
  }

  @Override
  public void addThruPipe(Instance inst) {
    HashSparseVector data = (HashSparseVector) inst.getData();
    TIntFloatIterator it = data.data.iterator();
    while (it.hasNext()) {
      it.advance();
      int id = it.key();
      if (idf[id] > 0) {
        float value = (float) (it.value()*Math.log(docNum / idf[id]));
        data.put(id, value);
      }
    }

  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

 
  @Override
  public void addThruPipe(Instance inst) throws Exception {
    List<String> data = (List<String>) inst.getData();
    int size = data.size();
    HashSparseVector sv = new HashSparseVector();
   
    Iterator<String> it = data.iterator();
   
    for(int i=0;i<size;i++){
      String token = it.next();
      if(isSorted){
        token+="@"+i;
      }
      int id = features.lookupIndex(token);
      if(id==-1)
        continue;
      sv.put(id, 1.0f);
    }
    sv.put(constIndex, 1.0f);
    inst.setData(sv);
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

  }
  public void noFeatureSelection(){
    Arrays.fill(isUseful, true);
  }
  public HashSparseVector select(HashSparseVector vec){
    HashSparseVector sv=new HashSparseVector();   
    TIntFloatIterator it=vec.data.iterator();
    while(it.hasNext()){
      it.advance();
      if(isUseful[it.key()])
        sv.put(it.key(), it.value());
    }
    return sv;
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   * @param insts
   *
   * @return
   */
  private HashSparseVector calculateCentroid (ArrayList<Instance> insts) {
    HashSparseVector centroid = new HashSparseVector();
   
   
    Iterator i = insts.iterator();

    while (i.hasNext()) {
      Instance d = (Instance) i.next();

      centroid.plus((HashSparseVector) d.getData());
    }
    centroid.scaleDivide(insts.size());

    return centroid;
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

    return true;
  }

  public Instance next() {
    String[] tokens = content.split("\\t+|\\s+");
    HashSparseVector sv = new HashSparseVector();
   
    for (int i = 1; i < tokens.length; i++) {
      String[] taken = tokens[i].split(":");
      if (taken.length > 1) {
        float value = Float.parseFloat(taken[1]);
        int idx = Integer.parseInt(taken[0]);
        sv.put(idx, value);
      }
    }
    return new Instance(sv, tokens[0]);
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   * @return
   */
  private float calculateClusterQuality (ArrayList<Instance> docs,
      HashSparseVector centroid) {
    float quality = 0.0f;
    HashSparseVector c = centroid;

    for (int i = 0; i < docs.size(); ++i) {
      Instance doc = docs.get(i);

      quality += c.distanceEuclidean((HashSparseVector) doc.getData());
    }

    return quality;
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

    /* Clear records for incremental k-means */

    for (int i = 0; i < this.centroids.length; ++i) {
      this.newClusters[i] = new ArrayList<Instance>();
      this.newCentroids[i] = new HashSparseVector();
      this.newQualities[i] = 0.0f;
    }

    for (int clusterNum = 0; clusterNum < this.centroids.length; ++clusterNum) {    // iterate over clusters
      for (int docNum = 0; docNum < this.assignedClusters[clusterNum].size();  ++docNum) {    // iterate over docs

        /*
         *  Store the document the loops have selected in the 'doc' variable.
         * Store is vector in the 'docVec' variable for easy access.
         */
        Instance doc = this.assignedClusters[clusterNum].get(docNum);
        HashSparseVector docVec = (HashSparseVector) doc.getData();

        int bestClusterNum = clusterNum;    // Assume we are already in the best cluster.
        double distanceToCurrentCentroid =
          this.centroids[clusterNum].distanceEuclidean(docVec);
        double squareDistanceOfBestCluster = distanceToCurrentCentroid;
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

  }

  @Override
  public void addThruPipe(Instance inst) {
    HashSparseVector data = (HashSparseVector) inst.getData();
    TIntFloatIterator it = data.data.iterator();
    while (it.hasNext()) {
      it.advance();
      idf[it.key()]++;
    }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

    Object obj=instance.getData();
    if(!(obj instanceof HashSparseVector)){
      System.out.println("error 输入类型非HashSparseVector!");
      return null;
    }
    HashSparseVector data = (HashSparseVector) obj;
    if(fs!=null)
      data=fs.select(data);
    TIntFloatIterator it = data.data.iterator();
    float feaSize=tf.getFeatureSize();
    while (it.hasNext()) {
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

    }
    else{
      return false;
    }
   
    HashSparseVector data = (HashSparseVector) inst.getData();
    TIntFloatIterator it = data.data.iterator();
    while (it.hasNext()) {
      it.advance();
      int feature=it.key();
      for(int i=0;i<type.length;i++){
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.