package lbfgsb;

/**
 * Stop conditions for the algorithm. 
 * Each stop condition is associated with a flag that determines if the
 * stop condition is active. See descriptions of set... methods for
 * explanation of each of the conditions meaning.
 * 
 * @author Mateusz Kobos
 */
public class StopConditions{
	public static double defaultFunctionReductionFactor = 1e7;
	public static double defaultMaxGradientNorm = 1e-5;
	public static int defaultMaxIterations = 100;
	
	private double functionReductionFactor = defaultFunctionReductionFactor;
	private double maxGradientNorm = defaultMaxGradientNorm;
	private int maxIterations = defaultMaxIterations;
	
	public double getFunctionReductionFactor() {
		return functionReductionFactor;
	}
	/**@param value relative function reduction factor.
	 * <p>Cite from the original L-BFGS-B fortran code:</p>
	 * 
	 * <p>The iteration will stop when
	 * 		(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
	 * 	where epsmch is the machine precision which is automatically
	 * 	generated by the code.</p>
	 * 
	 * <p>Example values for 15 digits accuracy: 
	 * <ul>
	 * 	<li>1e+12 for low accuracy,</li> 
	 * 	<li>1e+7  for moderate accuracy,</li>
	 * 	<li>1e+1  for extremely high accuracy</li>
	 * <ul></p>
	 * */
	public void setFunctionReductionFactor(double value) {
		assert value >= 0;
		this.functionReductionFactor = value;
	}
	public boolean isFunctionReductionFactorActive(){
		return functionReductionFactor > 0;
	}
	public void setFunctionReductionFactorInactive(){
		functionReductionFactor = 0;
	}
	
	public double getMaxGradientNorm() {
		return maxGradientNorm;
	}
	/**
	 * @param value maximal acceptable gradient value
	 * The iteration will stop when $||proj g||_{\infty} <= value$
	 * where $proj g$ is the projected gradient.  
	 */
	public void setMaxGradientNorm(double value) {
		assert value >= 0;
		this.maxGradientNorm = value;
	}
	public boolean isMaxGradientNormActive(){
		return maxGradientNorm > 0;
	}
	public void setMaxGradientNormInactive(){
		maxGradientNorm = 0;
	}
	
	public int getMaxIterations() {
		return maxIterations;
	}
	/**
	 * @param value maximal number of algorithm's iterations
	 */
	public void setMaxIterations(int value) {
		assert value >= 0;
		this.maxIterations = value;
	}
	public boolean isMaxIterationsActive(){
		return maxIterations >= 0;
	}
	public void setMaxIterationsInactive(){
		maxIterations = -1;
	}
}

@@ -931,18 +931,20 @@
 +1%7D%7C,1%7D 
-%3C=
+&le;
  factr*e
@@ -1097,17 +1097,20 @@
 ccuracy:
- 
+%3C/p%3E
 %0A%09 * %3Cul
@@ -1250,15 +1250,12 @@
  * %3C
+/
 ul%3E
-%3C/p%3E
 %0A%09 *
@@ -1738,10 +1738,12 @@
 ty%7D 
-%3C=
+&le;
  val

Fix StopConditions javadoc