public class SparseNetworkLearner extends Learner
SparseNetworkLearner
uses multiple LinearThresholdUnit
s to make a
multi-class classification. Any LinearThresholdUnit
may be used, so long as it implements
its clone()
method and a public constructor that takes no arguments.
It is assumed that a single discrete label feature will be produced in association with each example object. A feature taking one of the values observed in that label feature will be produced by the learned classifier.
This algorithm's user-configurable parameters are stored in member fields of this class. They may
be set via either a constructor that names each parameter explicitly or a constructor that takes
an instance of Parameters
as input. The documentation in
each member field in this class indicates the default value of the associated parameter when
using the former type of constructor. The documentation of the associated member field in the
Parameters
class indicates the default value of the
parameter when using the latter type of constructor.
Modifier and Type | Class and Description |
---|---|
static class |
SparseNetworkLearner.Parameters
Simply a container for all of
SparseNetworkLearner 's configurable parameters. |
Modifier and Type | Field and Description |
---|---|
protected LinearThresholdUnit |
baseLTU
The underlying algorithm used to learn each class separately as a binary classifier; default
defaultBaseLTU . |
protected boolean |
conjunctiveLabels
Whether or not this learner's labeler produces conjunctive features.
|
static LinearThresholdUnit |
defaultBaseLTU
Default for
baseLTU . |
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector |
network
A collection of the linear threshold units used to learn each label, indexed by the label.
|
protected int |
numExamples
The total number of examples in the training data, or 0 if unknown.
|
protected int |
numFeatures
The total number of distinct features in the training data, or 0 if unknown.
|
candidates, encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, lossFlag, predictions, readLexiconOnDemand
containingPackage, name
Constructor and Description |
---|
SparseNetworkLearner()
Instantiates this multi-class learner with the default learning algorithm:
defaultBaseLTU . |
SparseNetworkLearner(LinearThresholdUnit ltu)
Instantiates this multi-class learner using the specified algorithm to learn each class
separately as a binary classifier.
|
SparseNetworkLearner(SparseNetworkLearner.Parameters p)
Initializing constructor.
|
SparseNetworkLearner(String n)
Instantiates this multi-class learner with the default learning algorithm:
defaultBaseLTU . |
SparseNetworkLearner(String n,
LinearThresholdUnit ltu)
Instantiates this multi-class learner using the specified algorithm to learn each class
separately as a binary classifier.
|
SparseNetworkLearner(String n,
SparseNetworkLearner.Parameters p)
Initializing constructor.
|
Modifier and Type | Method and Description |
---|---|
FeatureVector |
classify(int[] exampleFeatures,
double[] exampleValues)
This implementation uses a winner-take-all comparison of the outputs from the individual
linear threshold units' score methods.
|
Object |
clone()
Returns a deep clone of this learning algorithm.
|
protected ScoreSet |
conjunctiveScores(int[] exampleFeatures,
double[] exampleValues,
Iterator I)
This method is a surrogate for
scores(int[],double[],Collection) when the labeler is
known to produce conjunctive features. |
protected Feature |
conjunctiveValueOf(int[] exampleFeatures,
double[] exampleValues,
Iterator I)
This method is a surrogate for
valueOf(int[],double[],Collection) when the labeler
is known to produce conjunctive features. |
String |
discreteValue(int[] exampleFeatures,
double[] exampleValues)
This implementation uses a winner-take-all comparison of the outputs from the individual
linear threshold units' score methods.
|
void |
doneLearning()
Simply calls
doneLearning() on every LTU in the network. |
void |
doneWithRound()
Simply calls
Learner.doneWithRound() on every LTU in the network. |
Feature |
featureValue(int[] f,
double[] v)
Returns the classification of the given example as a single feature instead of a
FeatureVector . |
void |
forget()
Clears the network.
|
LinearThresholdUnit |
getBaseLTU() |
Object |
getLTU(int i)
returns the i-th LTU; the type of this depends on the type of the baseLTU (see above).
|
edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector |
getNetwork() |
int |
getNumExamples() |
int |
getNumFeatures() |
Learner.Parameters |
getParameters()
Retrieves the parameters that are set in this learner.
|
void |
initialize(int ne,
int nf)
Sets the number of examples and features.
|
boolean |
isUsingConjunctiveLabels() |
void |
learn(int[] exampleFeatures,
double[] exampleValues,
int[] exampleLabels,
double[] labelValues)
Each example is treated as a positive example for the linear threshold unit associated with
the label's value that is active for the example and as a negative example for all other
linear threshold units in the network.
|
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a learner with this object's run-time type, overwriting
any and all learned or manually specified parameters as well as the label lexicon but without
modifying the feature lexicon.
|
ScoreSet |
scores(int[] exampleFeatures,
double[] exampleValues)
Produces a set of scores indicating the degree to which each possible discrete classification
value is associated with the given example object.
|
ScoreSet |
scores(int[] exampleFeatures,
double[] exampleValues,
Collection candidates)
Returns scores for only those labels in the given collection.
|
ScoreSet |
scores(Object example,
Collection candidates)
Returns scores for only those labels in the given collection.
|
void |
setExtractor(Classifier e)
Sets the extractor.
|
void |
setLabeler(Classifier l)
Sets the labeler.
|
void |
setLTU(LinearThresholdUnit ltu)
Sets the
baseLTU variable. |
void |
setNetworkLabel(int label)
Create a
LinearThresholdUnit and add it to the network |
void |
setParameters(SparseNetworkLearner.Parameters p)
Sets the values of parameters that control the behavior of this learning algorithm.
|
Feature |
valueOf(int[] exampleFeatures,
double[] exampleValues,
Collection candidates)
Using this method, the winner-take-all competition is narrowed to involve only those labels
contained in the specified list.
|
Feature |
valueOf(Object example,
Collection candidates)
Using this method, the winner-take-all competition is narrowed to involve only those labels
contained in the specified list.
|
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes the learned function's internal representation in binary form.
|
void |
write(PrintStream out)
Writes the algorithm's internal representation as text.
|
classify, classify, classify, classify, countFeatures, createPrediction, createPrediction, demandLexicon, discreteValue, discreteValue, emptyClone, featureValue, featureValue, getCurrentLexicon, getExampleArray, getExampleArray, getExtractor, getLabeler, getLabelLexicon, getLexicon, getLexiconDiscardCounts, getLexiconLocation, getModelLocation, getPrunedLexiconSize, learn, learn, learn, learn, read, readLabelLexicon, readLearner, readLearner, readLearner, readLearner, readLearner, readLearner, readLexicon, readLexicon, readLexiconOnDemand, readLexiconOnDemand, readModel, readModel, readParameters, realValue, realValue, realValue, save, saveLexicon, saveModel, scores, scores, scoresAugmented, setCandidates, setEncoding, setLabelLexicon, setLexicon, setLexiconLocation, setLexiconLocation, setLossFlag, setModelLocation, setModelLocation, setParameters, setReadLexiconOnDemand, unclone, unsetLossFlag, write, writeLexicon, writeModel, writeParameters
allowableValues, classify, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValueArray, test, toString, valueIndexOf
public static final LinearThresholdUnit defaultBaseLTU
baseLTU
.protected LinearThresholdUnit baseLTU
defaultBaseLTU
.protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector network
protected int numExamples
protected int numFeatures
protected boolean conjunctiveLabels
public SparseNetworkLearner()
defaultBaseLTU
.public SparseNetworkLearner(LinearThresholdUnit ltu)
ltu
- The linear threshold unit used to learn binary classifiers.public SparseNetworkLearner(SparseNetworkLearner.Parameters p)
SparseNetworkLearner.Parameters
object.p
- The settings of all parameters.public SparseNetworkLearner(String n)
defaultBaseLTU
.n
- The name of the classifier.public SparseNetworkLearner(String n, LinearThresholdUnit ltu)
n
- The name of the classifier.ltu
- The linear threshold unit used to learn binary classifiers.public SparseNetworkLearner(String n, SparseNetworkLearner.Parameters p)
SparseNetworkLearner.Parameters
object.n
- The name of the classifier.p
- The settings of all parameters.public int getNumExamples()
public int getNumFeatures()
public LinearThresholdUnit getBaseLTU()
public edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector getNetwork()
public boolean isUsingConjunctiveLabels()
public Object getLTU(int i)
public void setParameters(SparseNetworkLearner.Parameters p)
p
- The parameters.public Learner.Parameters getParameters()
getParameters
in class Learner
public void setLTU(LinearThresholdUnit ltu)
baseLTU
variable. This method will not have any effect on the
LTUs that already exist in the network. However, new LTUs created after this method is
executed will be of the same type as the object specified.ltu
- The new LTU.public void setLabeler(Classifier l)
setLabeler
in class Learner
l
- A labeling classifier.public void setExtractor(Classifier e)
setExtractor
in class Learner
e
- A feature extracting classifier.public void setNetworkLabel(int label)
LinearThresholdUnit
and add it to the networklabel
- The label associated with the LTUpublic void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues)
public void doneLearning()
doneLearning()
on every LTU in the network.doneLearning
in class Learner
public void initialize(int ne, int nf)
initialize
in class Learner
ne
- The number of examples that will be observed during training.nf
- The number of features that will be observed during training.public void doneWithRound()
Learner.doneWithRound()
on every LTU in the network.doneWithRound
in class Learner
public ScoreSet scores(Object example, Collection candidates)
LinearThresholdUnit
associated with a given label from the collection, that label's score in the returned
ScoreSet
will be set to Double.NEGATIVE_INFINITY
.
The elements of candidates
must all be String
s.
example
- The example object.candidates
- A list of the only labels the example may take.candidates
.public ScoreSet scores(int[] exampleFeatures, double[] exampleValues, Collection candidates)
LinearThresholdUnit
associated with a given label from the collection, that label's score in the returned
ScoreSet
will be set to Double.NEGATIVE_INFINITY
.
The elements of candidates
must all be String
s.
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.candidates
- A list of the only labels the example may take.candidates
.protected ScoreSet conjunctiveScores(int[] exampleFeatures, double[] exampleValues, Iterator I)
scores(int[],double[],Collection)
when the labeler is
known to produce conjunctive features. It is necessary because when given a string label from
the collection, we will not know how to construct the appropriate conjunctive feature key for
lookup in the label lexicon. So, we must go through each feature in the label lexicon and use
Feature.valueEquals(String)
.exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.I
- An iterator over the set of labels to choose from.null
if the network did not
contain any of the specified labels.public ScoreSet scores(int[] exampleFeatures, double[] exampleValues)
LinearThresholdUnit.scores(Object)
.scores
in class Learner
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.Learner.scores(Object)
public Feature featureValue(int[] f, double[] v)
FeatureVector
.featureValue
in class Learner
f
- The features array.v
- The values array.public String discreteValue(int[] exampleFeatures, double[] exampleValues)
discreteValue
in class Learner
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.public FeatureVector classify(int[] exampleFeatures, double[] exampleValues)
public Feature valueOf(Object example, Collection candidates)
String
s.example
- The example object.candidates
- A list of the only labels the example may take.null
if the network did not contain any
of the specified labels.public Feature valueOf(int[] exampleFeatures, double[] exampleValues, Collection candidates)
String
s.exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.candidates
- A list of the only labels the example may take.null
if the network did not contain any
of the specified labels.protected Feature conjunctiveValueOf(int[] exampleFeatures, double[] exampleValues, Iterator I)
valueOf(int[],double[],Collection)
when the labeler
is known to produce conjunctive features. It is necessary because when given a string label
from the collection, we will not know how to construct the appropriate conjunctive feature
key for lookup in the label lexicon. So, we must go through each feature in the label lexicon
and use Feature.valueEquals(String)
.exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.I
- An iterator over the set of labels to choose from.null
if the network did not
contain any of the specified labels.public void write(PrintStream out)
public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Copyright © 2016. All rights reserved.