public class SparseMIRA extends Learner
SparseNetworkLearner
does. However, updates to these weight vectors given an
example vector x with label y are dependent on each other as follows. For each
weight vector wv corresponding to a prediction value v, a multiplier
tv is selected and used to update wv as wv
+= tv x. tv must be less than or equal to zero for all
v != y. ty must be less than or equal to one. MIRA selects these
multipliers so that they sum to 0 and so that the vector norm of all updated weight vectors
concatenated is as small as possible.
In this sparse implementation of the algorithm, weight vectors corresponding to labels and weights for features within those vectors are added as they are observed in the data. Whenever a feature is observed for the first time, its corresponding weight in any given weight vector is set to a random number, which is necessary to make this algorithm work. It must never be the case that all weight vectors are equal to each other, or updates will stop happening. To ensure that results are reproducible, the random number generator is seeded with the same seed every time.
In addition to the observed features, each weight vector also contains a bias. For this reason, we also halucinate an extra dimension on every example vector containing a feature whose strength is 1.
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 |
SparseMIRA.Parameters
Simply a container for all of
SparseMIRA 's configurable parameters. |
Modifier and Type | Field and Description |
---|---|
protected boolean |
conjunctiveLabels
Whether or not this learner's labeler produces conjunctive features.
|
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector |
network
A map from labels to the weight vector corresponding to that label.
|
static double |
TOLERANCE
Used to decide if two values are nearly equal to each other.
|
candidates, encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, lossFlag, predictions, readLexiconOnDemand
containingPackage, name
Constructor and Description |
---|
SparseMIRA()
This algorithm has no parameters to set!
|
SparseMIRA(SparseMIRA.Parameters p)
Initializing constructor.
|
SparseMIRA(String n)
This algorithm has no parameters to set!
|
SparseMIRA(String n,
SparseMIRA.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 individual weight vectors' dot
products.
|
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 individual weight vectors' dot
products.
|
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.
|
Learner.Parameters |
getParameters()
Retrieves the parameters that are set in this learner.
|
void |
learn(int[] exampleFeatures,
double[] exampleValues,
int[] exampleLabels,
double[] labelValues)
Finds the optimal multiplier settings before updating the weight vectors.
|
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 |
setLabeler(Classifier l)
Sets the labeler.
|
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, doneLearning, doneWithRound, emptyClone, featureValue, featureValue, getCurrentLexicon, getExampleArray, getExampleArray, getExtractor, getLabeler, getLabelLexicon, getLexicon, getLexiconDiscardCounts, getLexiconLocation, getModelLocation, getPrunedLexiconSize, initialize, 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, setExtractor, 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 double TOLERANCE
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector network
protected boolean conjunctiveLabels
public SparseMIRA()
public SparseMIRA(SparseMIRA.Parameters p)
p
- The settings of all parameters.public SparseMIRA(String n)
n
- The name of the classifier.public SparseMIRA(String n, SparseMIRA.Parameters p)
n
- The name of the classifier.p
- The settings of all parameters.public Learner.Parameters getParameters()
getParameters
in class Learner
public void setLabeler(Classifier l)
setLabeler
in class Learner
l
- A labeling classifier.public void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues)
public ScoreSet scores(int[] exampleFeatures, double[] exampleValues)
scores
in class Learner
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.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 ScoreSet scores(Object example, Collection candidates)
BiasedRandomWeightVector
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)
BiasedRandomWeightVector
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 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.