Class ShrinkingMatrix
java.lang.Object
org.tribuo.math.la.DenseMatrix
org.tribuo.math.optimisers.util.ShrinkingMatrix
- All Implemented Interfaces:
Serializable,Iterable<MatrixTuple>,Matrix,Tensor,ShrinkingTensor,ProtoSerializable<org.tribuo.math.protos.TensorProto>
A subclass of
DenseMatrix which shrinks the value every time a new value is added.
Be careful when modifying this or DenseMatrix.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.tribuo.math.la.DenseMatrix
DenseMatrix.CholeskyFactorization, DenseMatrix.EigenDecomposition, DenseMatrix.LUFactorizationNested classes/interfaces inherited from interface org.tribuo.math.la.Matrix
Matrix.Factorization -
Field Summary
Fields inherited from class org.tribuo.math.la.DenseMatrix
CURRENT_VERSION, dim1, dim2, FACTORIZATION_TOLERANCE, valuesFields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZERFields inherited from interface org.tribuo.math.optimisers.util.ShrinkingTensor
tolerance -
Constructor Summary
ConstructorsConstructorDescriptionShrinkingMatrix(DenseMatrix v, double baseRate, boolean scaleShrinking) Constructs a shrinking matrix copy of the supplied dense matrix.ShrinkingMatrix(DenseMatrix v, double baseRate, double lambda) Constructs a shrinking matrix copy of the supplied dense matrix. -
Method Summary
Modifier and TypeMethodDescriptionConverts the tensor into a dense tensor.static ShrinkingMatrixdeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.doubleget(int i, int j) Gets an element from thisMatrix.voidintersectAndAddInPlace(Tensor other, DoubleUnaryOperator f) Updates thisTensorby adding all the values from the intersection withother.iterator()leftMultiply(SGDVector input) Multiplies this Matrix by aSGDVectorreturning a vector of the appropriate size.voidscaleInPlace(double value) Scales each element of thisTensorbycoefficient.org.tribuo.math.protos.TensorProtoSerializes this object to a protobuf.doubletwoNorm()Calculates the euclidean norm for this vector.Methods inherited from class org.tribuo.math.la.DenseMatrix
add, add, addAcrossDim1, addAcrossDim2, broadcastIntersectAndAddInPlace, choleskyFactorization, columnSum, columnSum, copy, createDenseMatrix, createDenseMatrix, createIdentity, eigenDecomposition, equals, foreachInPlace, gatherAcrossDim1, gatherAcrossDim2, getColumn, getDimension1Size, getDimension2Size, getRow, getShape, hadamardProductInPlace, hashCode, isSquare, isSymmetric, luFactorization, matrixMultiply, matrixMultiply, normalizeRows, numActiveElements, reshape, rightMultiply, rowScaleInPlace, rowSum, rowSum, selectColumns, selectColumns, set, setColumn, toArray, toString, transpose, unpackProtoMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.tribuo.math.la.Tensor
hadamardProductInPlace, intersectAndAddInPlace, scalarAddInPlace
-
Constructor Details
-
ShrinkingMatrix
Constructs a shrinking matrix copy of the supplied dense matrix.This matrix shrinks during each call to
intersectAndAddInPlace(Tensor, DoubleUnaryOperator).- Parameters:
v- The matrix to copy.baseRate- The base amount of shrinking to apply after each update.scaleShrinking- If true reduce the shrinking value over time proportionally to the number of updates.
-
ShrinkingMatrix
Constructs a shrinking matrix copy of the supplied dense matrix.This matrix shrinks during each call to
intersectAndAddInPlace(Tensor, DoubleUnaryOperator), and then reprojects the matrix so it has the same twoNorm.- Parameters:
v- The matrix to copy.baseRate- The base rate of shrinkage.lambda- The lambda value (seePegasos).
-
-
Method Details
-
deserializeFromProto
public static ShrinkingMatrix 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.TensorProto serialize()Description copied from interface:ProtoSerializableSerializes this object to a protobuf.- Specified by:
serializein interfaceProtoSerializable<org.tribuo.math.protos.TensorProto>- Overrides:
serializein classDenseMatrix- Returns:
- The protobuf.
-
convertToDense
Description copied from interface:ShrinkingTensorConverts the tensor into a dense tensor.- Specified by:
convertToDensein interfaceShrinkingTensor- Returns:
- A dense tensor copy of this shrinking tensor.
-
leftMultiply
Description copied from interface:MatrixMultiplies this Matrix by aSGDVectorreturning a vector of the appropriate size.The input must have dimension equal to
Matrix.getDimension2Size().- Specified by:
leftMultiplyin interfaceMatrix- Overrides:
leftMultiplyin classDenseMatrix- Parameters:
input- The input vector.- Returns:
- A new
SGDVectorof sizeMatrix.getDimension1Size().
-
intersectAndAddInPlace
Description copied from interface:TensorUpdates thisTensorby adding all the values from the intersection withother.The function
fis applied to all values fromotherbefore the addition.Each value is updated as value += f(otherValue).
- Specified by:
intersectAndAddInPlacein interfaceTensor- Overrides:
intersectAndAddInPlacein classDenseMatrix- Parameters:
other- The otherTensor.f- A function to apply.
-
get
public double get(int i, int j) Description copied from interface:MatrixGets an element from thisMatrix.- Specified by:
getin interfaceMatrix- Overrides:
getin classDenseMatrix- Parameters:
i- The index for the first dimension.j- The index for the second dimension.- Returns:
- The value at matrix[i][j].
-
scaleInPlace
public void scaleInPlace(double value) Description copied from interface:TensorScales each element of thisTensorbycoefficient.- Specified by:
scaleInPlacein interfaceTensor- Parameters:
value- The coefficient of scaling.
-
twoNorm
public double twoNorm()Description copied from interface:TensorCalculates the euclidean norm for this vector.- Specified by:
twoNormin interfaceTensor- Overrides:
twoNormin classDenseMatrix- Returns:
- The euclidean norm.
-
iterator
- Specified by:
iteratorin interfaceIterable<MatrixTuple>- Overrides:
iteratorin classDenseMatrix
-