Package cc.mallet.fst

Class ThreadedOptimizable

    • Field Detail

      • 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
    • 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 parallelized
        numFactors - Number of factors in model's parameters, used to initialize the gradient
        cacheIndicator - Determines when value/gradient become stale
    • Method Detail

      • 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.

      • 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 interface Optimizable.ByGradientValue
      • createTasks

        protected void createTasks()
        Creates tasks to be executed in parallel, each task looks at a batch of data.
      • setParameter

        public void setParameter​(int index,
                                 double value)
        Specified by:
        setParameter in interface Optimizable