Package cc.mallet.fst
Class ThreadedOptimizable
- java.lang.Object
-
- cc.mallet.fst.ThreadedOptimizable
-
- All Implemented Interfaces:
Optimizable
,Optimizable.ByGradientValue
public class ThreadedOptimizable extends java.lang.Object implements Optimizable.ByGradientValue
An adaptor for optimizables based on batch values/gradients.Computes values, gradients for each batch in multiple threads and combines them in the end.
- Author:
- Gaurav Chandalia
- See Also:
CRFOptimizableByBatchLabelLikelihood
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cc.mallet.optimize.Optimizable
Optimizable.ByBatchGradient, Optimizable.ByCombiningBatchGradient, Optimizable.ByGISUpdate, Optimizable.ByGradient, Optimizable.ByGradientValue, Optimizable.ByHessian, Optimizable.ByValue, Optimizable.ByVotedPerceptron
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<double[]>
batchCachedGradient
Gradient obtained from the optimizable for each batchprotected double[]
batchCachedValue
Value obtained from the optimizable for each batchprotected CacheStaleIndicator
cacheIndicator
protected Optimizable.ByCombiningBatchGradient
optimizable
optimizable to be parallelizedstatic int
SLEEP_TIME
protected InstanceList
trainingSet
Data
-
Constructor Summary
Constructors Constructor Description ThreadedOptimizable(Optimizable.ByCombiningBatchGradient optimizable, InstanceList trainingSet, int numFactors, CacheStaleIndicator cacheIndicator)
Initializes the optimizable and starts new threads.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createTasks()
Creates tasks to be executed in parallel, each task looks at a batch of data.int
getNumParameters()
Optimizable.ByCombiningBatchGradient
getOptimizable()
double
getParameter(int index)
void
getParameters(double[] buffer)
double
getValue()
void
getValueGradient(double[] buffer)
Returns the gradient, re-computes if gradient is stale.void
setParameter(int index, double value)
void
setParameters(double[] buff)
void
shutdown()
Shuts down the executor used to start and run threads to compute values and gradients.
-
-
-
Field Detail
-
trainingSet
protected InstanceList trainingSet
Data
-
optimizable
protected Optimizable.ByCombiningBatchGradient optimizable
optimizable to be parallelized
-
batchCachedValue
protected double[] batchCachedValue
Value obtained from the optimizable for each batch
-
batchCachedGradient
protected java.util.List<double[]> batchCachedGradient
Gradient obtained from the optimizable for each batch
-
cacheIndicator
protected CacheStaleIndicator cacheIndicator
-
SLEEP_TIME
public static final int SLEEP_TIME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ThreadedOptimizable
public ThreadedOptimizable(Optimizable.ByCombiningBatchGradient optimizable, InstanceList trainingSet, int numFactors, CacheStaleIndicator cacheIndicator)
Initializes the optimizable and starts new threads.- Parameters:
optimizable
- Optimizable to be parallelizednumFactors
- Number of factors in model's parameters, used to initialize the gradientcacheIndicator
- Determines when value/gradient become stale
-
-
Method Detail
-
getOptimizable
public Optimizable.ByCombiningBatchGradient getOptimizable()
-
shutdown
public void shutdown()
Shuts down the executor used to start and run threads to compute values and gradients.*Note*: For a clean exit of all the threads, it is recommended to call this method after training finishes.
-
getValue
public double getValue()
- Specified by:
getValue
in interfaceOptimizable.ByGradientValue
-
getValueGradient
public void getValueGradient(double[] buffer)
Returns the gradient, re-computes if gradient is stale.*Note*: Assumes that buffer is already initialized.
- Specified by:
getValueGradient
in interfaceOptimizable.ByGradientValue
-
createTasks
protected void createTasks()
Creates tasks to be executed in parallel, each task looks at a batch of data.
-
getNumParameters
public int getNumParameters()
- Specified by:
getNumParameters
in interfaceOptimizable
-
getParameters
public void getParameters(double[] buffer)
- Specified by:
getParameters
in interfaceOptimizable
-
getParameter
public double getParameter(int index)
- Specified by:
getParameter
in interfaceOptimizable
-
setParameters
public void setParameters(double[] buff)
- Specified by:
setParameters
in interfaceOptimizable
-
setParameter
public void setParameter(int index, double value)
- Specified by:
setParameter
in interfaceOptimizable
-
-