Package org.tribuo.common.sgd
Class FMParameters
java.lang.Object
org.tribuo.common.sgd.FMParameters
- All Implemented Interfaces:
Serializable
,FeedForwardParameters
,Parameters
,ProtoSerializable<org.tribuo.math.protos.ParametersProto>
A
Parameters
for factorization machines.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionFMParameters
(SplittableRandom rng, int numFeatures, int numLabels, int numFactors, double variance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Returns a copy of the parameters.static FMParameters
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.Tensor[]
get()
Get a reference to the underlyingTensor
array.Tensor[]
This returns aDenseMatrix
the same size as the Parameters.Tensor[]
Generate the gradients for a particular feature vector given the loss and the per output gradients.Tensor[]
Merge together an array of gradient arrays.Generates an unnormalised prediction by multiplying the weights with the incoming features, adding the bias and adding the feature factors.org.tribuo.math.protos.ParametersProto
Serializes this object to a protobuf.void
Set the underlyingTensor
array to newWeights.void
Apply gradients to the parameters.
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
-
Constructor Details
-
FMParameters
public FMParameters(SplittableRandom rng, int numFeatures, int numLabels, int numFactors, double variance) Constructor. The number of features and the number of outputs must be fixed and known in advance.- Parameters:
rng
- The RNG to use for initialization.numFeatures
- The number of features in the training dataset.numLabels
- The number of outputs in the training dataset.numFactors
- The size of the factorized feature representation.variance
- The variance of the factor initializer.
-
-
Method Details
-
deserializeFromProto
public static FMParameters 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:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<org.tribuo.math.protos.ParametersProto>
- Returns:
- The protobuf.
-
predict
Generates an unnormalised prediction by multiplying the weights with the incoming features, adding the bias and adding the feature factors.- Specified by:
predict
in interfaceFeedForwardParameters
- 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, SGDVector features) Generate the gradients for a particular feature vector given the loss and the per output gradients.This method returns a
Tensor
array with numLabels + 2 elements.- Specified by:
gradients
in interfaceFeedForwardParameters
- Parameters:
score
- The Pair returned by the objective.features
- The feature vector.- Returns:
- A
Tensor
array containing all the 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.
-
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.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:
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.
-
copy
Description copied from interface:FeedForwardParameters
Returns a copy of the parameters.- Specified by:
copy
in interfaceFeedForwardParameters
- Returns:
- A copy of the model parameters.
-