Class LinearParameters
java.lang.Object
org.tribuo.math.LinearParameters
- All Implemented Interfaces:
Serializable,FeedForwardParameters,Parameters,ProtoSerializable<org.tribuo.math.protos.ParametersProto>
A
Parameters for producing linear models.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
ConstructorsConstructorDescriptionLinearParameters(int numFeatures, int numLabels) Constructor.LinearParameters(DenseMatrix weightMatrix) Constructs a LinearParameters wrapped around a weight matrix. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a copy of the parameters.static LinearParametersdeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.booleanTensor[]get()Get a reference to the underlyingTensorarray.Tensor[]This returns aDenseMatrixthe same size as the Parameters.Returns the weight matrix.Tensor[]Generate the gradients for a particular feature vector given the loss and the per output gradients.inthashCode()Tensor[]Merge together an array of gradient arrays.Generates an unnormalised prediction by leftMultiply'ing the weights with the incoming features.org.tribuo.math.protos.ParametersProtoSerializes this object to a protobuf.voidSet the underlyingTensorarray to newWeights.voidApply gradients to the parameters.
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
-
Constructor Details
-
LinearParameters
public LinearParameters(int numFeatures, int numLabels) 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.
-
LinearParameters
Constructs a LinearParameters wrapped around a weight matrix.Used for serialization compatibility with Tribuo 4.0.
- Parameters:
weightMatrix- The weight matrix to wrap.
-
-
Method Details
-
deserializeFromProto
public static LinearParameters deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version- The serialized object version.className- The class name.message- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException- If the protobuf could not be parsed from themessage.
-
serialize
public org.tribuo.math.protos.ParametersProto serialize()Description copied from interface:ProtoSerializableSerializes this object to a protobuf.- Specified by:
serializein interfaceProtoSerializable<org.tribuo.math.protos.ParametersProto>- Returns:
- The protobuf.
-
predict
Generates an unnormalised prediction by leftMultiply'ing the weights with the incoming features.- Specified by:
predictin interfaceFeedForwardParameters- Parameters:
example- A feature vector- Returns:
- A
DenseVectorcontaining a score for each label.
-
gradients
public 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. This parameters returns a single elementTensorarray.- Specified by:
gradientsin interfaceFeedForwardParameters- Parameters:
score- The Pair returned by the objective.features- The feature vector.- Returns:
- A
Tensorarray with a singleMatrixcontaining all gradients.
-
getEmptyCopy
This returns aDenseMatrixthe same size as the Parameters.- Specified by:
getEmptyCopyin interfaceParameters- Returns:
- A
Tensorarray containing a singleDenseMatrix.
-
get
Description copied from interface:ParametersGet a reference to the underlyingTensorarray.- Specified by:
getin interfaceParameters- Returns:
- The parameters.
-
getWeightMatrix
-
set
Description copied from interface:ParametersSet the underlyingTensorarray to newWeights.- Specified by:
setin interfaceParameters- Parameters:
newWeights- New parameters to store in this object.
-
update
Description copied from interface:ParametersApply gradients to the parameters. Assumes that gradients is the same length as the parameters, and eachTensoris the same size as the corresponding one from the parameters.The gradients are added to the parameters.
- Specified by:
updatein interfaceParameters- Parameters:
gradients- ATensorarray of updates, with the length equal toParameters.get().length.
-
merge
Description copied from interface:ParametersMerge together an array of gradient arrays. Assumes the first dimension is the number of gradient arrays and the second dimension is the number of parameterTensors.For performance reasons this call may mutate the input gradient array, and may return a subset of those elements as the merge output.
- Specified by:
mergein 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
Tensorarray of the summed gradients.
-
copy
Description copied from interface:FeedForwardParametersReturns a copy of the parameters.- Specified by:
copyin interfaceFeedForwardParameters- Returns:
- A copy of the model parameters.
-
equals
-
hashCode
-