|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.classify.LinearClassifier
public class LinearClassifier
Implements a multiclass linear classifier. At classification time this can be any generalized linear model classifier (such as a perceptron, naive logistic regression, SVM).
Field Summary | |
---|---|
boolean |
intern
|
static String |
TEXT_SERIALIZATION_DELIMITER
|
Constructor Summary | |
---|---|
LinearClassifier(Counter<Pair> weightCounter)
|
|
LinearClassifier(Counter<Pair> weightCounter,
Counter thresholdsC)
|
|
LinearClassifier(double[][] weights,
Index featureIndex,
Index labelIndex)
|
|
LinearClassifier(double[][] weights,
Index featureIndex,
Index labelIndex,
double[] thresholds)
|
Method Summary | |
---|---|
void |
adaptWeights(Dataset adapt,
LinearClassifierFactory lcf)
|
Object |
classOf(Datum example)
|
Object |
classOf(RVFDatum example)
|
void |
dump()
Print all features in the classifier and the weight that they assign to each class. |
void |
dumpSorted()
Print all features in the classifier and the weight that they assign to each class. |
Index |
featureIndex()
|
Collection<Object> |
features()
|
void |
justificationOf(Datum example)
|
void |
justificationOf(Datum example,
PrintWriter pw)
Print all features active for a particular datum and the weight that the classifier assigns to each class for those features. |
void |
justificationOf(Datum example,
PrintWriter pw,
boolean sorted)
Print all features active for a particular datum and the weight that the classifier assigns to each class for those features. |
void |
justificationOf(Datum example,
PrintWriter pw,
Function printer)
|
void |
justificationOf(Datum example,
PrintWriter pw,
Function printer,
boolean sortedByFeature)
Print all features active for a particular datum and the weight that the classifier assigns to each class for those features. |
void |
justificationOf(RVFDatum example)
|
void |
justificationOf(RVFDatum example,
PrintWriter pw)
Print all features active for a particular datum and the weight that the classifier assigns to each class for those features. |
Index<Object> |
labelIndex()
|
Collection<Object> |
labels()
|
Counter |
logProbabilityOf(Datum example)
Returns a counter mapping from each class name to the log probability of that class for a certain example. |
Counter |
logProbabilityOf(RVFDatum example)
Returns a counter for the log probability of each of the classes looking at the the sum of e^v for each count v, should be 1 |
Counter |
probabilityOf(Datum example)
Returns a counter mapping from each class name to the probability of that class for a certain example. |
Counter |
probabilityOf(RVFDatum example)
Returns a counter mapping from each class name to the probability of that class for a certain example. |
static LinearClassifier |
readClassifier(String loadPath)
|
void |
saveToFilename(String file)
Saves this out to a standard text file, instead of as a serialized Java object. |
double |
scoreOf(Datum example,
Object label)
Returns of the score of the Datum for the specified label. |
double |
scoreOf(RVFDatum example,
Object label)
Returns the score of the RVFDatum for the specified label. |
Counter |
scoresOf(Datum example)
Construct a counter with keys the labels of the classifier and values the score (unnormalized log probability) of each class. |
Counter |
scoresOf(Datum example,
Collection possibleLabels)
|
Counter |
scoresOf(RVFDatum example)
Construct a counter with keys the labels of the classifier and values the score (unnormalized log probability) of each class for an RVFDatum. |
void |
setWeights(double[][] newWeights)
|
String |
toAllWeightsString()
|
String |
toBiggestWeightFeaturesString(boolean useMagnitude,
int numFeatures,
boolean printDescending)
Return a String that prints features with large weights. |
String |
toDistributionString(int treshold)
Similar to histogram but exact values of the weights to see whether there are many equal weights. |
String |
toHistogramString()
|
String |
toString()
Print out a partial representation of a linear classifier. |
String |
toString(String style,
int param)
Print out a partial representation of a linear classifier in one of several ways. |
int |
totalSize()
|
double |
weight(Object feature,
Object label)
|
double[][] |
weights()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public boolean intern
public static final String TEXT_SERIALIZATION_DELIMITER
Constructor Detail |
---|
public LinearClassifier(double[][] weights, Index featureIndex, Index labelIndex)
public LinearClassifier(double[][] weights, Index featureIndex, Index labelIndex, double[] thresholds) throws Exception
Exception
public LinearClassifier(Counter<Pair> weightCounter)
public LinearClassifier(Counter<Pair> weightCounter, Counter thresholdsC)
Method Detail |
---|
public Collection<Object> labels()
labels
in interface Classifier
public Collection<Object> features()
public Index<Object> labelIndex()
public Index featureIndex()
public double weight(Object feature, Object label)
public Counter scoresOf(Datum example)
scoresOf
in interface Classifier
public double scoreOf(Datum example, Object label)
public Counter scoresOf(RVFDatum example)
scoresOf
in interface RVFClassifier
public double scoreOf(RVFDatum example, Object label)
public Counter probabilityOf(Datum example)
probabilityOf
in interface ProbabilisticClassifier
public Counter probabilityOf(RVFDatum example)
public Counter logProbabilityOf(Datum example)
logProbabilityOf
in interface ProbabilisticClassifier
public Counter logProbabilityOf(RVFDatum example)
public String toBiggestWeightFeaturesString(boolean useMagnitude, int numFeatures, boolean printDescending)
useMagnitude
- Whether the notion of "large" should ignore
the sign of the feature weight.numFeatures
- How many top features to print
public String toDistributionString(int treshold)
public int totalSize()
public String toHistogramString()
public String toString()
toString
in class Object
public String toString(String style, int param)
style
- Options are:
HighWeight: print out the param parameters with largest weights;
HighMagnitude: print out the param parameters for which the absolute
value of their weight is largest;
AllWeights: print out the weights of all features
WeightHistogram: print out a particular hard-coded textual histogram
representation of a classifierparam
- Determines the number of things printed in certain styles
IllegalArgumentException
- if the style name is unrecognizedpublic String toAllWeightsString()
public void dump()
public void justificationOf(RVFDatum example)
public void justificationOf(RVFDatum example, PrintWriter pw)
public void justificationOf(Datum example)
public void justificationOf(Datum example, PrintWriter pw, Function printer)
public void justificationOf(Datum example, PrintWriter pw, Function printer, boolean sortedByFeature)
example
- The datum for which features are to be printedpw
- Where to print it toprinter
- If this is non-null, then it is applied to each
feature to convert it to a more readable formsortedByFeature
- Whether to sort by feature namespublic void justificationOf(Datum example, PrintWriter pw)
public void dumpSorted()
public void justificationOf(Datum example, PrintWriter pw, boolean sorted)
public Counter scoresOf(Datum example, Collection possibleLabels)
public Object classOf(Datum example)
classOf
in interface Classifier
public Object classOf(RVFDatum example)
classOf
in interface RVFClassifier
public void adaptWeights(Dataset adapt, LinearClassifierFactory lcf)
public double[][] weights()
public void setWeights(double[][] newWeights)
public static LinearClassifier readClassifier(String loadPath)
public void saveToFilename(String file)
file
- String filepath to write out to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |