public abstract class StochasticMinimizer<T extends Function> extends 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);
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 PrintWriter |
file |
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 static 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 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 static 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) |
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 List<double[]> gradList
protected int memory
protected int numPasses
protected Random gen
protected PrintWriter file
protected PrintWriter infoFile
protected long maxTime
protected static final NumberFormat nf
public void shutUp()
protected abstract 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(List<double[]> toSmooth)
public double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<Double> ps, double lower, double upper)
public double tuneDouble(Function function, double[] initial, long msPerTest, StochasticMinimizer.PropertySetter<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<Integer,Double> tune(Function function, double[] initial, long msPerTest, List<Integer> batchSizes, List<Double> gains)
protected void init(AbstractStochasticCachingDiffFunction func)
public double[] minimize(Function function, double functionTolerance, double[] initial)
Minimizer
function
starting at initial
, within
functionTolerance
.public double[] minimize(Function function, double functionTolerance, double[] initial, int maxIterations)
protected void sayln(String s)
protected void say(String s)