public static class FunctionGradient.SparseGradient extends java.lang.Object implements FunctionGradient
FunctionGradient that only explicitly stores
 the partial derivative for parameters with non-zero partial derivatives. The partial derivative for parameters
 not explicitly stored will have a value of zero returned.FunctionGradient.PartialDerivative, FunctionGradient.SparseGradient| Modifier and Type | Field and Description | 
|---|---|
protected java.util.Map<java.lang.Integer,java.lang.Double> | 
gradient
A map from weight identifiers to their partial derivative 
 | 
| Constructor and Description | 
|---|
SparseGradient()
Initializes with the gradient unspecified for any weights. 
 | 
SparseGradient(int capacity)
Initializes with the gradient unspecified, but reserves space for the given capacity 
 | 
| Modifier and Type | Method and Description | 
|---|---|
java.util.Set<FunctionGradient.PartialDerivative> | 
getNonZeroPartialDerivatives()
Returns all non-zero partial derivatives. 
 | 
double | 
getPartialDerivative(int parameterId)
Returns the partial derivative for the given weight 
 | 
int | 
numNonZeroPDs()
Returns the number of non-zero partial derivatives 
 | 
void | 
put(int parameterId,
   double partialDerivative)
Adds the partial derivative for a given weight 
 | 
protected java.util.Map<java.lang.Integer,java.lang.Double> gradient
public SparseGradient()
public SparseGradient(int capacity)
capacity - how much space to reserve for storing the gradient; i.e., the number of weights over which the gradient will be definedpublic void put(int parameterId,
                double partialDerivative)
FunctionGradientput in interface FunctionGradientparameterId - the parameter identifier for which the partial derivative is to be stored.partialDerivative - the partial derivative value for the parameterpublic double getPartialDerivative(int parameterId)
FunctionGradientgetPartialDerivative in interface FunctionGradientparameterId - the parameter for which the partial derivative will be returnedpublic java.util.Set<FunctionGradient.PartialDerivative> getNonZeroPartialDerivatives()
FunctionGradientMap.Entry where
 the key is an Integer of the parameter identifier and the value is a double specifying its partial
 derivative.getNonZeroPartialDerivatives in interface FunctionGradientpublic int numNonZeroPDs()
FunctionGradientnumNonZeroPDs in interface FunctionGradient