public class GradientMachine extends AbstractVectorClassifier implements OnlineLearner, org.apache.hadoop.io.Writable
Modifier and Type | Field and Description |
---|---|
static int |
WRITABLE_VERSION |
MIN_LOG_LIKELIHOOD
Constructor and Description |
---|
GradientMachine(int numFeatures,
int numHidden,
int numOutput) |
Modifier and Type | Method and Description |
---|---|
Vector |
classify(Vector instance)
Compute and return a vector containing
n-1 scores, where
n is equal to numCategories() , given an input
vector instance . |
Vector |
classifyNoLink(Vector instance)
Compute and return a vector of scores before applying the inverse link
function.
|
double |
classifyScalar(Vector instance)
Classifies a vector in the special case of a binary classifier where
AbstractVectorClassifier.classify(Vector) would return a vector with only one element. |
void |
close()
Prepares the classifier for classification and deallocates any temporary data structures.
|
GradientMachine |
copy() |
void |
copyFrom(GradientMachine other) |
DenseVector |
hiddenToOutput(Vector hiddenActivation)
Feeds forward from hidden to output
|
void |
initWeights(Random gen)
Initialize weights.
|
DenseVector |
inputToHidden(Vector input)
Feeds forward from input to hidden unit..
|
GradientMachine |
learningRate(double learningRate)
Chainable configuration option.
|
int |
numCategories()
Returns the number of categories that a target variable can be assigned to.
|
int |
numFeatures() |
int |
numHidden() |
void |
readFields(DataInput in) |
GradientMachine |
regularization(double regularization)
Chainable configuration option.
|
GradientMachine |
sparsity(double sparsity)
Chainable configuration option.
|
GradientMachine |
sparsityLearningRate(double sparsityLearningRate)
Chainable configuration option.
|
void |
train(int actual,
Vector instance)
Updates the model using a particular target variable value and a feature vector.
|
void |
train(long trackingKey,
int actual,
Vector instance)
Updates the model using a particular target variable value and a feature vector.
|
void |
train(long trackingKey,
String groupKey,
int actual,
Vector instance)
Updates the model using a particular target variable value and a feature vector.
|
void |
updateRanking(Vector hiddenActivation,
Collection<Integer> goodLabels,
int numTrials,
Random gen)
Updates using ranking loss.
|
void |
write(DataOutput out) |
classify, classifyFull, classifyFull, classifyFull, classifyScalar, logLikelihood
public static final int WRITABLE_VERSION
public GradientMachine(int numFeatures, int numHidden, int numOutput)
public void initWeights(Random gen)
gen
- random number generator.public GradientMachine learningRate(double learningRate)
learningRate
- New value of initial learning rate.public GradientMachine regularization(double regularization)
regularization
- A positive value that controls the weight vector size.public GradientMachine sparsity(double sparsity)
sparsity
- A value between zero and one that controls the fraction of hidden units
that are activated on average.public GradientMachine sparsityLearningRate(double sparsityLearningRate)
sparsityLearningRate
- New value of initial learning rate for sparsity.public void copyFrom(GradientMachine other)
public int numCategories()
AbstractVectorClassifier
0
to numCategories()-1
(inclusive).numCategories
in class AbstractVectorClassifier
public int numFeatures()
public int numHidden()
public DenseVector inputToHidden(Vector input)
public DenseVector hiddenToOutput(Vector hiddenActivation)
public void updateRanking(Vector hiddenActivation, Collection<Integer> goodLabels, int numTrials, Random gen)
hiddenActivation
- the hidden unit's activationgoodLabels
- the labels you want ranked above others.numTrials
- how many times you want to search for the highest scoring bad label.gen
- Random number generator.public Vector classify(Vector instance)
AbstractVectorClassifier
n-1
scores, where
n
is equal to numCategories()
, given an input
vector instance
. Higher scores indicate that the input vector
is more likely to belong to that category. The categories are denoted by
the integers 0
through n-1
(inclusive), and the
scores in the returned vector correspond to categories 1 through
n-1
(leaving out category 0). It is assumed that the score for
category 0 is one minus the sum of the scores in the returned vector.classify
in class AbstractVectorClassifier
instance
- A feature vector to be classified.n-1
encoding.public Vector classifyNoLink(Vector instance)
AbstractVectorClassifier
The implementation of this method provided by AbstractVectorClassifier
throws an
UnsupportedOperationException
. Your subclass must explicitly override this method to support
this operation.
classifyNoLink
in class AbstractVectorClassifier
instance
- A feature vector to be classified.public double classifyScalar(Vector instance)
AbstractVectorClassifier
AbstractVectorClassifier.classify(Vector)
would return a vector with only one element. As
such, using this method can avoid the allocation of a vector.classifyScalar
in class AbstractVectorClassifier
instance
- The feature vector to be classified.AbstractVectorClassifier.classify(Vector)
public GradientMachine copy()
public void write(DataOutput out) throws IOException
write
in interface org.apache.hadoop.io.Writable
IOException
public void readFields(DataInput in) throws IOException
readFields
in interface org.apache.hadoop.io.Writable
IOException
public void close()
OnlineLearner
close
in interface Closeable
close
in interface AutoCloseable
close
in interface OnlineLearner
public void train(long trackingKey, String groupKey, int actual, Vector instance)
OnlineLearner
train
in interface OnlineLearner
trackingKey
- The tracking key for this training example.groupKey
- An optional value that allows examples to be grouped in the computation of
the update to the model.actual
- The value of the target variable. This value should be in the half-open
interval [0..n) where n is the number of target categories.instance
- The feature vector for this example.public void train(long trackingKey, int actual, Vector instance)
OnlineLearner
train
in interface OnlineLearner
trackingKey
- The tracking key for this training example.actual
- The value of the target variable. This value should be in the half-open
interval [0..n) where n is the number of target categories.instance
- The feature vector for this example.public void train(int actual, Vector instance)
OnlineLearner
train
in interface OnlineLearner
actual
- The value of the target variable. This value should be in the half-open
interval [0..n) where n is the number of target categories.instance
- The feature vector for this example.Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.