edu.stanford.nlp.optimization
Class StochasticMinimizer<T extends Function>

java.lang.Object
  extended by edu.stanford.nlp.optimization.StochasticMinimizer<T>
All Implemented Interfaces:
HasEvaluators, Minimizer<T>
Direct Known Subclasses:
ScaledSGDMinimizer, SGDMinimizer, SMDMinimizer, SQNMinimizer

public abstract class StochasticMinimizer<T extends Function>
extends Object
implements Minimizer<T>, HasEvaluators

Stochastic Gradient Descent Minimizer The basic way to use the minimizer is with a null constructor, then the simple minimize method:

Minimizer smd = new SGDMinimizer();
DiffFunction df = new SomeDiffFunction(); //Note that it must be a incidence of AbstractStochasticCachingDiffFunction
double tol = 1e-4;
double[] initial = getInitialGuess();
int maxIterations = someSafeNumber;
double[] minimum = qnm.minimize(df,tol,initial,maxIterations);

Constructing with a null constructor will use the default values of


batchSize = 15;
initialGain = 0.1;

Since:
1.0
Author:
Alex Kleeman

Nested Class Summary
static class StochasticMinimizer.InvalidElementException
           
static interface StochasticMinimizer.PropertySetter<T1>
           
 
Field Summary
protected static int bSize
           
protected  PrintWriter file
           
static double gain
           
protected  Random gen
           
protected  double[] grad
           
protected  List<double[]> gradList
           
protected  PrintWriter infoFile
           
protected  int k
           
protected  long maxTime
           
protected  int memory
           
protected  double[] newGrad
           
protected  double[] newX
           
protected  int numBatches
           
protected  int numPasses
           
 int outputFrequency
           
 boolean outputIterationsToFile
           
protected  boolean quiet
           
protected  double[] v
           
protected  double[] x
           
 
Constructor Summary
StochasticMinimizer()
           
 
Method Summary
protected  double gainSchedule(int it, double tau)
           
protected abstract  String getName()
           
protected  void init(AbstractStochasticCachingDiffFunction func)
           
 double[] minimize(Function function, double functionTolerance, double[] initial)
          Attempts to find an unconstrained minimum of the objective function starting at initial, within functionTolerance.
 double[] minimize(Function function, double functionTolerance, double[] initial, int maxIterations)
           
protected  void say(String s)
           
protected  void sayln(String s)
           
 void setEvaluators(int iters, Evaluator[] evaluators)
           
 void shutUp()
           
protected  double[] smooth(List<double[]> toSmooth)
           
protected abstract  void takeStep(AbstractStochasticCachingDiffFunction dfunction)
           
abstract  Pair<Integer,Double> tune(Function function, double[] initial, long msPerTest)
           
 Pair<Integer,Double> tune(Function function, double[] initial, long msPerTest, List<Integer> batchSizes, List<Double> gains)
           
 int tuneBatch(Function function, double[] initial, long msPerTest, int bStart)
           
 double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<Double> ps, double lower, double upper)
           
 double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<Double> ps, double lower, double upper, double TOL)
           
 double tuneGain(Function function, double[] initial, long msPerTest, double lower, double upper)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputIterationsToFile

public boolean outputIterationsToFile

outputFrequency

public int outputFrequency

gain

public static double gain

x

protected double[] x

newX

protected double[] newX

grad

protected double[] grad

newGrad

protected double[] newGrad

v

protected double[] v

numBatches

protected int numBatches

k

protected int k

bSize

protected static int bSize

quiet

protected boolean quiet

gradList

protected List<double[]> gradList

memory

protected int memory

numPasses

protected int numPasses

gen

protected Random gen

file

protected PrintWriter file

infoFile

protected PrintWriter infoFile

maxTime

protected long maxTime
Constructor Detail

StochasticMinimizer

public StochasticMinimizer()
Method Detail

shutUp

public void shutUp()

getName

protected abstract String getName()

takeStep

protected abstract void takeStep(AbstractStochasticCachingDiffFunction dfunction)

setEvaluators

public void setEvaluators(int iters,
                          Evaluator[] evaluators)
Specified by:
setEvaluators in interface HasEvaluators

gainSchedule

protected double gainSchedule(int it,
                              double tau)

smooth

protected double[] smooth(List<double[]> toSmooth)

tune

public abstract Pair<Integer,Double> tune(Function function,
                                          double[] initial,
                                          long msPerTest)

tuneDouble

public double tuneDouble(Function function,
                         double[] initial,
                         long msPerTest,
                         StochasticMinimizer.PropertySetter<Double> ps,
                         double lower,
                         double upper)

tuneDouble

public double tuneDouble(Function function,
                         double[] initial,
                         long msPerTest,
                         StochasticMinimizer.PropertySetter<Double> ps,
                         double lower,
                         double upper,
                         double TOL)

tuneGain

public double tuneGain(Function function,
                       double[] initial,
                       long msPerTest,
                       double lower,
                       double upper)

tuneBatch

public int tuneBatch(Function function,
                     double[] initial,
                     long msPerTest,
                     int bStart)

tune

public Pair<Integer,Double> tune(Function function,
                                 double[] initial,
                                 long msPerTest,
                                 List<Integer> batchSizes,
                                 List<Double> gains)

init

protected void init(AbstractStochasticCachingDiffFunction func)

minimize

public double[] minimize(Function function,
                         double functionTolerance,
                         double[] initial)
Description copied from interface: Minimizer
Attempts to find an unconstrained minimum of the objective function starting at initial, within functionTolerance.

Specified by:
minimize in interface Minimizer<T extends Function>
Parameters:
function - the objective function
functionTolerance - a double value
initial - a initial feasible point
Returns:
Unconstrained minimum of function

minimize

public double[] minimize(Function function,
                         double functionTolerance,
                         double[] initial,
                         int maxIterations)
Specified by:
minimize in interface Minimizer<T extends Function>

sayln

protected void sayln(String s)

say

protected void say(String s)


Stanford NLP Group