Package com.clearnlp.classification.vector

Examples of com.clearnlp.classification.vector.SparseFeatureVector


    return Collections.max(ps);
  }
 
  private void updateCounts(StringOnlineModel model, IntInstance instance, double[] gs, int yp, int yn)
  {
    SparseFeatureVector x = instance.getFeatureVector();
    int i, len = x.size();
    double d;
   
    for (i=0; i<len; i++)
    {
      d = UTMath.sq(x.getWeight(i));
     
      gs[model.getWeightIndex(yp, x.getIndex(i))] += d;
      gs[model.getWeightIndex(yn, x.getIndex(i))] += d;
    }
  }
View Full Code Here


    }
  }
 
  private void updateWeights(StringOnlineModel model, IntInstance instance, double[] gs, int yp, int yn)
  {
    SparseFeatureVector x = instance.getFeatureVector();
    int i, xi, len = x.size();
    double vi, cost;
   
    for (i=0; i<len; i++)
    {
      xi = x.getIndex(i);
      vi = x.getWeight(i);
     
      cost = getCost(model, gs, yp, xi) * vi;
      model.updateWeight(yp, xi, (float)cost);
     
      cost = -getCost(model, gs, yn, xi) * vi;
 
View Full Code Here

   * @param vector the string feature vector.
   * @return the sparse feature vector converted from the string feature vector.
   */
  public SparseFeatureVector toSparseFeatureVector(StringFeatureVector vector)
  {
    SparseFeatureVector sparse = new SparseFeatureVector(vector.hasWeight());
    int i, index, size = vector.size();
    ObjectIntHashMap<String> map;
    String type, value;
   
    for (i=0; i<size; i++)
    {
      type  = vector.getType(i);
      value = vector.getValue(i);
     
      if ((map = m_features.get(type)) != null && (index = map.get(value)) > 0)
      {
        if (sparse.hasWeight())
          sparse.addFeature(index, vector.getWeight(i));
        else
          sparse.addFeature(index);
      }
    }
   
    sparse.trimToSize();
    return sparse;
  }
View Full Code Here

 
// ================================ BUILD ================================

  public void build(int labelCutoff, int featureCutoff)
  {
    SparseFeatureVector vector;
    StringInstance instance;
    int label;
   
    l_instances = Lists.newArrayList();
    buildLabels  (labelCutoff);
    buildFeatures(featureCutoff);
   
    while ((instance = i_collector.pollInstance()) != null)
    {
      if ((label = getLabelIndex(instance.getLabel())) < 0)
        continue;
     
      vector = toSparseFeatureVector(instance.getFeatureVector());
      if (!vector.isEmpty()) l_instances.add(new IntInstance(label, vector));
    }
  }
View Full Code Here

   * @param vector the string feature vector.
   * @return the sparse feature vector converted from the string feature vector.
   */
  public SparseFeatureVector toSparseFeatureVector(StringFeatureVector vector)
  {
    SparseFeatureVector sparse = new SparseFeatureVector(vector.hasWeight());
    int i, index, size = vector.size();
    ObjectIntOpenHashMap<String> map;
    String type, value;
   
    for (i=0; i<size; i++)
    {
      type  = vector.getType(i);
      value = vector.getValue(i);
     
      if ((map = m_features.get(type)) != null && (index = map.get(value)) > 0)
      {
        if (sparse.hasWeight())
          sparse.addFeature(index, vector.getWeight(i));
        else
          sparse.addFeature(index);
      }
    }
   
    sparse.trimToSize();
    return sparse;
  }
View Full Code Here

TOP

Related Classes of com.clearnlp.classification.vector.SparseFeatureVector

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.