All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.berkeley.nlp.discPCFG.IndexLinearizer Maven / Gradle / Ivy

Go to download

The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).

The newest version!
/**
 * 
 */
package edu.berkeley.nlp.discPCFG;

/**
 * @author petrov
 *
 */
/**
 * The IndexLinearizer maintains the linearization of the two-dimensional features-by-labels pair space.  This is
 * because, while we might think about lambdas and derivatives as being indexed by a feature-label pair, the
 * optimization code expects one long vector for lambdas and derivatives.  To go from a pair featureIndex, labelIndex
 * to a single pairIndex, use getLinearIndex().
 */
public class IndexLinearizer {
  int numFeatures;
  int numLabels;

  public int getNumLinearIndexes() {
    return numFeatures * numLabels;
  }

  public int getLinearIndex(int featureIndex, int labelIndex) {
    return labelIndex + featureIndex * numLabels;
  }

  public int getFeatureIndex(int linearIndex) {
    return linearIndex / numLabels;
  }

  public int getLabelIndex(int linearIndex) {
    return linearIndex % numLabels;
  }

  public IndexLinearizer(int numFeatures, int numLabels) {
    this.numFeatures = numFeatures;
    this.numLabels = numLabels;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy