![JAR search and dependency download from the Maven repository](/logo.png)
edu.berkeley.nlp.classify.IndexLinearizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of berkeleyparser Show documentation
Show all versions of berkeleyparser Show documentation
The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).
The newest version!
package edu.berkeley.nlp.classify;
import java.io.Serializable;
/**
* 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 implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6164226851901151038L;
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