public class LinearParameters extends Object implements Parameters
Constructor and Description |
---|
LinearParameters(int numFeatures,
int numLabels)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Tensor[] |
get()
Get a reference to the underlying
Tensor array. |
Tensor[] |
getEmptyCopy()
This returns a
DenseMatrix the same size as the Parameters. |
DenseMatrix |
getWeightMatrix()
Returns the weight matrix.
|
Tensor[] |
gradients(com.oracle.labs.mlrg.olcut.util.Pair<Double,SGDVector> score,
SparseVector features)
Generate the gradients for a particular feature vector given
the loss and the per output gradients.
|
Tensor[] |
merge(Tensor[][] gradients,
int size)
Merge together an array of gradient arrays.
|
SGDVector |
predict(SparseVector example)
Generates an unnormalised prediction by leftMultiply'ing the weights with the incoming features.
|
void |
set(Tensor[] newWeights)
Set the underlying
Tensor array to newWeights. |
void |
update(Tensor[] gradients)
Apply gradients to the parameters.
|
public LinearParameters(int numFeatures, int numLabels)
numFeatures
- The number of features in the training dataset (excluding the bias).numLabels
- The number of outputs in the training dataset.public SGDVector predict(SparseVector example)
example
- A feature vectorDenseVector
containing a score for each label.public Tensor[] gradients(com.oracle.labs.mlrg.olcut.util.Pair<Double,SGDVector> score, SparseVector features)
Tensor
array.score
- The Pair returned by the objective.features
- The feature vector.Tensor
array with a single DenseSparseMatrix
containing all gradients.public Tensor[] getEmptyCopy()
DenseMatrix
the same size as the Parameters.getEmptyCopy
in interface Parameters
Tensor
array containing a single DenseMatrix
.public Tensor[] get()
Parameters
Tensor
array.get
in interface Parameters
public DenseMatrix getWeightMatrix()
public void set(Tensor[] newWeights)
Parameters
Tensor
array to newWeights.set
in interface Parameters
newWeights
- New parameters to store in this object.public void update(Tensor[] gradients)
Parameters
Tensor
is the same size as the corresponding one from the parameters.
The gradients are added to the parameters.
update
in interface Parameters
gradients
- A Tensor
array of updates, with the length equal to Parameters.get()
.length.public Tensor[] merge(Tensor[][] gradients, int size)
Parameters
Tensor
s.merge
in interface Parameters
gradients
- An array of gradient update arrays.size
- The number of elements of gradients to merge. Allows gradients to have unused elements.Tensor
array of the summed gradients.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.