Class LinearParameters
java.lang.Object
org.tribuo.math.LinearParameters
- All Implemented Interfaces:
Parameters
A Parameters for producing single label linear models.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTensor[]
get()
Get a reference to the underlyingTensor
array.Tensor[]
This returns aDenseMatrix
the same size as the Parameters.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 together an array of gradient arrays.predict
(SparseVector example) Generates an unnormalised prediction by leftMultiply'ing the weights with the incoming features.void
Set the underlyingTensor
array to newWeights.void
Apply gradients to the parameters.
-
Constructor Details
-
LinearParameters
Constructor. The number of features and the number of outputs must be fixed and known in advance.- Parameters:
numFeatures
- The number of features in the training dataset (excluding the bias).numLabels
- The number of outputs in the training dataset.
-
-
Method Details
-
predict
Generates an unnormalised prediction by leftMultiply'ing the weights with the incoming features.- Parameters:
example
- A feature vector- Returns:
- A
DenseVector
containing a score for each label.
-
gradients
public 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. This parameters returns a single elementTensor
array.- Parameters:
score
- The Pair returned by the objective.features
- The feature vector.- Returns:
- A
Tensor
array with a singleDenseSparseMatrix
containing all gradients.
-
getEmptyCopy
This returns aDenseMatrix
the same size as the Parameters.- Specified by:
getEmptyCopy
in interfaceParameters
- Returns:
- A
Tensor
array containing a singleDenseMatrix
.
-
get
Description copied from interface:Parameters
Get a reference to the underlyingTensor
array.- Specified by:
get
in interfaceParameters
- Returns:
- The parameters.
-
getWeightMatrix
-
set
Description copied from interface:Parameters
Set the underlyingTensor
array to newWeights.- Specified by:
set
in interfaceParameters
- Parameters:
newWeights
- New parameters to store in this object.
-
update
Description copied from interface:Parameters
Apply gradients to the parameters. Assumes that gradients is the same length as the parameters, and eachTensor
is the same size as the corresponding one from the parameters.The gradients are added to the parameters.
- Specified by:
update
in interfaceParameters
- Parameters:
gradients
- ATensor
array of updates, with the length equal toParameters.get()
.length.
-
merge
Description copied from interface:Parameters
Merge together an array of gradient arrays. Assumes the first dimension is the number of gradient arrays and the second dimension is the number of parameterTensor
s.- Specified by:
merge
in interfaceParameters
- Parameters:
gradients
- An array of gradient update arrays.size
- The number of elements of gradients to merge. Allows gradients to have unused elements.- Returns:
- A single
Tensor
array of the summed gradients.
-