Class ShrinkingVector
java.lang.Object
org.tribuo.math.la.DenseVector
org.tribuo.math.optimisers.util.ShrinkingVector
- All Implemented Interfaces:
Serializable,Iterable<VectorTuple>,SGDVector,Tensor,ShrinkingTensor
A subclass of
DenseVector which shrinks the value every time a new value is added.
Be careful when modifying this or DenseVector.
- See Also:
-
Field Summary
Fields inherited from class org.tribuo.math.la.DenseVector
elementsFields inherited from interface org.tribuo.math.optimisers.util.ShrinkingTensor
tolerance -
Constructor Summary
ConstructorsConstructorDescriptionShrinkingVector(DenseVector v, double baseRate, boolean scaleShrinking) Constructs a shrinking vector copy of the supplied dense matrix.ShrinkingVector(DenseVector v, double baseRate, double lambda) Constructs a shrinking vector copy of the supplied dense vector. -
Method Summary
Modifier and TypeMethodDescriptionConverts the tensor into a dense tensor.copy()Returns a deep copy of this vector.doubleCalculates the dot product between this vector andother.doubleget(int index) Gets an element from this vector.intReturns the index of the maximum value.voidintersectAndAddInPlace(Tensor other, DoubleUnaryOperator f) Updates thisTensorby adding all the values from the intersection withother.iterator()doublemaxValue()Returns the maximum value.doubleminValue()Returns the minimum value.voidscaleInPlace(double value) Scales each element of thisTensorbycoefficient.doublesum()Calculates the sum of this vector.double[]toArray()Generates a copy of the values in this DenseVector.doubletwoNorm()Calculates the euclidean norm for this vector.Methods inherited from class org.tribuo.math.la.DenseVector
add, add, createDenseVector, createDenseVector, equals, euclideanDistance, expNormalize, fill, foreachIndexedInPlace, foreachInPlace, getShape, hadamardProductInPlace, hashCode, l1Distance, normalize, numActiveElements, oneNorm, outer, reduce, reshape, scale, set, setElements, size, sparsify, sparsify, subtract, sum, toString, varianceMethods 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.SGDVector
cosineDistance, cosineSimilarity, l2Distance, varianceMethods inherited from interface org.tribuo.math.la.Tensor
hadamardProductInPlace, intersectAndAddInPlace, scalarAddInPlace
-
Constructor Details
-
ShrinkingVector
Constructs a shrinking vector copy of the supplied dense matrix.This vector shrinks during each call to
intersectAndAddInPlace(Tensor, DoubleUnaryOperator).- Parameters:
v- The vector 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.
-
ShrinkingVector
Constructs a shrinking vector copy of the supplied dense vector.This vector shrinks during each call to
intersectAndAddInPlace(Tensor, DoubleUnaryOperator), and then reprojects the vector so it has the same twoNorm.- Parameters:
v- The vector to copy.baseRate- The base rate of shrinkage.lambda- The lambda value (seePegasos).
-
-
Method Details
-
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.
-
copy
Description copied from interface:SGDVectorReturns a deep copy of this vector. -
toArray
public double[] toArray()Description copied from class:DenseVectorGenerates a copy of the values in this DenseVector.This implementation uses Arrays.copyOf, and should be overridden if the get function has been modified.
- Specified by:
toArrayin interfaceSGDVector- Overrides:
toArrayin classDenseVector- Returns:
- A copy of the values in this DenseVector.
-
get
public double get(int index) Description copied from interface:SGDVectorGets an element from this vector.- Specified by:
getin interfaceSGDVector- Overrides:
getin classDenseVector- Parameters:
index- The index of the element.- Returns:
- The value at that index.
-
sum
public double sum()Description copied from interface:SGDVectorCalculates the sum of this vector.- Specified by:
sumin interfaceSGDVector- Overrides:
sumin classDenseVector- Returns:
- The sum.
-
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 classDenseVector- Parameters:
other- The otherTensor.f- A function to apply.
-
indexOfMax
public int indexOfMax()Description copied from interface:SGDVectorReturns the index of the maximum value. Requires probing the array.- Specified by:
indexOfMaxin interfaceSGDVector- Overrides:
indexOfMaxin classDenseVector- Returns:
- The index of the maximum value.
-
dot
-
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
-
maxValue
public double maxValue()Description copied from interface:SGDVectorReturns the maximum value. Requires probing the array.- Specified by:
maxValuein interfaceSGDVector- Overrides:
maxValuein classDenseVector- Returns:
- The maximum value.
-
minValue
public double minValue()Description copied from interface:SGDVectorReturns the minimum value. Requires probing the array.- Specified by:
minValuein interfaceSGDVector- Overrides:
minValuein classDenseVector- Returns:
- The minimum value.
-
iterator
- Specified by:
iteratorin interfaceIterable<VectorTuple>- Overrides:
iteratorin classDenseVector
-