public class CRFLogConditionalObjectiveFunction extends AbstractStochasticCachingDiffUpdateFunction implements HasCliquePotentialFunction, HasFeatureGrouping
AbstractStochasticCachingDiffFunction.SamplingMethod
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
backgroundSymbol |
protected Index<java.lang.String> |
classIndex |
protected CliquePotentialFunction |
cliquePotentialFunc |
static boolean |
CONDENSE |
protected int[][][][] |
data |
static boolean |
DEBUG2 |
static boolean |
DEBUG3 |
protected int |
domainDimension |
static int |
DROPOUT_PRIOR |
protected double[][] |
E |
protected double[][] |
Ehat |
protected double |
epsilon |
protected int[][] |
featureGrouping |
protected double[][][][] |
featureVal |
static int |
HUBER_PRIOR |
protected java.util.List<Index<CRFLabel>> |
labelIndices
label indices - for all possible label sequences - for each feature
|
protected int[][] |
labels |
protected int[] |
map |
protected int |
multiThreadGrad |
static int |
NO_PRIOR |
protected int |
numClasses |
protected double[][][] |
parallelE |
protected double[][][] |
parallelEhat |
protected int |
prior |
static int |
QUADRATIC_PRIOR |
static int |
QUARTIC_PRIOR |
protected java.util.Random |
rand |
protected double |
sigma |
protected static double |
smallConst |
static boolean |
TIMED |
static boolean |
VERBOSE |
protected int[][] |
weightIndices |
protected double[][] |
weights |
protected int |
window |
skipValCalc
allIndices, curElement, finiteDifferenceStepSize, gradPerturbed, hasNewVals, HdotV, lastBatch, lastBatchSize, lastElement, lastVBatch, lastXBatch, method, randGenerator, recalculatePrevBatch, returnPreviousValues, sampleMethod, scaleUp, thisBatch, xPerturbed
derivative, value
Modifier and Type | Method and Description |
---|---|
protected void |
applyPrior(double[] x,
double batchScale) |
void |
calculate(double[] x)
Calculates both value and partial derivatives at the point x, and save them internally.
|
void |
calculateStochastic(double[] x,
double[] v,
int[] batch)
calculateStochastic needs to calculate a stochastic approximation to the derivative and value of
of a function for a given batch of the data.
|
void |
calculateStochasticGradient(double[] x,
int[] batch)
Performs stochastic gradient update based
on samples indexed by batch, but does not apply regularization.
|
double |
calculateStochasticUpdate(double[] x,
double xScale,
int[] batch,
double gScale)
Performs stochastic update of weights x (scaled by xScale) based
on samples indexed by batch.
|
static double[][] |
clear2D(double[][] arr2D) |
protected static void |
combine2DArr(double[][] combineInto,
double[][] toBeCombined) |
protected static void |
combine2DArr(double[][] combineInto,
double[][] toBeCombined,
double scale) |
protected static void |
combine2DArr(double[][] combineInto,
java.util.Map<java.lang.Integer,double[]> toBeCombined) |
protected static void |
combine2DArr(double[][] combineInto,
java.util.Map<java.lang.Integer,double[]> toBeCombined,
double scale) |
int |
dataDimension()
Data dimension must return the size of the data used by the function.
|
protected void |
documentExpectedCounts(double[][] E,
int[][][] docData,
double[][][] featureVal3DArr,
CRFCliqueTree<java.lang.String> cliqueTree)
Compute the expected counts for this document, which we will need to compute the derivative.
|
int |
domainDimension()
Returns the number of dimensions in the function's domain
|
protected void |
empiricalCounts(double[][] eHat) |
protected void |
empiricalCountsForADoc(double[][] eHat,
int docIndex) |
protected double[][] |
empty2D() |
protected double |
expectedAndEmpiricalCountsAndValueForADoc(double[][] E,
double[][] Ehat,
int docIndex) |
protected double |
expectedCountsAndValueForADoc(double[][] E,
int docIndex) |
protected double |
expectedCountsAndValueForADoc(double[][] E,
int docIndex,
boolean doExpectedCountCalc,
boolean doValueCalc) |
protected double |
expectedCountsForADoc(double[][] E,
int docIndex) |
CliquePotentialFunction |
getCliquePotentialFunction(double[] x) |
protected Pair<double[][][],double[][][]> |
getCondProbs(CRFCliqueTree<java.lang.String> cTree,
int[][][] docData) |
int[][] |
getFeatureGrouping() |
int[][] |
getLabels() |
static int |
getPriorType(java.lang.String priorTypeStr) |
int[][] |
getWeightIndices() |
double[] |
initial()
Returns the intitial point in the domain (but not necessarily a feasible one).
|
double[] |
initial(boolean useRandomSeed) |
double[] |
initial(java.util.Random randGen) |
protected double |
multiThreadGradient(int[] docIDs,
boolean calculateEmpirical) |
protected double |
regularGradientAndValue() |
void |
setFeatureGrouping(int[][] fg) |
void |
setWeights(double[][] weights) |
double[] |
to1D(double[][] weights) |
static void |
to1D(double[][] weights,
double[] newWeights) |
static double[] |
to1D(double[][] weights,
int domainDimension) |
double[][] |
to2D(double[] weights) |
void |
to2D(double[] weights1D,
double[][] newWeights) |
static double[][] |
to2D(double[] weights,
java.util.List<Index<CRFLabel>> labelIndices,
int[] map)
Takes a double array of weights and creates a 2D array where:
the first element is the mapped index of the clique size (e.g., node-0, edge-1) matching featuresIndex i
the second element is the number of output classes for that clique size
|
static void |
to2D(double[] weights,
java.util.List<Index<CRFLabel>> labelIndices,
int[] map,
double[][] newWeights)
Takes a double array of weights and populates a 2D array where:
the first element is the mapped index of the clique size (e.g., node-0, edge-1) matching featuresIndex i
the second element is the number of output classes for that clique size
|
float[][] |
to2Dfloat(double[] weights) |
double |
valueAt(double[] x,
double xScale,
int[] batch)
Computes value of function for specified value of x (scaled by xScale)
only over samples indexed by batch.
|
double |
valueForADoc(int docIndex) |
calculateStochasticGradient, calculateStochasticUpdate, getSample, valueAt
clearCache, decrementBatch, derivativeAt, derivativeAt, getBatch, HdotVAt, HdotVAt, HdotVAt, incrementBatch, incrementRandom, lastDerivative, lastValue, scaleUp, valueAt, valueAt
copy, derivativeAt, ensure, getDerivative, gradientCheck, gradientCheck, randomInitial, valueAt
public static final int NO_PRIOR
public static final int QUADRATIC_PRIOR
public static final int HUBER_PRIOR
public static final int QUARTIC_PRIOR
public static final int DROPOUT_PRIOR
public static final boolean DEBUG2
public static final boolean DEBUG3
public static final boolean TIMED
public static final boolean CONDENSE
public static boolean VERBOSE
protected final int prior
protected final double sigma
protected final double epsilon
protected final java.util.List<Index<CRFLabel>> labelIndices
protected final Index<java.lang.String> classIndex
protected final double[][] Ehat
protected final double[][] E
protected double[][][] parallelE
protected double[][][] parallelEhat
protected final int window
protected final int numClasses
protected final int[] map
protected int[][][][] data
protected double[][][][] featureVal
protected int[][] labels
protected final int domainDimension
protected int[][] weightIndices
protected final java.lang.String backgroundSymbol
protected int[][] featureGrouping
protected static final double smallConst
protected java.util.Random rand
protected final int multiThreadGrad
protected double[][] weights
protected CliquePotentialFunction cliquePotentialFunc
public double[] initial()
HasInitial
initial
in interface HasInitial
initial
in class AbstractStochasticCachingDiffFunction
public double[] initial(boolean useRandomSeed)
public double[] initial(java.util.Random randGen)
public static int getPriorType(java.lang.String priorTypeStr)
protected void empiricalCounts(double[][] eHat)
protected void empiricalCountsForADoc(double[][] eHat, int docIndex)
public CliquePotentialFunction getCliquePotentialFunction(double[] x)
getCliquePotentialFunction
in interface HasCliquePotentialFunction
protected double expectedAndEmpiricalCountsAndValueForADoc(double[][] E, double[][] Ehat, int docIndex)
public double valueForADoc(int docIndex)
protected double expectedCountsAndValueForADoc(double[][] E, int docIndex)
protected double expectedCountsForADoc(double[][] E, int docIndex)
protected double expectedCountsAndValueForADoc(double[][] E, int docIndex, boolean doExpectedCountCalc, boolean doValueCalc)
protected void documentExpectedCounts(double[][] E, int[][][] docData, double[][][] featureVal3DArr, CRFCliqueTree<java.lang.String> cliqueTree)
public void setWeights(double[][] weights)
protected double regularGradientAndValue()
protected double multiThreadGradient(int[] docIDs, boolean calculateEmpirical)
public void calculate(double[] x)
calculate
in class AbstractCachingDiffFunction
x
- The point at which to calculate the functionpublic int dataDimension()
AbstractStochasticCachingDiffFunction
dataDimension
in class AbstractStochasticCachingDiffFunction
public void calculateStochastic(double[] x, double[] v, int[] batch)
AbstractStochasticCachingDiffFunction
derivative
, the approximation to the value in value
and the approximation to the Hessian vector product H.v in the array HdotV
. Note
that the hessian vector product is used primarily with the Stochastic Meta Descent optimization
routine SMDMinimizer
.
Important: The stochastic approximation must be such that the sum of all stochastic calculations over each of the batches in the data must equal the full calculation. i.e. for a data set of size 100 the sum of the gradients for batches 1-10 , 11-20 , 21-30 .... 91-100 must be the same as the gradient for the full calculation (at the very least in expectation). Be sure to take into account the priors.
calculateStochastic
in class AbstractStochasticCachingDiffFunction
x
- Value to evaluate atv
- The vector for the Hessian vector product H.vbatch
- An array containing the indices of the data to use in the calculation, this array is being calculated
internal to the abstract, and only needs to be handled not generated by the implementation.public double calculateStochasticUpdate(double[] x, double xScale, int[] batch, double gScale)
calculateStochasticUpdate
in class AbstractStochasticCachingDiffUpdateFunction
x
- - unscaled weightsxScale
- - how much to scale x by when performing calculationsbatch
- - indices of which samples to compute function overgScale
- - how much to scale adjustments to xpublic void calculateStochasticGradient(double[] x, int[] batch)
calculateStochasticGradient
in class AbstractStochasticCachingDiffUpdateFunction
x
- - unscaled weightsbatch
- - indices of which samples to compute function overpublic double valueAt(double[] x, double xScale, int[] batch)
valueAt
in class AbstractStochasticCachingDiffUpdateFunction
x
- - unscaled weightsxScale
- - how much to scale x by when performing calculationsbatch
- - indices of which samples to compute function overpublic int[][] getFeatureGrouping()
getFeatureGrouping
in interface HasFeatureGrouping
public void setFeatureGrouping(int[][] fg)
protected void applyPrior(double[] x, double batchScale)
protected Pair<double[][][],double[][][]> getCondProbs(CRFCliqueTree<java.lang.String> cTree, int[][][] docData)
protected static void combine2DArr(double[][] combineInto, double[][] toBeCombined, double scale)
protected static void combine2DArr(double[][] combineInto, double[][] toBeCombined)
protected static void combine2DArr(double[][] combineInto, java.util.Map<java.lang.Integer,double[]> toBeCombined)
protected static void combine2DArr(double[][] combineInto, java.util.Map<java.lang.Integer,double[]> toBeCombined, double scale)
public int domainDimension()
Function
domainDimension
in interface Function
public static double[][] to2D(double[] weights, java.util.List<Index<CRFLabel>> labelIndices, int[] map)
public double[][] to2D(double[] weights)
public float[][] to2Dfloat(double[] weights)
public static void to2D(double[] weights, java.util.List<Index<CRFLabel>> labelIndices, int[] map, double[][] newWeights)
public void to2D(double[] weights1D, double[][] newWeights)
public static double[][] clear2D(double[][] arr2D)
public static void to1D(double[][] weights, double[] newWeights)
public static double[] to1D(double[][] weights, int domainDimension)
public double[] to1D(double[][] weights)
public int[][] getWeightIndices()
protected double[][] empty2D()
public int[][] getLabels()