public abstract class StochasticMinimizer<T extends Function> extends java.lang.Object implements Minimizer<T>, HasEvaluators
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;
Modifier and Type | Class and Description |
---|---|
static interface |
StochasticMinimizer.PropertySetter<T1> |
Modifier and Type | Field and Description |
---|---|
protected int |
bSize |
protected java.io.PrintWriter |
file |
double |
gain |
protected java.util.Random |
gen |
protected double[] |
grad |
protected java.util.List<double[]> |
gradList |
protected java.io.PrintWriter |
infoFile |
protected int |
k |
protected long |
maxTime |
protected int |
memory |
protected double[] |
newGrad |
protected double[] |
newX |
protected static java.text.NumberFormat |
nf |
protected int |
numBatches |
protected int |
numPasses |
int |
outputFrequency |
boolean |
outputIterationsToFile |
protected boolean |
quiet |
protected double[] |
v |
protected double[] |
x |
Constructor and Description |
---|
StochasticMinimizer() |
Modifier and Type | Method and Description |
---|---|
protected static double |
gainSchedule(int it,
double tau) |
protected abstract java.lang.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 , accurate to
within functionTolerance (normally implemented as
a multiplier of the range value to give range tolerance). |
double[] |
minimize(Function function,
double functionTolerance,
double[] initial,
int maxIterations)
Attempts to find an unconstrained minimum of the objective
function starting at initial , accurate to
within functionTolerance (normally implemented as
a multiplier of the range value to give range tolerance), but
running only for at most maxIterations iterations. |
protected void |
say(java.lang.String s) |
protected void |
sayln(java.lang.String s) |
void |
setEvaluators(int iters,
Evaluator[] evaluators) |
void |
shutUp() |
protected static double[] |
smooth(java.util.List<double[]> toSmooth) |
protected abstract void |
takeStep(AbstractStochasticCachingDiffFunction dfunction) |
abstract Pair<java.lang.Integer,java.lang.Double> |
tune(Function function,
double[] initial,
long msPerTest) |
Pair<java.lang.Integer,java.lang.Double> |
tune(Function function,
double[] initial,
long msPerTest,
java.util.List<java.lang.Integer> batchSizes,
java.util.List<java.lang.Double> gains) |
int |
tuneBatch(Function function,
double[] initial,
long msPerTest,
int bStart) |
double |
tuneDouble(Function function,
double[] initial,
long msPerTest,
StochasticMinimizer.PropertySetter<java.lang.Double> ps,
double lower,
double upper) |
double |
tuneDouble(Function function,
double[] initial,
long msPerTest,
StochasticMinimizer.PropertySetter<java.lang.Double> ps,
double lower,
double upper,
double TOL) |
double |
tuneGain(Function function,
double[] initial,
long msPerTest,
double lower,
double upper) |
public boolean outputIterationsToFile
public int outputFrequency
public double gain
protected double[] x
protected double[] newX
protected double[] grad
protected double[] newGrad
protected double[] v
protected int numBatches
protected int k
protected int bSize
protected boolean quiet
protected java.util.List<double[]> gradList
protected int memory
protected int numPasses
protected java.util.Random gen
protected java.io.PrintWriter file
protected java.io.PrintWriter infoFile
protected long maxTime
protected static final java.text.NumberFormat nf
public void shutUp()
protected abstract java.lang.String getName()
protected abstract void takeStep(AbstractStochasticCachingDiffFunction dfunction)
public void setEvaluators(int iters, Evaluator[] evaluators)
setEvaluators
in interface HasEvaluators
protected static double gainSchedule(int it, double tau)
protected static double[] smooth(java.util.List<double[]> toSmooth)
public abstract Pair<java.lang.Integer,java.lang.Double> tune(Function function, double[] initial, long msPerTest)
public double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<java.lang.Double> ps, double lower, double upper)
public double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<java.lang.Double> ps, double lower, double upper, double TOL)
public double tuneGain(Function function, double[] initial, long msPerTest, double lower, double upper)
public int tuneBatch(Function function, double[] initial, long msPerTest, int bStart)
public Pair<java.lang.Integer,java.lang.Double> tune(Function function, double[] initial, long msPerTest, java.util.List<java.lang.Integer> batchSizes, java.util.List<java.lang.Double> gains)
protected void init(AbstractStochasticCachingDiffFunction func)
public double[] minimize(Function function, double functionTolerance, double[] initial)
Minimizer
function
starting at initial
, accurate to
within functionTolerance
(normally implemented as
a multiplier of the range value to give range tolerance).public double[] minimize(Function function, double functionTolerance, double[] initial, int maxIterations)
Minimizer
function
starting at initial
, accurate to
within functionTolerance
(normally implemented as
a multiplier of the range value to give range tolerance), but
running only for at most maxIterations
iterations.protected void sayln(java.lang.String s)
protected void say(java.lang.String s)