public class LinearParameters extends Object implements FeedForwardParameters
Parameters
for producing linear models.Constructor and Description |
---|
LinearParameters(DenseMatrix weightMatrix)
Constructs a LinearParameters wrapped around a weight matrix.
|
LinearParameters(int numFeatures,
int numLabels)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
LinearParameters |
copy()
Returns a copy of the parameters.
|
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,
SGDVector 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.
|
DenseVector |
predict(SGDVector 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 LinearParameters(DenseMatrix weightMatrix)
Used for serialization compatibility with Tribuo 4.0.
weightMatrix
- The weight matrix to wrap.public DenseVector predict(SGDVector example)
predict
in interface FeedForwardParameters
example
- A feature vectorDenseVector
containing a score for each label.public Tensor[] gradients(com.oracle.labs.mlrg.olcut.util.Pair<Double,SGDVector> score, SGDVector features)
Tensor
array.gradients
in interface FeedForwardParameters
score
- The Pair returned by the objective.features
- The feature vector.Tensor
array with a single Matrix
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.public LinearParameters copy()
FeedForwardParameters
copy
in interface FeedForwardParameters
Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.