Removed trailing spaces.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@811685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2009-09-05 17:36:48 +00:00
parent abb6fb94bd
commit dc9278a2aa
542 changed files with 7410 additions and 7402 deletions

View File

@ -90,6 +90,14 @@
<property name="ignoreConstructorParameter" value="true" />
<property name="ignoreSetter" value="true" />
</module>
<!-- No trailing whitespace -->
<module name="Regexp">
<property name="format" value="[ \t]+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Trailing whitespace"/>
</module>
<!--
<module name="DeclarationOrder" />

View File

@ -31,7 +31,7 @@ public class ArgumentOutsideDomainException extends FunctionEvaluationException
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param argument the failing function argument
* @param argument the failing function argument
* @param lower lower bound of the domain
* @param upper upper bound of the domain
*/

View File

@ -23,7 +23,7 @@ package org.apache.commons.math;
* @version $Revision$ $Date$
*/
public class ConvergenceException extends MathException {
/** Serializable version identifier */
private static final long serialVersionUID = 4883703247677159141L;
@ -33,7 +33,7 @@ public class ConvergenceException extends MathException {
public ConvergenceException() {
super("Convergence failed");
}
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.

View File

@ -38,14 +38,14 @@ public interface ConvergingAlgorithm {
* <p>
* A {@link ConvergenceException} will be thrown if this number
* is exceeded.</p>
*
*
* @param count maximum number of iterations
*/
public abstract void setMaximalIterationCount(int count);
/**
* Get the upper limit for the number of iterations.
*
*
* @return the actual upper limit
*/
public abstract int getMaximalIterationCount();
@ -54,7 +54,7 @@ public interface ConvergingAlgorithm {
* Reset the upper limit for the number of iterations to the default.
* <p>
* The default value is supplied by the algorithm implementation.</p>
*
*
* @see #setMaximalIterationCount(int)
*/
public abstract void resetMaximalIterationCount();
@ -69,16 +69,16 @@ public interface ConvergingAlgorithm {
* <p>
* Algorithms are advised to do a plausibility check with the relative
* accuracy, but clients should not rely on this.</p>
*
*
* @param accuracy the accuracy.
* @throws IllegalArgumentException if the accuracy can't be achieved by
* the solver or is otherwise deemed unreasonable.
* the solver or is otherwise deemed unreasonable.
*/
public abstract void setAbsoluteAccuracy(double accuracy);
/**
* Get the actual absolute accuracy.
*
*
* @return the accuracy
*/
public abstract double getAbsoluteAccuracy();
@ -99,10 +99,10 @@ public interface ConvergingAlgorithm {
* If this should be the primary criterion for convergence rather then a
* safety measure, set the absolute accuracy to a ridiculously small value,
* like {@link org.apache.commons.math.util.MathUtils#SAFE_MIN MathUtils.SAFE_MIN}.</p>
*
*
* @param accuracy the relative accuracy.
* @throws IllegalArgumentException if the accuracy can't be achieved by
* the algorithm or is otherwise deemed unreasonable.
* the algorithm or is otherwise deemed unreasonable.
*/
public abstract void setRelativeAccuracy(double accuracy);
@ -126,11 +126,11 @@ public interface ConvergingAlgorithm {
* is notoriously high, check whether the problem is evaluated
* properly, and whether another algorithm is more amenable to the
* problem.</p>
*
*
* @return the last iteration count.
* @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed.
*/
public abstract int getIterationCount();
}
}

View File

@ -21,7 +21,7 @@ package org.apache.commons.math;
/**
* Provide a default implementation for several functions useful to generic
* converging algorithms.
*
*
* @version $Revision$ $Date$
* @since 2.0
*/
@ -51,10 +51,10 @@ public abstract class ConvergingAlgorithmImpl implements ConvergingAlgorithm{
/**
* Construct an algorithm with given iteration count and accuracy.
*
*
* @param defaultAbsoluteAccuracy maximum absolute error
* @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the
* @throws IllegalArgumentException if f is null or the
* defaultAbsoluteAccuracy is not valid
*/
protected ConvergingAlgorithmImpl(final int defaultMaximalIterationCount,

View File

@ -18,12 +18,12 @@ package org.apache.commons.math;
/**
* Error thrown when two dimensions differ.
*
*
* @since 1.2
* @version $Revision$ $Date$
*/
public class DimensionMismatchException extends MathException {
/** Serializable version identifier */
private static final long serialVersionUID = -1316089546353786411L;
@ -45,7 +45,7 @@ public class DimensionMismatchException extends MathException {
public int getDimension1() {
return dimension1;
}
/**
* Get the second dimension
* @return second dimension
@ -56,8 +56,8 @@ public class DimensionMismatchException extends MathException {
/** First dimension. */
private int dimension1;
/** Second dimension. */
private int dimension2;
}

View File

@ -18,12 +18,12 @@ package org.apache.commons.math;
/**
* Exeption thrown when a sample contains several entries at the same abscissa.
*
*
* @since 1.2
* @version $Revision$ $Date$
*/
public class DuplicateSampleAbscissaException extends MathException {
/** Serializable version identifier */
private static final long serialVersionUID = -2271007547170169872L;
@ -45,5 +45,5 @@ public class DuplicateSampleAbscissaException extends MathException {
public double getDuplicateAbscissa() {
return ((Double) getArguments()[0]).doubleValue();
}
}

View File

@ -48,4 +48,4 @@ public interface Field<T> {
*/
T getOne();
}
}

View File

@ -57,4 +57,4 @@ public interface FieldElement<T> {
*/
Field<T> getField();
}
}

View File

@ -23,44 +23,44 @@ import org.apache.commons.math.linear.ArrayRealVector;
* <p>
* Maintains an <code>argument</code> property holding the input value that
* caused the function evaluation to fail.
*
*
* @version $Revision$ $Date$
*/
public class FunctionEvaluationException extends MathException {
/** Serializable version identifier. */
private static final long serialVersionUID = -4305020489115478365L;
/** Argument causing function evaluation failure */
private double[] argument;
/**
* Construct an exception indicating the argument value
* that caused the function evaluation to fail.
*
* @param argument the failing function argument
*
* @param argument the failing function argument
*/
public FunctionEvaluationException(double argument) {
super("evaluation failed for argument = {0}", argument);
this.argument = new double[] { argument };
}
/**
* Construct an exception indicating the argument value
* that caused the function evaluation to fail.
*
* @param argument the failing function argument
*
* @param argument the failing function argument
* @since 2.0
*/
public FunctionEvaluationException(double[] argument) {
super("evaluation failed for argument = {0}", new ArrayRealVector(argument));
this.argument = argument.clone();
}
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param argument the failing function argument
* @param argument the failing function argument
* @param pattern format specifier
* @param arguments format arguments
* @since 1.2
@ -74,7 +74,7 @@ public class FunctionEvaluationException extends MathException {
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param argument the failing function argument
* @param argument the failing function argument
* @param pattern format specifier
* @param arguments format arguments
* @since 2.0
@ -89,7 +89,7 @@ public class FunctionEvaluationException extends MathException {
* Constructs an exception with specified root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param cause the exception or error that caused this exception to be thrown
* @param argument the failing function argument
* @param argument the failing function argument
* @since 1.2
*/
public FunctionEvaluationException(Throwable cause, double argument) {
@ -101,7 +101,7 @@ public class FunctionEvaluationException extends MathException {
* Constructs an exception with specified root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param cause the exception or error that caused this exception to be thrown
* @param argument the failing function argument
* @param argument the failing function argument
* @since 2.0
*/
public FunctionEvaluationException(Throwable cause, double[] argument) {
@ -113,7 +113,7 @@ public class FunctionEvaluationException extends MathException {
* Constructs an exception with specified formatted detail message and root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param cause the exception or error that caused this exception to be thrown
* @param argument the failing function argument
* @param argument the failing function argument
* @param pattern format specifier
* @param arguments format arguments
* @since 1.2
@ -129,7 +129,7 @@ public class FunctionEvaluationException extends MathException {
* Constructs an exception with specified formatted detail message and root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param cause the exception or error that caused this exception to be thrown
* @param argument the failing function argument
* @param argument the failing function argument
* @param pattern format specifier
* @param arguments format arguments
* @since 2.0
@ -143,7 +143,7 @@ public class FunctionEvaluationException extends MathException {
/**
* Returns the function argument that caused this exception.
*
*
* @return argument that caused function evaluation to fail
*/
public double[] getArgument() {

View File

@ -33,7 +33,7 @@ public class MathConfigurationException extends MathException implements Seriali
public MathConfigurationException() {
super();
}
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.

View File

@ -30,11 +30,11 @@ import java.util.ResourceBundle;
* Supports nesting, emulating JDK 1.4 behavior if necessary.</p>
* <p>
* Adapted from <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/FunctorException.html"/>.</p>
*
*
* @version $Revision$ $Date$
*/
public class MathException extends Exception {
/** Serializable version identifier. */
private static final long serialVersionUID = -9004610152740737812L;
@ -63,7 +63,7 @@ public class MathException extends Exception {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
@ -82,7 +82,7 @@ public class MathException extends Exception {
* @return a message string
*/
private static String buildMessage(Locale locale, String pattern, Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/**
@ -94,7 +94,7 @@ public class MathException extends Exception {
this.pattern = null;
this.arguments = new Object[0];
}
/**
* Constructs a new <code>MathException</code> with specified
* formatted detail message.
@ -120,7 +120,7 @@ public class MathException extends Exception {
this.pattern = getMessage();
this.arguments = new Object[0];
}
/**
* Constructs a new <code>MathException</code> with specified
* formatted detail message and nested <code>Throwable</code> root cause.
@ -158,7 +158,7 @@ public class MathException extends Exception {
/** Gets the message in a specified locale.
*
* @param locale Locale in which the message should be translated
*
*
* @return localized message
* @since 1.2
*/
@ -179,7 +179,7 @@ public class MathException extends Exception {
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* Prints the stack trace of this exception to the specified stream.
*

View File

@ -30,12 +30,12 @@ import java.util.ResourceBundle;
/**
* Base class for commons-math unchecked exceptions.
*
*
* @version $Revision$ $Date$
* @since 2.0
*/
public class MathRuntimeException extends RuntimeException {
/** Serializable version identifier. */
private static final long serialVersionUID = -5128983364075381060L;
@ -64,7 +64,7 @@ public class MathRuntimeException extends RuntimeException {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
@ -84,7 +84,7 @@ public class MathRuntimeException extends RuntimeException {
*/
private static String buildMessage(final Locale locale, final String pattern,
final Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/**
@ -112,7 +112,7 @@ public class MathRuntimeException extends RuntimeException {
this.pattern = getMessage();
this.arguments = new Object[0];
}
/**
* Constructs a new <code>MathRuntimeException</code> with specified
* formatted detail message and nested <code>Throwable</code> root cause.
@ -148,7 +148,7 @@ public class MathRuntimeException extends RuntimeException {
/** Gets the message in a specified locale.
*
* @param locale Locale in which the message should be translated
*
*
* @return localized message
*/
public String getMessage(final Locale locale) {
@ -168,7 +168,7 @@ public class MathRuntimeException extends RuntimeException {
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* Prints the stack trace of this exception to the specified stream.
*

View File

@ -19,7 +19,7 @@ package org.apache.commons.math;
import java.util.ListResourceBundle;
/**
/**
* French localization message resources for the commons-math library.
* @version $Revision$ $Date$
* @since 1.2
@ -27,13 +27,13 @@ import java.util.ListResourceBundle;
public class MessagesResources_fr
extends ListResourceBundle {
/**
/**
* Simple constructor.
*/
public MessagesResources_fr() {
}
/**
/**
* Get the non-translated/translated messages arrays from this resource bundle.
* @return non-translated/translated messages arrays
*/
@ -405,7 +405,7 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.SparseRealVector
{ "vector length mismatch: got {0} but expected {1}",
"dimension de vecteur erronn\u00e9e : {0} \u00e0 la place de {1}" },
// org.apache.commons.math.linear.ArrayRealVector
// org.apache.commons.math.linear.ArrayFieldVector
// org.apache.commons.math.linear.SparseRealVector
@ -433,7 +433,7 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.AbstractRealMatrix
// org.apache.commons.math.linear.AbstractFieldMatrix
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
{ "some rows have length {0} while others have length {1}",
"certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1}" },

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis;
/**
/**
* Extension of {@link MultivariateRealFunction} representing a differentiable
* multivariate real function.
* @version $Revision$ $Date$

View File

@ -18,7 +18,7 @@
package org.apache.commons.math.analysis;
/**
/**
* Extension of {@link MultivariateVectorialFunction} representing a differentiable
* multivariate vectorial function.
* @version $Revision$ $Date$

View File

@ -24,10 +24,10 @@ package org.apache.commons.math.analysis;
*/
public interface DifferentiableUnivariateMatrixFunction
extends UnivariateMatrixFunction {
/**
* Returns the derivative of the function
*
*
* @return the derivative function
*/
public UnivariateMatrixFunction derivative();

View File

@ -23,10 +23,10 @@ package org.apache.commons.math.analysis;
*/
public interface DifferentiableUnivariateRealFunction
extends UnivariateRealFunction {
/**
* Returns the derivative of the function
*
*
* @return the derivative function
*/
public UnivariateRealFunction derivative();

View File

@ -24,10 +24,10 @@ package org.apache.commons.math.analysis;
*/
public interface DifferentiableUnivariateVectorialFunction
extends UnivariateVectorialFunction {
/**
* Returns the derivative of the function
*
*
* @return the derivative function
*/
public UnivariateVectorialFunction derivative();

View File

@ -20,14 +20,14 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
/**
/**
* An interface representing a multivariate matrix function.
* @version $Revision$ $Date$
* @since 2.0
*/
public interface MultivariateMatrixFunction {
/**
/**
* Compute the value for the function at the given point.
* @param point point at which the function must be evaluated
* @return function value for the given point

View File

@ -19,14 +19,14 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
/**
/**
* An interface representing a multivariate real function.
* @version $Revision$ $Date$
* @since 2.0
*/
public interface MultivariateRealFunction {
/**
/**
* Compute the value for the function at the given point.
* @param point point at which the function must be evaluated
* @return function value for the given point

View File

@ -19,14 +19,14 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
/**
/**
* An interface representing a multivariate vectorial function.
* @version $Revision$ $Date$
* @since 2.0
*/
public interface MultivariateVectorialFunction {
/**
/**
* Compute the value for the function at the given point.
* @param point point at which the function must be evaluated
* @return function value for the given point

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException;
/**
* An interface representing a univariate matrix function.
*
*
* @version $Revision$ $Date$
* @since 2.0
*/

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException;
/**
* An interface representing a univariate real function.
*
*
* @version $Revision$ $Date$
*/
public interface UnivariateRealFunction {

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.FunctionEvaluationException;
/**
* An interface representing a univariate vectorial function.
*
*
* @version $Revision$ $Date$
* @since 2.0
*/

View File

@ -163,7 +163,7 @@ public class LegendreGaussIntegrator extends UnivariateRealIntegratorImpl {
public double integrate(final UnivariateRealFunction f,
final double min, final double max)
throws ConvergenceException, FunctionEvaluationException, IllegalArgumentException {
clearResult();
verifyInterval(min, max);
verifyIterationCount();

View File

@ -30,7 +30,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* Romberg integration employs k successive refinements of the trapezoid
* rule to remove error terms less than order O(N^(-2k)). Simpson's rule
* is a special case of k = 2.</p>
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -38,7 +38,7 @@ public class RombergIntegrator extends UnivariateRealIntegratorImpl {
/**
* Construct an integrator for the given function.
*
*
* @param f function to integrate
* @deprecated as of 2.0 the integrand function is passed as an argument
* to the {@link #integrate(UnivariateRealFunction, double, double)}method.
@ -66,7 +66,7 @@ public class RombergIntegrator extends UnivariateRealIntegratorImpl {
public double integrate(final UnivariateRealFunction f,
final double min, final double max)
throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException {
int i = 1, j, m = maximalIterationCount + 1;
// Array structure here can be improved for better space
// efficiency because only the lower triangle is used.
@ -90,7 +90,7 @@ public class RombergIntegrator extends UnivariateRealIntegratorImpl {
if (i >= minimalIterationCount) {
final double delta = Math.abs(s - olds);
final double rLimit =
relativeAccuracy * (Math.abs(olds) + Math.abs(s)) * 0.5;
relativeAccuracy * (Math.abs(olds) + Math.abs(s)) * 0.5;
if ((delta <= rLimit) || (delta <= absoluteAccuracy)) {
setResult(s, i);
return result;

View File

@ -29,7 +29,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* <p>
* This implementation employs basic trapezoid rule as building blocks to
* calculate the Simpson's rule of alternating 2/3 and 4/3.</p>
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -37,7 +37,7 @@ public class SimpsonIntegrator extends UnivariateRealIntegratorImpl {
/**
* Construct an integrator for the given function.
*
*
* @param f function to integrate
* @deprecated as of 2.0 the integrand function is passed as an argument
* to the {@link #integrate(UnivariateRealFunction, double, double)}method.
@ -65,10 +65,10 @@ public class SimpsonIntegrator extends UnivariateRealIntegratorImpl {
public double integrate(final UnivariateRealFunction f,
final double min, final double max)
throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException {
int i = 1;
double s, olds, t, oldt;
clearResult();
verifyInterval(min, max);
verifyIterationCount();
@ -88,7 +88,7 @@ public class SimpsonIntegrator extends UnivariateRealIntegratorImpl {
if (i >= minimalIterationCount) {
final double delta = Math.abs(s - olds);
final double rLimit =
relativeAccuracy * (Math.abs(olds) + Math.abs(s)) * 0.5;
relativeAccuracy * (Math.abs(olds) + Math.abs(s)) * 0.5;
if ((delta <= rLimit) || (delta <= absoluteAccuracy)) {
setResult(s, i);
return result;

View File

@ -28,7 +28,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* chapter 3.
* <p>
* The function should be integrable.</p>
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -39,7 +39,7 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
/**
* Construct an integrator for the given function.
*
*
* @param f function to integrate
* @deprecated as of 2.0 the integrand function is passed as an argument
* to the {@link #integrate(UnivariateRealFunction, double, double)}method.
@ -76,10 +76,10 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
double stage(final UnivariateRealFunction f,
final double min, final double max, final int n)
throws FunctionEvaluationException {
long i, np;
double x, spacing, sum = 0;
if (n == 0) {
s = 0.5 * (max - min) * (f.value(min) + f.value(max));
return s;
@ -108,10 +108,10 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
public double integrate(final UnivariateRealFunction f,
final double min, final double max)
throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException {
int i = 1;
double t, oldt;
clearResult();
verifyInterval(min, max);
verifyIterationCount();
@ -122,7 +122,7 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
if (i >= minimalIterationCount) {
final double delta = Math.abs(t - oldt);
final double rLimit =
relativeAccuracy * (Math.abs(oldt) + Math.abs(t)) * 0.5;
relativeAccuracy * (Math.abs(oldt) + Math.abs(t)) * 0.5;
if ((delta <= rLimit) || (delta <= absoluteAccuracy)) {
setResult(t, i);
return result;

View File

@ -23,7 +23,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Interface for univariate real integration algorithms.
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -45,7 +45,7 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
/**
* Get the lower limit for the number of iterations.
*
*
* @return the actual lower limit
*/
int getMinimalIterationCount();
@ -54,14 +54,14 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
* Reset the lower limit for the number of iterations to the default.
* <p>
* The default value is supplied by the implementation.</p>
*
*
* @see #setMinimalIterationCount(int)
*/
void resetMinimalIterationCount();
/**
* Integrate the function in the given interval.
*
*
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the value of integral
@ -75,12 +75,12 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
* since 2.0
*/
@Deprecated
double integrate(double min, double max) throws ConvergenceException,
double integrate(double min, double max) throws ConvergenceException,
FunctionEvaluationException, IllegalArgumentException;
/**
* Integrate the function in the given interval.
*
*
* @param f the integrand function
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -92,12 +92,12 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
* @throws IllegalArgumentException if min > max or the endpoints do not
* satisfy the requirements specified by the integrator
*/
double integrate(UnivariateRealFunction f, double min, double max) throws ConvergenceException,
double integrate(UnivariateRealFunction f, double min, double max) throws ConvergenceException,
FunctionEvaluationException, IllegalArgumentException;
/**
* Get the result of the last run of the integrator.
*
*
* @return the last result
* @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed

View File

@ -22,7 +22,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Provide a default implementation for several generic functions.
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -52,7 +52,7 @@ public abstract class UnivariateRealIntegratorImpl
/**
* Construct an integrator with given iteration count and accuracy.
*
*
* @param f the integrand function
* @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the iteration
@ -75,13 +75,13 @@ public abstract class UnivariateRealIntegratorImpl
setRelativeAccuracy(1.0e-6);
this.defaultMinimalIterationCount = 3;
this.minimalIterationCount = defaultMinimalIterationCount;
verifyIterationCount();
}
/**
* Construct an integrator with given iteration count and accuracy.
*
*
* @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the iteration
* limits are not valid
@ -94,13 +94,13 @@ public abstract class UnivariateRealIntegratorImpl
setRelativeAccuracy(1.0e-6);
this.defaultMinimalIterationCount = 3;
this.minimalIterationCount = defaultMinimalIterationCount;
verifyIterationCount();
}
/**
* Access the last computed integral.
*
*
* @return the last computed integral
* @throws IllegalStateException if no integral has been computed
*/
@ -114,7 +114,7 @@ public abstract class UnivariateRealIntegratorImpl
/**
* Convenience function for implementations.
*
*
* @param newResult the result to set
* @param iterationCount the iteration count to set
*/
@ -149,7 +149,7 @@ public abstract class UnivariateRealIntegratorImpl
/**
* Verifies that the endpoints specify an interval.
*
*
* @param lower lower endpoint
* @param upper upper endpoint
* @throws IllegalArgumentException if not interval
@ -160,12 +160,12 @@ public abstract class UnivariateRealIntegratorImpl
throw MathRuntimeException.createIllegalArgumentException(
"endpoints do not specify an interval: [{0}, {1}]",
lower, upper);
}
}
}
/**
* Verifies that the upper and lower limits of iterations are valid.
*
*
* @throws IllegalArgumentException if not valid
*/
protected void verifyIterationCount() throws IllegalArgumentException {
@ -173,6 +173,6 @@ public abstract class UnivariateRealIntegratorImpl
throw MathRuntimeException.createIllegalArgumentException(
"invalid iteration limits: min={0}, max={1}",
minimalIterationCount, maximalIterationCount);
}
}
}
}

View File

@ -19,4 +19,4 @@
<body>
Numerical integration (quadrature) algorithms for univariate real functions.
</body>
</html>
</html>

View File

@ -81,7 +81,7 @@ public class DividedDifferenceInterpolator implements UnivariateRealInterpolator
/**
* Returns a copy of the divided difference array.
* <p>
* <p>
* The divided difference array is defined recursively by <pre>
* f[x0] = f(x0)
* f[x0,x1,...,xk] = (f(x1,...,xk) - f(x0,...,x[k-1])) / (xk - x0)

View File

@ -281,7 +281,7 @@ public class LoessInterpolator
// Recompute the robustness weights.
// Find the median residual.
// An arraycopy and a sort are completely tractable here,
// An arraycopy and a sort are completely tractable here,
// because the preceding loop is a lot more expensive
System.arraycopy(residuals, 0, sortedResiduals, 0, n);
Arrays.sort(sortedResiduals);
@ -328,7 +328,7 @@ public class LoessInterpolator
}
/**
* Compute the
* Compute the
* <a href="http://en.wikipedia.org/wiki/Local_regression#Weight_function">tricube</a>
* weight function
*

View File

@ -24,7 +24,7 @@ import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
* Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set.
* <p>
* The {@link #interpolate(double[], double[])} method returns a {@link PolynomialSplineFunction}
* consisting of n cubic polynomials, defined over the subintervals determined by the x values,
* consisting of n cubic polynomials, defined over the subintervals determined by the x values,
* x[0] < x[i] ... < x[n]. The x values are referred to as "knot points."</p>
* <p>
* The value of the PolynomialSplineFunction at a point x that is greater than or equal to the smallest
@ -34,13 +34,13 @@ import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
* </p>
* <p>
* The interpolating polynomials satisfy: <ol>
* <li>The value of the PolynomialSplineFunction at each of the input x values equals the
* <li>The value of the PolynomialSplineFunction at each of the input x values equals the
* corresponding y value.</li>
* <li>Adjacent polynomials are equal through two derivatives at the knot points (i.e., adjacent polynomials
* <li>Adjacent polynomials are equal through two derivatives at the knot points (i.e., adjacent polynomials
* "match up" at the knot points, as do their first and second derivatives).</li>
* </ol></p>
* <p>
* The cubic spline interpolation algorithm implemented is as described in R.L. Burden, J.D. Faires,
* The cubic spline interpolation algorithm implemented is as described in R.L. Burden, J.D. Faires,
* <u>Numerical Analysis</u>, 4th Ed., 1989, PWS-Kent, ISBN 0-53491-585-X, pp 126-131.
* </p>
*
@ -48,7 +48,7 @@ import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
*
*/
public class SplineInterpolator implements UnivariateRealInterpolator {
/**
* Computes an interpolating function for the data set.
* @param x the arguments for the interpolation points
@ -60,15 +60,15 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
throw MathRuntimeException.createIllegalArgumentException(
"dimension mismatch {0} != {1}", x.length, y.length);
}
if (x.length < 3) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} points are required, got only {1}", 3, x.length);
}
// Number of intervals. The number of data points is n + 1.
int n = x.length - 1;
int n = x.length - 1;
for (int i = 0; i < n; i++) {
if (x[i] >= x[i + 1]) {
throw MathRuntimeException.createIllegalArgumentException(
@ -76,13 +76,13 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
i, i+1, x[i], x[i+1]);
}
}
// Differences between knot points
double h[] = new double[n];
for (int i = 0; i < n; i++) {
h[i] = x[i + 1] - x[i];
}
double mu[] = new double[n];
double z[] = new double[n + 1];
mu[0] = 0d;
@ -94,21 +94,21 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) /
(h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g;
}
// cubic spline coefficients -- b is linear, c quadratic, d is cubic (original y's are constants)
double b[] = new double[n];
double c[] = new double[n + 1];
double d[] = new double[n];
z[n] = 0d;
c[n] = 0d;
for (int j = n -1; j >=0; j--) {
c[j] = z[j] - mu[j] * c[j + 1];
b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d;
d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
}
PolynomialFunction polynomials[] = new PolynomialFunction[n];
double coefficients[] = new double[4];
for (int i = 0; i < n; i++) {
@ -118,7 +118,7 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
coefficients[3] = d[i];
polynomials[i] = new PolynomialFunction(coefficients);
}
return new PolynomialSplineFunction(x, polynomials);
}

View File

@ -21,7 +21,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Interface representing a univariate real interpolating function.
*
*
* @version $Revision$ $Date$
*/
public interface UnivariateRealInterpolator {

View File

@ -19,4 +19,4 @@
<body>
Univariate real functions interpolation algorithms.
</body>
</html>
</html>

View File

@ -30,4 +30,4 @@
or univariate, real vectorial or matrix valued, and they can be differentiable or not.
</p>
</body>
</html>
</html>

View File

@ -37,10 +37,10 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
* Serializtion identifier
*/
private static final long serialVersionUID = -7726511984200295583L;
/**
* The coefficients of the polynomial, ordered by degree -- i.e.,
* coefficients[0] is the constant term and coefficients[n] is the
* The coefficients of the polynomial, ordered by degree -- i.e.,
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private final double coefficients[];
@ -50,11 +50,11 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
* of the coefficients array is the constant term. Higher degree
* coefficients follow in sequence. The degree of the resulting polynomial
* is the index of the last non-null element of the array, or 0 if all elements
* are null.
* are null.
* <p>
* The constructor makes a copy of the input array and assigns the copy to
* the coefficients property.</p>
*
*
* @param c polynomial coefficients
* @throws NullPointerException if c is null
* @throws IllegalArgumentException if c is empty
@ -78,7 +78,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
* The value returned is <br>
* <code>coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]</code>
* </p>
*
*
* @param x the argument for which the function value should be computed
* @return the value of the polynomial at the given point
* @see UnivariateRealFunction#value(double)
@ -90,32 +90,32 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
/**
* Returns the degree of the polynomial
*
*
* @return the degree of the polynomial
*/
public int degree() {
return coefficients.length - 1;
}
/**
* Returns a copy of the coefficients array.
* <p>
* Changes made to the returned copy will not affect the coefficients of
* the polynomial.</p>
*
*
* @return a fresh copy of the coefficients array
*/
public double[] getCoefficients() {
return coefficients.clone();
}
/**
* Uses Horner's Method to evaluate the polynomial with the given coefficients at
* the argument.
*
*
* @param coefficients the coefficients of the polynomial to evaluate
* @param argument the input value
* @return the value of the polynomial
* @return the value of the polynomial
* @throws IllegalArgumentException if coefficients is empty
* @throws NullPointerException if coefficients is null
*/
@ -222,7 +222,7 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
/**
* Returns the coefficients of the derivative of the polynomial with the given coefficients.
*
*
* @param coefficients the coefficients of the polynomial to differentiate
* @return the coefficients of the derivative or null if coefficients has length 1.
* @throws IllegalArgumentException if coefficients is empty
@ -242,19 +242,19 @@ public class PolynomialFunction implements DifferentiableUnivariateRealFunction,
}
return result;
}
/**
* Returns the derivative as a PolynomialRealFunction
*
*
* @return the derivative polynomial
*/
public PolynomialFunction polynomialDerivative() {
return new PolynomialFunction(differentiate(coefficients));
}
/**
* Returns the derivative as a UnivariateRealFunction
*
*
* @return the derivative function
*/
public UnivariateRealFunction derivative() {

View File

@ -37,7 +37,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
/**
* The coefficients of the polynomial, ordered by degree -- i.e.
* coefficients[0] is the constant term and coefficients[n] is the
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private double coefficients[];
@ -57,7 +57,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* values. The order of interpolating points are not important.
* <p>
* The constructor makes copy of the input arrays and assigns them.</p>
*
*
* @param x interpolating points
* @param y function values at interpolating points
* @throws IllegalArgumentException if input arrays are not valid
@ -91,7 +91,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
/**
* Returns the degree of the polynomial.
*
*
* @return the degree of the polynomial
*/
public int degree() {
@ -102,7 +102,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the interpolating points array.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of the interpolating points array
*/
public double[] getInterpolatingPoints() {
@ -115,7 +115,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the interpolating values array.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of the interpolating values array
*/
public double[] getInterpolatingValues() {
@ -128,7 +128,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the coefficients array.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of the coefficients array
*/
public double[] getCoefficients() {
@ -141,7 +141,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
}
/**
* Evaluate the Lagrange polynomial using
* Evaluate the Lagrange polynomial using
* <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
* Neville's Algorithm</a>. It takes O(N^2) time.
* <p>
@ -276,7 +276,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* <p>
* The interpolating points must be distinct. However it is not
* verified here, it is checked in evaluate() and computeCoefficients().</p>
*
*
* @param x the interpolating points array
* @param y the interpolating values array
* @throws IllegalArgumentException if not valid

View File

@ -37,7 +37,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
/**
* The coefficients of the polynomial, ordered by degree -- i.e.
* coefficients[0] is the constant term and coefficients[n] is the
* coefficients[0] is the constant term and coefficients[n] is the
* coefficient of x^n where n is the degree of the polynomial.
*/
private double coefficients[];
@ -60,7 +60,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* completely change, not just a permutation of old a[].
* <p>
* The constructor makes copy of the input arrays and assigns them.</p>
*
*
* @param a the coefficients in Newton form formula
* @param c the centers
* @throws IllegalArgumentException if input arrays are not valid
@ -90,7 +90,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
/**
* Returns the degree of the polynomial.
*
*
* @return the degree of the polynomial
*/
public int degree() {
@ -101,7 +101,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of coefficients in Newton form formula.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of coefficients in Newton form formula
*/
public double[] getNewtonCoefficients() {
@ -114,7 +114,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of the centers array.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of the centers array
*/
public double[] getCenters() {
@ -127,7 +127,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of the coefficients array.
* <p>
* Changes made to the returned copy will not affect the polynomial.</p>
*
*
* @return a fresh copy of the coefficients array
*/
public double[] getCoefficients() {
@ -193,7 +193,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* <p>
* The centers must be distinct for interpolation purposes, but not
* for general use. Thus it is not verified here.</p>
*
*
* @param a the coefficients in Newton form formula
* @param c the centers
* @throws IllegalArgumentException if not valid

View File

@ -26,20 +26,20 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Represents a polynomial spline function.
* <p>
* A <strong>polynomial spline function</strong> consists of a set of
* <i>interpolating polynomials</i> and an ascending array of domain
* A <strong>polynomial spline function</strong> consists of a set of
* <i>interpolating polynomials</i> and an ascending array of domain
* <i>knot points</i>, determining the intervals over which the spline function
* is defined by the constituent polynomials. The polynomials are assumed to
* have been computed to match the values of another function at the knot
* points. The value consistency constraints are not currently enforced by
* points. The value consistency constraints are not currently enforced by
* <code>PolynomialSplineFunction</code> itself, but are assumed to hold among
* the polynomials and knot points passed to the constructor.</p>
* <p>
* N.B.: The polynomials in the <code>polynomials</code> property must be
* centered on the knot points to compute the spline function values.
* centered on the knot points to compute the spline function values.
* See below.</p>
* <p>
* The domain of the polynomial spline function is
* The domain of the polynomial spline function is
* <code>[smallest knot, largest knot]</code>. Attempts to evaluate the
* function at values outside of this range generate IllegalArgumentExceptions.
* </p>
@ -57,7 +57,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
*
* @version $Revision$ $Date$
*/
public class PolynomialSplineFunction
public class PolynomialSplineFunction
implements DifferentiableUnivariateRealFunction {
/** Spline segment interval delimiters (knots). Size is n+1 for n segments. */
@ -71,13 +71,13 @@ public class PolynomialSplineFunction
* knot segment to which x belongs.
*/
private PolynomialFunction polynomials[] = null;
/**
/**
* Number of spline segments = number of polynomials
* = number of partition points - 1
* = number of partition points - 1
*/
private int n = 0;
/**
* Construct a polynomial spline function with the given segment delimiters
@ -85,14 +85,14 @@ public class PolynomialSplineFunction
* <p>
* The constructor copies both arrays and assigns the copies to the knots
* and polynomials properties, respectively.</p>
*
*
* @param knots spline segment interval delimiters
* @param polynomials polynomial functions that make up the spline
* @throws NullPointerException if either of the input arrays is null
* @throws IllegalArgumentException if knots has length less than 2,
* @throws IllegalArgumentException if knots has length less than 2,
* <code>polynomials.length != knots.length - 1 </code>, or the knots array
* is not strictly increasing.
*
*
*/
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[]) {
if (knots.length < 2) {
@ -109,7 +109,7 @@ public class PolynomialSplineFunction
throw MathRuntimeException.createIllegalArgumentException(
"knot values must be strictly increasing");
}
this.n = knots.length -1;
this.knots = new double[n + 1];
System.arraycopy(knots, 0, this.knots, 0, n + 1);
@ -125,7 +125,7 @@ public class PolynomialSplineFunction
* <p>
* See {@link PolynomialSplineFunction} for details on the algorithm for
* computing the value of the function.</p>
*
*
* @param v the point for which the function value should be computed
* @return the value
* @throws ArgumentOutsideDomainException if v is outside of the domain of
@ -148,7 +148,7 @@ public class PolynomialSplineFunction
}
return polynomials[i].value(v - knots[i]);
}
/**
* Returns the derivative of the polynomial spline function as a UnivariateRealFunction
* @return the derivative function
@ -156,10 +156,10 @@ public class PolynomialSplineFunction
public UnivariateRealFunction derivative() {
return polynomialSplineDerivative();
}
/**
* Returns the derivative of the polynomial spline function as a PolynomialSplineFunction
*
*
* @return the derivative function
*/
public PolynomialSplineFunction polynomialSplineDerivative() {
@ -171,9 +171,9 @@ public class PolynomialSplineFunction
}
/**
* Returns the number of spline segments = the number of polynomials
* Returns the number of spline segments = the number of polynomials
* = the number of knot points - 1.
*
*
* @return the number of spline segments
*/
public int getN() {
@ -185,7 +185,7 @@ public class PolynomialSplineFunction
* <p>
* Returns a fresh copy of the array. Changes made to the copy will
* not affect the polynomials property.</p>
*
*
* @return the interpolating polynomials
*/
public PolynomialFunction[] getPolynomials() {
@ -199,19 +199,19 @@ public class PolynomialSplineFunction
* <p>
* Returns a fresh copy of the array. Changes made to the copy
* will not affect the knots property.</p>
*
*
* @return the knot points
*/
public double[] getKnots() {
double out[] = new double[n + 1];
System.arraycopy(knots, 0, out, 0, n + 1);
return out;
return out;
}
/**
* Determines if the given array is ordered in a strictly increasing
* fashion.
*
*
* @param x the array to examine.
* @return <code>true</code> if the elements in <code>x</code> are ordered
* in a stricly increasing manner. <code>false</code>, otherwise.

View File

@ -22,7 +22,7 @@ import org.apache.commons.math.fraction.BigFraction;
/**
* A collection of static methods that operate on or return polynomials.
*
*
* @version $Revision$ $Date$
* @since 2.0
*/
@ -219,7 +219,7 @@ public class PolynomialsUtils {
return new PolynomialFunction(a);
}
/** Compute polynomial coefficients up to a given degree.
* @param degree maximal degree
* @param maxDegree current maximal degree

View File

@ -20,4 +20,4 @@
Univariate real polynomials implementations, seen as differentiable
univariate real functions.
</body>
</html>
</html>

View File

@ -22,17 +22,17 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements the <a href="http://mathworld.wolfram.com/Bisection.html">
* bisection algorithm</a> for finding zeros of univariate real functions.
* bisection algorithm</a> for finding zeros of univariate real functions.
* <p>
* The function should be continuous but not necessarily smooth.</p>
*
*
* @version $Revision$ $Date$
*/
public class BisectionSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver for the given function.
*
*
* @param f function to solve.
* @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or
@ -46,7 +46,7 @@ public class BisectionSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver.
*
*
*/
public BisectionSolver() {
super(100, 1E-6);
@ -58,7 +58,7 @@ public class BisectionSolver extends UnivariateRealSolverImpl {
throws MaxIterationsExceededException, FunctionEvaluationException {
return solve(f, min, max);
}
/** {@inheritDoc} */
@Deprecated
public double solve(double min, double max)
@ -75,13 +75,13 @@ public class BisectionSolver extends UnivariateRealSolverImpl {
/** {@inheritDoc} */
public double solve(final UnivariateRealFunction f, double min, double max)
throws MaxIterationsExceededException, FunctionEvaluationException {
clearResult();
verifyInterval(min,max);
double m;
double fm;
double fmin;
int i = 0;
while (i < maximalIterationCount) {
m = UnivariateRealSolverUtils.midpoint(min, max);
@ -103,7 +103,7 @@ public class BisectionSolver extends UnivariateRealSolverImpl {
}
++i;
}
throw new MaxIterationsExceededException(maximalIterationCount);
}
}

View File

@ -27,17 +27,17 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* Brent algorithm</a> for finding zeros of real univariate functions.
* <p>
* The function should be continuous but not necessarily smooth.</p>
*
*
* @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $
*/
public class BrentSolver extends UnivariateRealSolverImpl {
/** Serializable version identifier */
private static final long serialVersionUID = 7694577816772532779L;
/**
* Construct a solver for the given function.
*
*
* @param f function to solve.
* @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or
@ -76,7 +76,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
* function at the three points have the same sign (note that it is
* allowed to have endpoints with the same sign if the initial point has
* opposite sign function-wise).</p>
*
*
* @param f function to solve.
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
@ -84,7 +84,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
* initial point is known).
* @return the value where the function is zero
* @throws MaxIterationsExceededException the maximum iteration count
* is exceeded
* is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating
* the function
* @throws IllegalArgumentException if initial is not between min and max
@ -132,37 +132,37 @@ public class BrentSolver extends UnivariateRealSolverImpl {
return solve(f, min, yMin, max, yMax, initial, yInitial);
}
/**
* Find a zero in the given interval.
* <p>
* Requires that the values of the function at the endpoints have opposite
* signs. An <code>IllegalArgumentException</code> is thrown if this is not
* the case.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
* @return the value where the function is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if min is not less than max or the
* signs of the values of the function at the endpoints are not opposites
*/
public double solve(final UnivariateRealFunction f,
final double min, final double max)
throws MaxIterationsExceededException,
throws MaxIterationsExceededException,
FunctionEvaluationException {
clearResult();
verifyInterval(min, max);
double ret = Double.NaN;
double yMin = f.value(min);
double yMax = f.value(max);
// Verify bracketing
double sign = yMin * yMax;
if (sign > 0) {
@ -178,7 +178,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs. " +
"Endpoints: [{0}, {1}], Values: [{2}, {3}]",
min, max, yMin, yMax);
min, max, yMin, yMax);
}
} else if (sign < 0){
// solve using only the first endpoint as initial guess
@ -194,7 +194,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
return ret;
}
/**
* Find a zero starting search according to the three provided points.
* @param f the function to solve
@ -210,7 +210,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
* @throws MaxIterationsExceededException if the maximum iteration count
* is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating
* the function
* the function
*/
private double solve(final UnivariateRealFunction f,
double x0, double y0,
@ -286,7 +286,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
delta = p / p1;
}
}
// Save old X1, Y1
// Save old X1, Y1
x0 = x1;
y0 = y1;
// Compute new X1, Y1

View File

@ -73,7 +73,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/**
* Returns a copy of the polynomial function.
*
*
* @return a fresh copy of the polynomial function
* @deprecated as of 2.0 the function is not stored anymore within the instance.
*/
@ -100,7 +100,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
* Find a real root in the given interval with initial value.
* <p>
* Requires bracketing condition.</p>
*
*
* @param f function to solve (must be polynomial)
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -147,7 +147,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
* @throws ConvergenceException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public double solve(final UnivariateRealFunction f,
@ -192,7 +192,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/**
* Returns true iff the given complex root is actually a real zero
* in the given interval, within the solver tolerance level.
*
*
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @param z the complex root
@ -208,14 +208,14 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/**
* Find all complex roots for the polynomial with the given coefficients,
* starting from the given initial value.
*
*
* @param coefficients the polynomial coefficients array
* @param initial the start value to use
* @return the point at which the function value is zero
* @throws ConvergenceException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public Complex[] solveAll(double coefficients[], double initial) throws
@ -232,14 +232,14 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/**
* Find all complex roots for the polynomial with the given coefficients,
* starting from the given initial value.
*
*
* @param coefficients the polynomial coefficients array
* @param initial the start value to use
* @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public Complex[] solveAll(Complex coefficients[], Complex initial) throws
@ -281,14 +281,14 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/**
* Find a complex root for the polynomial with the given coefficients,
* starting from the given initial value.
*
*
* @param coefficients the polynomial coefficients array
* @param initial the start value to use
* @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public Complex solve(Complex coefficients[], Complex initial) throws

View File

@ -39,7 +39,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver for the given function.
*
*
* @param f function to solve
* @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or
@ -76,7 +76,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* Find a real root in the given interval with initial value.
* <p>
* Requires bracketing condition.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -120,7 +120,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* bisection as a safety backup if it performs very poorly.</p>
* <p>
* The formulas here use divided differences directly.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -128,7 +128,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public double solve(final UnivariateRealFunction f,
@ -228,14 +228,14 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* approximation is often negligible.</p>
* <p>
* The formulas here do not use divided differences directly.</p>
*
*
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
* @deprecated replaced by {@link #solve2(UnivariateRealFunction, double, double)}
* since 2.0
@ -261,7 +261,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* approximation is often negligible.</p>
* <p>
* The formulas here do not use divided differences directly.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -269,7 +269,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public double solve2(final UnivariateRealFunction f,

View File

@ -25,14 +25,14 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements <a href="http://mathworld.wolfram.com/NewtonsMethod.html">
* Newton's Method</a> for finding zeros of real univariate functions.
* <p>
* Newton's Method</a> for finding zeros of real univariate functions.
* <p>
* The function should be continuous but not necessarily smooth.</p>
*
* @version $Revision$ $Date$
*/
public class NewtonSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver for the given function.
* @param f function to solve.
@ -56,7 +56,7 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
/** {@inheritDoc} */
@Deprecated
public double solve(final double min, final double max)
throws MaxIterationsExceededException,
throws MaxIterationsExceededException,
FunctionEvaluationException {
return solve(f, min, max);
}
@ -70,12 +70,12 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
/**
* Find a zero near the midpoint of <code>min</code> and <code>max</code>.
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the value where the function is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function or derivative
* @throws IllegalArgumentException if min is not less than max
@ -88,13 +88,13 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
/**
* Find a zero near the value <code>startValue</code>.
*
*
* @param f the function to solve
* @param min the lower bound for the interval (ignored).
* @param max the upper bound for the interval (ignored).
* @param startValue the start value to use.
* @return the value where the function is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function or derivative
* @throws IllegalArgumentException if startValue is not between min and max or
@ -132,5 +132,5 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
throw MathRuntimeException.createIllegalArgumentException("function is not differentiable");
}
}
}

View File

@ -30,7 +30,7 @@ import org.apache.commons.math.util.MathUtils;
* Systems, 26 (1979), 979 - 980.
* <p>
* The function should be continuous but not necessarily smooth.</p>
*
*
* @version $Revision$ $Date$
* @since 1.2
*/
@ -38,7 +38,7 @@ public class RiddersSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver for the given function.
*
*
* @param f function to solve
* @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or
@ -75,7 +75,7 @@ public class RiddersSolver extends UnivariateRealSolverImpl {
* Find a root in the given interval with initial value.
* <p>
* Requires bracketing condition.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -108,14 +108,14 @@ public class RiddersSolver extends UnivariateRealSolverImpl {
* Find a root in the given interval.
* <p>
* Requires bracketing condition.</p>
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
public double solve(final UnivariateRealFunction f,

View File

@ -24,23 +24,23 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements a modified version of the
* Implements a modified version of the
* <a href="http://mathworld.wolfram.com/SecantMethod.html">secant method</a>
* for approximating a zero of a real univariate function.
* for approximating a zero of a real univariate function.
* <p>
* The algorithm is modified to maintain bracketing of a root by successive
* approximations. Because of forced bracketing, convergence may be slower than
* the unrestricted secant algorithm. However, this implementation should in
* general outperform the
* general outperform the
* <a href="http://mathworld.wolfram.com/MethodofFalsePosition.html">
* regula falsi method.</a></p>
* <p>
* The function is assumed to be continuous but not necessarily smooth.</p>
*
*
* @version $Revision$ $Date$
*/
public class SecantSolver extends UnivariateRealSolverImpl {
/**
* Construct a solver for the given function.
* @param f function to solve.
@ -77,7 +77,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
/**
* Find a zero in the given interval.
*
*
* @param f the function to solve
* @param min the lower bound for the interval
* @param max the upper bound for the interval
@ -85,7 +85,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
* @return the value where the function is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if min is not less than max or the
* signs of the values of the function at the endpoints are not opposites
*/
@ -94,7 +94,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
throws MaxIterationsExceededException, FunctionEvaluationException {
return solve(f, min, max);
}
/**
* Find a zero in the given interval.
* @param f the function to solve
@ -103,17 +103,17 @@ public class SecantSolver extends UnivariateRealSolverImpl {
* @return the value where the function is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* function
* @throws IllegalArgumentException if min is not less than max or the
* signs of the values of the function at the endpoints are not opposites
*/
public double solve(final UnivariateRealFunction f,
final double min, final double max)
throws MaxIterationsExceededException, FunctionEvaluationException {
clearResult();
verifyInterval(min, max);
// Index 0 is the old approximation for the root.
// Index 1 is the last calculated approximation for the root.
// Index 2 is a bracket for the root with respect to x0.
@ -123,15 +123,15 @@ public class SecantSolver extends UnivariateRealSolverImpl {
double x1 = max;
double y0 = f.value(x0);
double y1 = f.value(x1);
// Verify bracketing
if (y0 * y1 >= 0) {
throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs, " +
"endpoints: [{0}, {1}], values: [{2}, {3}]",
min, max, y0, y1);
min, max, y0, y1);
}
double x2 = x0;
double y2 = y0;
double oldDelta = x2 - x1;
@ -171,7 +171,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
x1 = x1 + delta;
y1 = f.value(x1);
if ((y1 > 0) == (y2 > 0)) {
// New bracket is (x0,x1).
// New bracket is (x0,x1).
x2 = x0;
y2 = y0;
}

View File

@ -26,7 +26,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* Interface for (univariate real) rootfinding algorithms.
* <p>
* Implementations will search for only one zero in the given interval.</p>
*
*
* @version $Revision$ $Date$
*/
public interface UnivariateRealSolver extends ConvergingAlgorithm {
@ -39,10 +39,10 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* <p>
* This is a safety guard and it shouldn't be necessary to change this in
* general.</p>
*
*
* @param accuracy the accuracy.
* @throws IllegalArgumentException if the accuracy can't be achieved by
* the solver or is otherwise deemed unreasonable.
* the solver or is otherwise deemed unreasonable.
*/
void setFunctionValueAccuracy(double accuracy);
@ -63,7 +63,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* <p>A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.</p>
*
*
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
* @return a value where the function is zero
@ -77,7 +77,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* since 2.0
*/
@Deprecated
double solve(double min, double max) throws ConvergenceException,
double solve(double min, double max) throws ConvergenceException,
FunctionEvaluationException;
/**
@ -85,7 +85,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* <p>A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.</p>
*
*
* @param f the function to solve.
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
@ -99,7 +99,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* @since 2.0
*/
double solve(UnivariateRealFunction f, double min, double max)
throws ConvergenceException,
throws ConvergenceException,
FunctionEvaluationException;
/**
@ -107,7 +107,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* <p>A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.</p>
*
*
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
* @param startValue the start value to use
@ -130,7 +130,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
* <p>A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.</p>
*
*
* @param f the function to solve.
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
@ -149,7 +149,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
/**
* Get the result of the last run of the solver.
*
*
* @return the last result.
* @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed.
@ -158,10 +158,10 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm {
/**
* Get the result of the last run of the solver.
*
*
* @return the value of the function at the last result.
* @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed.
*/
double getFunctionValue();
}
}

View File

@ -51,35 +51,35 @@ public abstract class UnivariateRealSolverFactory {
public static UnivariateRealSolverFactory newInstance() {
return new UnivariateRealSolverFactoryImpl();
}
/**
* Create a new {@link UnivariateRealSolver}. The
* actual solver returned is determined by the underlying factory.
* @return the new solver.
*/
public abstract UnivariateRealSolver newDefaultSolver();
/**
* Create a new {@link UnivariateRealSolver}. The
* solver is an implementation of the bisection method.
* @return the new solver.
*/
public abstract UnivariateRealSolver newBisectionSolver();
/**
* Create a new {@link UnivariateRealSolver}. The
* solver is an implementation of the Brent method.
* @return the new solver.
*/
public abstract UnivariateRealSolver newBrentSolver();
/**
* Create a new {@link UnivariateRealSolver}. The
* solver is an implementation of Newton's Method.
* @return the new solver.
*/
public abstract UnivariateRealSolver newNewtonSolver();
/**
* Create a new {@link UnivariateRealSolver}. The
* solver is an implementation of the secant method.

View File

@ -25,7 +25,7 @@ package org.apache.commons.math.analysis.solvers;
* @version $Revision$ $Date$
*/
public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory {
/**
* Default constructor.
*/
@ -37,7 +37,7 @@ public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory
public UnivariateRealSolver newDefaultSolver() {
return newBrentSolver();
}
/** {@inheritDoc} */
@Override
public UnivariateRealSolver newBisectionSolver() {
@ -49,13 +49,13 @@ public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory
public UnivariateRealSolver newBrentSolver() {
return new BrentSolver();
}
/** {@inheritDoc} */
@Override
public UnivariateRealSolver newNewtonSolver() {
return new NewtonSolver();
}
/** {@inheritDoc} */
@Override
public UnivariateRealSolver newSecantSolver() {

View File

@ -25,7 +25,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Provide a default implementation for several functions useful to generic
* solvers.
*
*
* @version $Revision$ $Date$
*/
public abstract class UnivariateRealSolverImpl
@ -56,11 +56,11 @@ public abstract class UnivariateRealSolverImpl
/**
* Construct a solver with given iteration count and accuracy.
*
*
* @param f the function to solve.
* @param defaultAbsoluteAccuracy maximum absolute error
* @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the
* @throws IllegalArgumentException if f is null or the
* defaultAbsoluteAccuracy is not valid
* @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or
@ -82,10 +82,10 @@ public abstract class UnivariateRealSolverImpl
/**
* Construct a solver with given iteration count and accuracy.
*
*
* @param defaultAbsoluteAccuracy maximum absolute error
* @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the
* @throws IllegalArgumentException if f is null or the
* defaultAbsoluteAccuracy is not valid
*/
protected UnivariateRealSolverImpl(final int defaultMaximalIterationCount,
@ -133,7 +133,7 @@ public abstract class UnivariateRealSolverImpl
/**
* Convenience function for implementations.
*
*
* @param newResult the result to set
* @param iterationCount the iteration count to set
*/
@ -145,7 +145,7 @@ public abstract class UnivariateRealSolverImpl
/**
* Convenience function for implementations.
*
*
* @param x the result to set
* @param fx the result to set
* @param iterationCount the iteration count to set
@ -168,25 +168,25 @@ public abstract class UnivariateRealSolverImpl
/**
* Returns true iff the function takes opposite signs at the endpoints.
*
* @param lower the lower endpoint
*
* @param lower the lower endpoint
* @param upper the upper endpoint
* @param function the function
* @return true if f(lower) * f(upper) < 0
* @throws FunctionEvaluationException if an error occurs evaluating the
* @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints
*/
protected boolean isBracketing(final double lower, final double upper,
protected boolean isBracketing(final double lower, final double upper,
final UnivariateRealFunction function)
throws FunctionEvaluationException {
final double f1 = function.value(lower);
final double f2 = function.value(upper);
return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0));
}
/**
* Returns true if the arguments form a (strictly) increasing sequence
*
*
* @param start first number
* @param mid second number
* @param end third number
@ -195,11 +195,11 @@ public abstract class UnivariateRealSolverImpl
protected boolean isSequence(final double start, final double mid, final double end) {
return (start < mid) && (mid < end);
}
/**
* Verifies that the endpoints specify an interval,
* Verifies that the endpoints specify an interval,
* throws IllegalArgumentException if not
*
*
* @param lower lower endpoint
* @param upper upper endpoint
* @throws IllegalArgumentException
@ -209,13 +209,13 @@ public abstract class UnivariateRealSolverImpl
throw MathRuntimeException.createIllegalArgumentException(
"endpoints do not specify an interval: [{0}, {1}]",
lower, upper);
}
}
}
/**
* Verifies that <code>lower < initial < upper</code>
* throws IllegalArgumentException if not
*
*
* @param lower lower endpoint
* @param initial initial value
* @param upper upper endpoint
@ -226,30 +226,30 @@ public abstract class UnivariateRealSolverImpl
throw MathRuntimeException.createIllegalArgumentException(
"invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}",
lower, initial, upper);
}
}
}
/**
* Verifies that the endpoints specify an interval and the function takes
* opposite signs at the enpoints, throws IllegalArgumentException if not
*
*
* @param lower lower endpoint
* @param upper upper endpoint
* @param function function
* @throws IllegalArgumentException
* @throws FunctionEvaluationException if an error occurs evaluating the
* @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints
*/
protected void verifyBracketing(final double lower, final double upper,
protected void verifyBracketing(final double lower, final double upper,
final UnivariateRealFunction function)
throws FunctionEvaluationException {
verifyInterval(lower, upper);
if (!isBracketing(lower, upper, function)) {
throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs. " +
"Endpoints: [{0}, {1}], Values: [{2}, {3}]",
lower, upper, function.value(lower), function.value(upper));
lower, upper, function.value(lower), function.value(upper));
}
}
}

View File

@ -23,7 +23,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Utility routines for {@link UnivariateRealSolver} objects.
*
*
* @version $Revision$ $Date$
*/
public class UnivariateRealSolverUtils {
@ -33,11 +33,11 @@ public class UnivariateRealSolverUtils {
private UnivariateRealSolverUtils() {
super();
}
/**
* Convenience method to find a zero of a univariate real function. A default
* solver is used.
*
* solver is used.
*
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
@ -56,8 +56,8 @@ public class UnivariateRealSolverUtils {
/**
* Convenience method to find a zero of a univariate real function. A default
* solver is used.
*
* solver is used.
*
* @param f the function
* @param x0 the lower bound for the interval
* @param x1 the upper bound for the interval
@ -66,14 +66,14 @@ public class UnivariateRealSolverUtils {
* @throws ConvergenceException if the iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* @throws IllegalArgumentException if f is null, the endpoints do not
* @throws IllegalArgumentException if f is null, the endpoints do not
* specify a valid interval, or the absoluteAccuracy is not valid for the
* default solver
*/
public static double solve(UnivariateRealFunction f, double x0, double x1,
double absoluteAccuracy) throws ConvergenceException,
FunctionEvaluationException {
double absoluteAccuracy) throws ConvergenceException,
FunctionEvaluationException {
setup(f);
UnivariateRealSolver solver = LazyHolder.FACTORY.newDefaultSolver();
solver.setAbsoluteAccuracy(absoluteAccuracy);
@ -88,24 +88,24 @@ public class UnivariateRealSolverUtils {
* If f is continuous on <code>[a,b],</code> this means that <code>a</code>
* and <code>b</code> bracket a root of f.
* <p>
* The algorithm starts by setting
* The algorithm starts by setting
* <code>a := initial -1; b := initial +1,</code> examines the value of the
* function at <code>a</code> and <code>b</code> and keeps moving
* the endpoints out by one unit each time through a loop that terminates
* the endpoints out by one unit each time through a loop that terminates
* when one of the following happens: <ul>
* <li> <code> f(a) * f(b) < 0 </code> -- success!</li>
* <li> <code> a = lower </code> and <code> b = upper</code>
* <li> <code> a = lower </code> and <code> b = upper</code>
* -- ConvergenceException </li>
* <li> <code> Integer.MAX_VALUE</code> iterations elapse
* <li> <code> Integer.MAX_VALUE</code> iterations elapse
* -- ConvergenceException </li>
* </ul></p>
* <p>
* <strong>Note: </strong> this method can take
* <code>Integer.MAX_VALUE</code> iterations to throw a
* <strong>Note: </strong> this method can take
* <code>Integer.MAX_VALUE</code> iterations to throw a
* <code>ConvergenceException.</code> Unless you are confident that there
* is a root between <code>lowerBound</code> and <code>upperBound</code>
* near <code>initial,</code> it is better to use
* {@link #bracket(UnivariateRealFunction, double, double, double, int)},
* near <code>initial,</code> it is better to use
* {@link #bracket(UnivariateRealFunction, double, double, double, int)},
* explicitly specifying the maximum number of iterations.</p>
*
* @param function the function
@ -121,8 +121,8 @@ public class UnivariateRealSolverUtils {
* @throws IllegalArgumentException if function is null, maximumIterations
* is not positive, or initial is not between lowerBound and upperBound
*/
public static double[] bracket(UnivariateRealFunction function,
double initial, double lowerBound, double upperBound)
public static double[] bracket(UnivariateRealFunction function,
double initial, double lowerBound, double upperBound)
throws ConvergenceException, FunctionEvaluationException {
return bracket( function, initial, lowerBound, upperBound,
Integer.MAX_VALUE ) ;
@ -136,17 +136,17 @@ public class UnivariateRealSolverUtils {
* If f is continuous on <code>[a,b],</code> this means that <code>a</code>
* and <code>b</code> bracket a root of f.
* <p>
* The algorithm starts by setting
* The algorithm starts by setting
* <code>a := initial -1; b := initial +1,</code> examines the value of the
* function at <code>a</code> and <code>b</code> and keeps moving
* the endpoints out by one unit each time through a loop that terminates
* the endpoints out by one unit each time through a loop that terminates
* when one of the following happens: <ul>
* <li> <code> f(a) * f(b) <= 0 </code> -- success!</li>
* <li> <code> a = lower </code> and <code> b = upper</code>
* <li> <code> a = lower </code> and <code> b = upper</code>
* -- ConvergenceException </li>
* <li> <code> maximumIterations</code> iterations elapse
* <li> <code> maximumIterations</code> iterations elapse
* -- ConvergenceException </li></ul></p>
*
*
* @param function the function
* @param initial initial midpoint of interval being expanded to
* bracket a root
@ -157,16 +157,16 @@ public class UnivariateRealSolverUtils {
* @return a two element array holding {a, b}.
* @throws ConvergenceException if the algorithm fails to find a and b
* satisfying the desired conditions
* @throws FunctionEvaluationException if an error occurs evaluating the
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* @throws IllegalArgumentException if function is null, maximumIterations
* is not positive, or initial is not between lowerBound and upperBound
*/
public static double[] bracket(UnivariateRealFunction function,
double initial, double lowerBound, double upperBound,
int maximumIterations) throws ConvergenceException,
double initial, double lowerBound, double upperBound,
int maximumIterations) throws ConvergenceException,
FunctionEvaluationException {
if (function == null) {
throw MathRuntimeException.createIllegalArgumentException("function is null");
}
@ -184,17 +184,17 @@ public class UnivariateRealSolverUtils {
double fa;
double fb;
int numIterations = 0 ;
do {
a = Math.max(a - 1.0, lowerBound);
b = Math.min(b + 1.0, upperBound);
fa = function.value(a);
fb = function.value(b);
numIterations++ ;
} while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
} while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
((a > lowerBound) || (b < upperBound)));
if (fa * fb > 0.0 ) {
throw new ConvergenceException(
"number of iterations={0}, maximum iterations={1}, " +
@ -203,21 +203,21 @@ public class UnivariateRealSolverUtils {
numIterations, maximumIterations, initial,
lowerBound, upperBound, a, b, fa, fb);
}
return new double[]{a, b};
}
/**
* Compute the midpoint of two values.
*
*
* @param a first value.
* @param b second value.
* @return the midpoint.
* @return the midpoint.
*/
public static double midpoint(double a, double b) {
return (a + b) * .5;
}
/**
* Checks to see if f is null, throwing IllegalArgumentException if so.
* @param f input function

View File

@ -19,4 +19,4 @@
<body>
Root finding algorithms, for univariate real functions.
</body>
</html>
</html>

View File

@ -26,29 +26,29 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.util.MathUtils;
/**
* Representation of a Complex number - a number which has both a
* Representation of a Complex number - a number which has both a
* real and imaginary part.
* <p>
* Implementations of arithmetic operations handle <code>NaN</code> and
* infinite values according to the rules for {@link java.lang.Double}
* arithmetic, applying definitional formulas and returning <code>NaN</code> or
* infinite values in real or imaginary parts as these arise in computation.
* infinite values in real or imaginary parts as these arise in computation.
* See individual method javadocs for details.</p>
* <p>
* {@link #equals} identifies all values with <code>NaN</code> in either real
* {@link #equals} identifies all values with <code>NaN</code> in either real
* or imaginary part - e.g., <pre>
* <code>1 + NaNi == NaN + i == NaN + NaNi.</code></pre></p>
*
* implements Serializable since 2.0
*
*
* @version $Revision$ $Date$
*/
public class Complex implements FieldElement<Complex>, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -6195664516687396620L;
/** The square root of -1. A number representing "0.0 + 1.0i" */
/** The square root of -1. A number representing "0.0 + 1.0i" */
public static final Complex I = new Complex(0.0, 1.0);
// CHECKSTYLE: stop ConstantName
@ -59,32 +59,32 @@ public class Complex implements FieldElement<Complex>, Serializable {
/** A complex number representing "+INF + INFi" */
public static final Complex INF = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
/** A complex number representing "1.0 + 0.0i" */
/** A complex number representing "1.0 + 0.0i" */
public static final Complex ONE = new Complex(1.0, 0.0);
/** A complex number representing "0.0 + 0.0i" */
/** A complex number representing "0.0 + 0.0i" */
public static final Complex ZERO = new Complex(0.0, 0.0);
/**
* The imaginary part
/**
* The imaginary part
*/
private final double imaginary;
/**
* The real part
/**
* The real part
*/
private final double real;
/**
* Record whether this complex number is equal to NaN
*/
private final transient boolean isNaN;
/**
* Record whether this complex number is infinite
*/
private final transient boolean isInfinite;
/**
* Create a complex number given the real and imaginary parts.
*
@ -95,7 +95,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
super();
this.real = real;
this.imaginary = imaginary;
isNaN = Double.isNaN(real) || Double.isNaN(imaginary);
isInfinite = !isNaN &&
(Double.isInfinite(real) || Double.isInfinite(imaginary));
@ -115,11 +115,11 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Double.NaN;
}
if (isInfinite()) {
return Double.POSITIVE_INFINITY;
}
if (Math.abs(real) < Math.abs(imaginary)) {
if (imaginary == 0.0) {
return Math.abs(real);
@ -134,11 +134,11 @@ public class Complex implements FieldElement<Complex>, Serializable {
return (Math.abs(real) * Math.sqrt(1 + q*q));
}
}
/**
* Return the sum of this complex number and the given complex number.
* <p>
* Uses the definitional formula
* Uses the definitional formula
* <pre>
* (a + bi) + (c + di) = (a+c) + (b+d)i
* </pre></p>
@ -146,25 +146,25 @@ public class Complex implements FieldElement<Complex>, Serializable {
* If either this or <code>rhs</code> has a NaN value in either part,
* {@link #NaN} is returned; otherwise Inifinite and NaN values are
* returned in the parts of the result according to the rules for
* {@link java.lang.Double} arithmetic.</p>
* {@link java.lang.Double} arithmetic.</p>
*
* @param rhs the other complex number
* @return the complex number sum
* @throws NullPointerException if <code>rhs</code> is null
*/
public Complex add(Complex rhs) {
public Complex add(Complex rhs) {
return createComplex(real + rhs.getReal(),
imaginary + rhs.getImaginary());
}
/**
* Return the conjugate of this complex number. The conjugate of
* "A + Bi" is "A - Bi".
* "A + Bi" is "A - Bi".
* <p>
* {@link #NaN} is returned if either the real or imaginary
* part of this Complex number equals <code>Double.NaN</code>.</p>
* <p>
* If the imaginary part is infinite, and the real part is not NaN,
* If the imaginary part is infinite, and the real part is not NaN,
* the returned value has infinite imaginary part of the opposite
* sign - e.g. the conjugate of <code>1 + POSITIVE_INFINITY i</code>
* is <code>1 - NEGATIVE_INFINITY i</code></p>
@ -174,10 +174,10 @@ public class Complex implements FieldElement<Complex>, Serializable {
public Complex conjugate() {
if (isNaN()) {
return NaN;
}
}
return createComplex(real, -imaginary);
}
/**
* Return the quotient of this complex number and the given complex number.
* <p>
@ -187,7 +187,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* ----------- = -------------------------
* c + di c<sup>2</sup> + d<sup>2</sup>
* </code></pre>
* but uses
* but uses
* <a href="http://doi.acm.org/10.1145/1039813.1039814">
* prescaling of operands</a> to limit the effects of overflows and
* underflows in the computation.</p>
@ -202,13 +202,13 @@ public class Complex implements FieldElement<Complex>, Serializable {
* <li>If this and <code>rhs</code> are both infinite,
* {@link #NaN} is returned.</li>
* <li>If this is finite (i.e., has no infinite or NaN parts) and
* <code>rhs</code> is infinite (one or both parts infinite),
* <code>rhs</code> is infinite (one or both parts infinite),
* {@link #ZERO} is returned.</li>
* <li>If this is infinite and <code>rhs</code> is finite, NaN values are
* returned in the parts of the result if the {@link java.lang.Double}
* rules applied to the definitional formula force NaN results.</li>
* </ul></p>
*
*
* @param rhs the other complex number
* @return the complex number quotient
* @throws NullPointerException if <code>rhs</code> is null
@ -223,7 +223,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (c == 0.0 && d == 0.0) {
return NaN;
}
if (rhs.isInfinite() && !isInfinite()) {
return ZERO;
}
@ -246,7 +246,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
(imaginary - real * q) / denominator);
}
}
/**
* Test for the equality of two Complex objects.
* <p>
@ -256,20 +256,20 @@ public class Complex implements FieldElement<Complex>, Serializable {
* <p>
* All <code>NaN</code> values are considered to be equal - i.e, if either
* (or both) real and imaginary parts of the complex number are equal
* to <code>Double.NaN</code>, the complex number is equal to
* to <code>Double.NaN</code>, the complex number is equal to
* <code>Complex.NaN</code>.</p>
*
* @param other Object to test for equality to this
* @return true if two Complex objects are equal, false if
* object is null, not an instance of Complex, or
* not equal to this Complex instance
*
*
*/
@Override
public boolean equals(Object other) {
boolean ret;
if (this == other) {
if (this == other) {
ret = true;
} else if (other == null) {
ret = false;
@ -279,22 +279,22 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (rhs.isNaN()) {
ret = this.isNaN();
} else {
ret = (real == rhs.real) && (imaginary == rhs.imaginary);
ret = (real == rhs.real) && (imaginary == rhs.imaginary);
}
} catch (ClassCastException ex) {
// ignore exception
ret = false;
}
}
return ret;
}
/**
* Get a hashCode for the complex number.
* <p>
* All NaN values have the same hash code.</p>
*
*
* @return a hash code value for this object
*/
@Override
@ -302,7 +302,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return 7;
}
return 37 * (17 * MathUtils.hash(imaginary) +
return 37 * (17 * MathUtils.hash(imaginary) +
MathUtils.hash(real));
}
@ -323,7 +323,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
public double getReal() {
return real;
}
/**
* Returns true if either or both parts of this complex number is NaN;
* false otherwise
@ -332,22 +332,22 @@ public class Complex implements FieldElement<Complex>, Serializable {
* false otherwise
*/
public boolean isNaN() {
return isNaN;
return isNaN;
}
/**
* Returns true if either the real or imaginary part of this complex number
* takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or
* takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or
* <code>Double.NEGATIVE_INFINITY</code>) and neither part
* is <code>NaN</code>.
*
*
* @return true if one or both parts of this complex number are infinite
* and neither part is <code>NaN</code>
*/
public boolean isInfinite() {
return isInfinite;
return isInfinite;
}
/**
* Return the product of this complex number and the given complex number.
* <p>
@ -370,7 +370,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* Returns finite values in components of the result per the
* definitional formula in all remaining cases.
* </p>
*
*
* @param rhs the other complex number
* @return the complex number product
* @throws NullPointerException if <code>rhs</code> is null
@ -387,7 +387,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
return createComplex(real * rhs.real - imaginary * rhs.imaginary,
real * rhs.imaginary + imaginary * rhs.real);
}
/**
* Return the product of this complex number and the given scalar number.
* <p>
@ -410,7 +410,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* Returns finite values in components of the result per the
* definitional formula in all remaining cases.
* </p>
*
*
* @param rhs the scalar number
* @return the complex number product
*/
@ -425,7 +425,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
}
return createComplex(real * rhs, imaginary * rhs);
}
/**
* Return the additive inverse of this complex number.
* <p>
@ -438,15 +438,15 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return NaN;
}
return createComplex(-real, -imaginary);
}
/**
* Return the difference between this complex number and the given complex
* number.
* <p>
* Uses the definitional formula
* Uses the definitional formula
* <pre>
* (a + bi) - (c + di) = (a-c) + (b-d)i
* </pre></p>
@ -455,7 +455,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* {@link #NaN} is returned; otherwise inifinite and NaN values are
* returned in the parts of the result according to the rules for
* {@link java.lang.Double} arithmetic. </p>
*
*
* @param rhs the other complex number
* @return the complex number difference
* @throws NullPointerException if <code>rhs</code> is null
@ -464,22 +464,22 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN() || rhs.isNaN()) {
return NaN;
}
return createComplex(real - rhs.getReal(),
imaginary - rhs.getImaginary());
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top">
* inverse cosine</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code> acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))</code></pre></p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code> or infinite.</p>
*
*
* @return the inverse cosine of this complex number
* @since 1.2
*/
@ -491,18 +491,18 @@ public class Complex implements FieldElement<Complex>, Serializable {
return this.add(this.sqrt1z().multiply(Complex.I)).log()
.multiply(Complex.I.negate());
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top">
* inverse sine</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code> asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz)) </code></pre></p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code> or infinite.</p>
*
*
* @return the inverse sine of this complex number.
* @since 1.2
*/
@ -514,18 +514,18 @@ public class Complex implements FieldElement<Complex>, Serializable {
return sqrt1z().add(this.multiply(Complex.I)).log()
.multiply(Complex.I.negate());
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top">
* inverse tangent</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code> atan(z) = (i/2) log((i + z)/(i - z)) </code></pre></p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code> or infinite.</p>
*
*
* @return the inverse tangent of this complex number
* @since 1.2
*/
@ -533,13 +533,13 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
return this.add(Complex.I).divide(Complex.I.subtract(this)).log()
.multiply(Complex.I.divide(createComplex(2.0, 0.0)));
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top">
* cosine</a>
* of this complex number.
@ -547,20 +547,20 @@ public class Complex implements FieldElement<Complex>, Serializable {
* Implements the formula: <pre>
* <code> cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* cos(1 &plusmn; INFINITY i) = 1 &#x2213; INFINITY i
* cos(&plusmn;INFINITY + i) = NaN + NaN i
* cos(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>
*
*
* @return the cosine of this complex number
* @since 1.2
*/
@ -568,33 +568,33 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
return createComplex(Math.cos(real) * MathUtils.cosh(imaginary),
-Math.sin(real) * MathUtils.sinh(imaginary));
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top">
* hyperbolic cosine</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code> cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* cosh(1 &plusmn; INFINITY i) = NaN + NaN i
* cosh(&plusmn;INFINITY + i) = INFINITY &plusmn; INFINITY i
* cosh(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>
*
*
* @return the hyperbolic cosine of this complex number.
* @since 1.2
*/
@ -602,11 +602,11 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
return createComplex(MathUtils.cosh(real) * Math.cos(imaginary),
MathUtils.sinh(real) * Math.sin(imaginary));
}
/**
* Compute the
* <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top">
@ -618,18 +618,18 @@ public class Complex implements FieldElement<Complex>, Serializable {
* {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and
* {@link java.lang.Math#sin}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* exp(1 &plusmn; INFINITY i) = NaN + NaN i
* exp(INFINITY + i) = INFINITY + INFINITY i
* exp(-INFINITY + i) = 0 + 0i
* exp(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>
*
*
* @return <i>e</i><sup><code>this</code></sup>
* @since 1.2
*/
@ -637,13 +637,13 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
double expReal = Math.exp(real);
return createComplex(expReal * Math.cos(imaginary), expReal * Math.sin(imaginary));
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/NaturalLogarithm.html" TARGET="_top">
* natural logarithm</a> of this complex number.
* <p>
@ -653,12 +653,12 @@ public class Complex implements FieldElement<Complex>, Serializable {
* <code>|a + bi|</code> is the modulus, {@link Complex#abs}, and
* <code>arg(a + bi) = {@link java.lang.Math#atan2}(b, a)</code></p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite (or critical) values in real or imaginary parts of the input may
* result in infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* log(1 &plusmn; INFINITY i) = INFINITY &plusmn; (&pi;/2)i
* log(INFINITY + i) = INFINITY + 0i
@ -667,7 +667,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* log(-INFINITY &plusmn; INFINITY i) = INFINITY &plusmn; (3&pi;/4)i
* log(0 + 0i) = -INFINITY + 0i
* </code></pre></p>
*
*
* @return ln of this complex number.
* @since 1.2
*/
@ -677,21 +677,21 @@ public class Complex implements FieldElement<Complex>, Serializable {
}
return createComplex(Math.log(abs()),
Math.atan2(imaginary, real));
Math.atan2(imaginary, real));
}
/**
* Returns of value of this complex number raised to the power of <code>x</code>.
* <p>
* Implements the formula: <pre>
* <code> y<sup>x</sup> = exp(x&middot;log(y))</code></pre>
* <code> y<sup>x</sup> = exp(x&middot;log(y))</code></pre>
* where <code>exp</code> and <code>log</code> are {@link #exp} and
* {@link #log}, respectively.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code> or infinite, or if <code>y</code>
* equals {@link Complex#ZERO}.</p>
*
*
* @param x the exponent.
* @return <code>this</code><sup><code>x</code></sup>
* @throws NullPointerException if x is null
@ -703,9 +703,9 @@ public class Complex implements FieldElement<Complex>, Serializable {
}
return this.log().multiply(x).exp();
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/Sine.html" TARGET="_top">
* sine</a>
* of this complex number.
@ -713,20 +713,20 @@ public class Complex implements FieldElement<Complex>, Serializable {
* Implements the formula: <pre>
* <code> sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* sin(1 &plusmn; INFINITY i) = 1 &plusmn; INFINITY i
* sin(&plusmn;INFINITY + i) = NaN + NaN i
* sin(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>
*
*
* @return the sine of this complex number.
* @since 1.2
*/
@ -734,33 +734,33 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
return createComplex(Math.sin(real) * MathUtils.cosh(imaginary),
Math.cos(real) * MathUtils.sinh(imaginary));
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top">
* hyperbolic sine</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code> sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* sinh(1 &plusmn; INFINITY i) = NaN + NaN i
* sinh(&plusmn;INFINITY + i) = &plusmn; INFINITY + INFINITY i
* sinh(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>
*
*
* @return the hyperbolic sine of this complex number
* @since 1.2
*/
@ -768,17 +768,17 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
return createComplex(MathUtils.sinh(real) * Math.cos(imaginary),
MathUtils.cosh(real) * Math.sin(imaginary));
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
* square root</a> of this complex number.
* <p>
* Implements the following algorithm to compute <code>sqrt(a + bi)</code>:
* Implements the following algorithm to compute <code>sqrt(a + bi)</code>:
* <ol><li>Let <code>t = sqrt((|a| + |a + bi|) / 2)</code></li>
* <li><pre>if <code> a &#8805; 0</code> return <code>t + (b/2t)i</code>
* else return <code>|b|/2t + sign(b)t i </code></pre></li>
@ -789,12 +789,12 @@ public class Complex implements FieldElement<Complex>, Serializable {
* <li><code>sign(b) = {@link MathUtils#indicator}(b) </code>
* </ul></p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* sqrt(1 &plusmn; INFINITY i) = INFINITY + NaN i
* sqrt(INFINITY + i) = INFINITY + 0i
@ -802,7 +802,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* sqrt(INFINITY &plusmn; INFINITY i) = INFINITY + NaN i
* sqrt(-INFINITY &plusmn; INFINITY i) = NaN &plusmn; INFINITY i
* </code></pre></p>
*
*
* @return the square root of this complex number
* @since 1.2
*/
@ -810,11 +810,11 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
if (real == 0.0 && imaginary == 0.0) {
return createComplex(0.0, 0.0);
}
double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
if (real >= 0.0) {
return createComplex(t, imaginary / (2.0 * t));
@ -823,52 +823,52 @@ public class Complex implements FieldElement<Complex>, Serializable {
MathUtils.indicator(imaginary) * t);
}
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
* square root</a> of 1 - <code>this</code><sup>2</sup> for this complex
* number.
* <p>
* Computes the result directly as
* Computes the result directly as
* <code>sqrt(Complex.ONE.subtract(z.multiply(z)))</code>.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.</p>
*
*
* @return the square root of 1 - <code>this</code><sup>2</sup>
* @since 1.2
*/
public Complex sqrt1z() {
return createComplex(1.0, 0.0).subtract(this.multiply(this)).sqrt();
}
/**
* Compute the
* Compute the
* <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
* tangent</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code>tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite (or critical) values in real or imaginary parts of the input may
* result in infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* tan(1 &plusmn; INFINITY i) = 0 + NaN i
* tan(&plusmn;INFINITY + i) = NaN + NaN i
* tan(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i
* tan(&plusmn;&pi;/2 + 0 i) = &plusmn;INFINITY + NaN i</code></pre></p>
*
*
* @return the tangent of this complex number
* @since 1.2
*/
@ -876,14 +876,14 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
double d = Math.cos(real2) + MathUtils.cosh(imaginary2);
return createComplex(Math.sin(real2) / d, MathUtils.sinh(imaginary2) / d);
}
/**
* Compute the
* <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top">
@ -892,15 +892,15 @@ public class Complex implements FieldElement<Complex>, Serializable {
* Implements the formula: <pre>
* <code>tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* Examples:
* <code>
* tanh(1 &plusmn; INFINITY i) = NaN + NaN i
* tanh(&plusmn;INFINITY + i) = NaN + 0 i
@ -914,34 +914,34 @@ public class Complex implements FieldElement<Complex>, Serializable {
if (isNaN()) {
return Complex.NaN;
}
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
double d = MathUtils.cosh(real2) + Math.cos(imaginary2);
return createComplex(MathUtils.sinh(real2) / d, Math.sin(imaginary2) / d);
}
/**
* <p>Compute the argument of this complex number.
* </p>
* <p>The argument is the angle phi between the positive real axis and the point
* representing this number in the complex plane. The value returned is between -PI (not inclusive)
* representing this number in the complex plane. The value returned is between -PI (not inclusive)
* and PI (inclusive), with negative values returned for numbers with negative imaginary parts.
* </p>
* <p>If either real or imaginary part (or both) is NaN, NaN is returned. Infinite parts are handled
* as java.Math.atan2 handles them, essentially treating finite parts as zero in the presence of
* an infinite coordinate and returning a multiple of pi/4 depending on the signs of the infinite
* parts. See the javadoc for java.Math.atan2 for full details.</p>
*
*
* @return the argument of this complex number
*/
public double getArgument() {
return Math.atan2(getImaginary(), getReal());
}
/**
* <p>Computes the n-th roots of this complex number.
* </p>
@ -954,7 +954,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* {@link #NaN} is returned.</p>
* <p>if neither part is NaN, but at least one part is infinite, the result is a one-element
* list containing {@link #INF}.</p>
*
*
* @param n degree of root
* @return List<Complex> all nth roots of this complex number
* @throws IllegalArgumentException if parameter n is less than or equal to 0
@ -967,14 +967,14 @@ public class Complex implements FieldElement<Complex>, Serializable {
"cannot compute nth root for null or negative n: {0}",
n);
}
List<Complex> result = new ArrayList<Complex>();
if (isNaN()) {
result.add(Complex.NaN);
return result;
}
if (isInfinite()) {
result.add(Complex.INF);
return result;
@ -1012,14 +1012,14 @@ public class Complex implements FieldElement<Complex>, Serializable {
/**
* <p>Resolve the transient fields in a deserialized Complex Object.</p>
* <p>Subclasses will need to override {@link #createComplex} to deserialize properly</p>
* <p>Subclasses will need to override {@link #createComplex} to deserialize properly</p>
* @return A Complex instance with all fields resolved.
* @since 2.0
*/
protected final Object readResolve() {
return createComplex(real, imaginary);
}
/** {@inheritDoc} */
public ComplexField getField() {
return ComplexField.getInstance();

View File

@ -70,7 +70,7 @@ public class ComplexField implements Field<Complex>, Serializable {
*/
private Object readResolve() {
// return the singleton instance
return LazyHolder.INSTANCE;
return LazyHolder.INSTANCE;
}
}

View File

@ -35,22 +35,22 @@ import org.apache.commons.math.util.CompositeFormat;
* @version $Revision$ $Date$
*/
public class ComplexFormat extends CompositeFormat {
/** Serializable version identifier */
private static final long serialVersionUID = -3343698360149467646L;
/** The default imaginary character. */
private static final String DEFAULT_IMAGINARY_CHARACTER = "i";
/** The notation used to signify the imaginary part of the complex number. */
private String imaginaryCharacter;
/** The format used for the imaginary part. */
private NumberFormat imaginaryFormat;
/** The format used for the real part. */
private NumberFormat realFormat;
/**
* Create an instance with the default imaginary character, 'i', and the
* default number format for both real and imaginary parts.
@ -67,7 +67,7 @@ public class ComplexFormat extends CompositeFormat {
public ComplexFormat(NumberFormat format) {
this(DEFAULT_IMAGINARY_CHARACTER, format);
}
/**
* Create an instance with a custom number format for the real part and a
* custom number format for the imaginary part.
@ -77,7 +77,7 @@ public class ComplexFormat extends CompositeFormat {
public ComplexFormat(NumberFormat realFormat, NumberFormat imaginaryFormat) {
this(DEFAULT_IMAGINARY_CHARACTER, realFormat, imaginaryFormat);
}
/**
* Create an instance with a custom imaginary character, and the default
* number format for both real and imaginary parts.
@ -86,7 +86,7 @@ public class ComplexFormat extends CompositeFormat {
public ComplexFormat(String imaginaryCharacter) {
this(imaginaryCharacter, getDefaultNumberFormat());
}
/**
* Create an instance with a custom imaginary character, and a custom number
* format for both real and imaginary parts.
@ -96,7 +96,7 @@ public class ComplexFormat extends CompositeFormat {
public ComplexFormat(String imaginaryCharacter, NumberFormat format) {
this(imaginaryCharacter, format, (NumberFormat)format.clone());
}
/**
* Create an instance with a custom imaginary character, a custom number
* format for the real part, and a custom number format for the imaginary
@ -115,7 +115,7 @@ public class ComplexFormat extends CompositeFormat {
/**
* Get the set of locales for which complex formats are available.
* <p>This is the same set as the {@link NumberFormat} set.</p>
* <p>This is the same set as the {@link NumberFormat} set.</p>
* @return available complex format locales.
*/
public static Locale[] getAvailableLocales() {
@ -132,7 +132,7 @@ public class ComplexFormat extends CompositeFormat {
public static String formatComplex(Complex c) {
return getInstance().format(c);
}
/**
* Formats a {@link Complex} object to produce a string.
*
@ -144,14 +144,14 @@ public class ComplexFormat extends CompositeFormat {
*/
public StringBuffer format(Complex complex, StringBuffer toAppendTo,
FieldPosition pos) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
// format real
double re = complex.getReal();
formatDouble(re, getRealFormat(), toAppendTo, pos);
// format sign and imaginary
double im = complex.getImaginary();
if (im < 0.0) {
@ -163,12 +163,12 @@ public class ComplexFormat extends CompositeFormat {
formatDouble(im, getImaginaryFormat(), toAppendTo, pos);
toAppendTo.append(getImaginaryCharacter());
}
return toAppendTo;
}
/**
* Formats a object to produce a string. <code>obj</code> must be either a
* Formats a object to produce a string. <code>obj</code> must be either a
* {@link Complex} object or a {@link Number} object. Any other type of
* object will result in an {@link IllegalArgumentException} being thrown.
*
@ -183,20 +183,20 @@ public class ComplexFormat extends CompositeFormat {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo,
FieldPosition pos) {
StringBuffer ret = null;
if (obj instanceof Complex) {
ret = format( (Complex)obj, toAppendTo, pos);
} else if (obj instanceof Number) {
ret = format( new Complex(((Number)obj).doubleValue(), 0.0),
toAppendTo, pos);
} else {
} else {
throw MathRuntimeException.createIllegalArgumentException(
"cannot format a {0} instance as a complex number",
obj.getClass().getName());
}
return ret;
}
@ -207,7 +207,7 @@ public class ComplexFormat extends CompositeFormat {
public String getImaginaryCharacter() {
return imaginaryCharacter;
}
/**
* Access the imaginaryFormat.
* @return the imaginaryFormat.
@ -215,7 +215,7 @@ public class ComplexFormat extends CompositeFormat {
public NumberFormat getImaginaryFormat() {
return imaginaryFormat;
}
/**
* Returns the default complex format for the current locale.
* @return the default complex format.
@ -223,7 +223,7 @@ public class ComplexFormat extends CompositeFormat {
public static ComplexFormat getInstance() {
return getInstance(Locale.getDefault());
}
/**
* Returns the default complex format for the given locale.
* @param locale the specific locale used by the format.
@ -233,7 +233,7 @@ public class ComplexFormat extends CompositeFormat {
NumberFormat f = getDefaultNumberFormat(locale);
return new ComplexFormat(f);
}
/**
* Access the realFormat.
* @return the realFormat.
@ -260,7 +260,7 @@ public class ComplexFormat extends CompositeFormat {
}
return result;
}
/**
* Parses a string to produce a {@link Complex} object.
*
@ -327,7 +327,7 @@ public class ComplexFormat extends CompositeFormat {
return new Complex(re.doubleValue(), im.doubleValue() * sign);
}
/**
* Parses a string to produce a object.
*
@ -354,7 +354,7 @@ public class ComplexFormat extends CompositeFormat {
}
this.imaginaryCharacter = imaginaryCharacter;
}
/**
* Modify the imaginaryFormat.
* @param imaginaryFormat The new imaginaryFormat value.
@ -368,7 +368,7 @@ public class ComplexFormat extends CompositeFormat {
}
this.imaginaryFormat = imaginaryFormat;
}
/**
* Modify the realFormat.
* @param realFormat The new realFormat value.

View File

@ -20,39 +20,39 @@ package org.apache.commons.math.complex;
import org.apache.commons.math.MathRuntimeException;
/**
* Static implementations of common
* Static implementations of common
* {@link org.apache.commons.math.complex.Complex} utilities functions.
*
* @version $Revision$ $Date$
*/
public class ComplexUtils {
/**
* Default constructor.
*/
private ComplexUtils() {
super();
}
/**
* Creates a complex number from the given polar representation.
* <p>
* The value returned is <code>r&middot;e<sup>i&middot;theta</sup></code>,
* computed as <code>r&middot;cos(theta) + r&middot;sin(theta)i</code></p>
* <p>
* If either <code>r</code> or <code>theta</code> is NaN, or
* If either <code>r</code> or <code>theta</code> is NaN, or
* <code>theta</code> is infinite, {@link Complex#NaN} is returned.</p>
* <p>
* If <code>r</code> is infinite and <code>theta</code> is finite,
* If <code>r</code> is infinite and <code>theta</code> is finite,
* infinite or NaN values may be returned in parts of the result, following
* the rules for double arithmetic.<pre>
* Examples:
* Examples:
* <code>
* polar2Complex(INFINITY, &pi;/4) = INFINITY + INFINITY i
* polar2Complex(INFINITY, 0) = INFINITY + NaN i
* polar2Complex(INFINITY, -&pi;/4) = INFINITY - INFINITY i
* polar2Complex(INFINITY, 5&pi;/4) = -INFINITY - INFINITY i </code></pre></p>
*
*
* @param r the modulus of the complex number to create
* @param theta the argument of the complex number to create
* @return <code>r&middot;e<sup>i&middot;theta</sup></code>
@ -66,5 +66,5 @@ public class ComplexUtils {
}
return new Complex(r * Math.cos(theta), r * Math.sin(theta));
}
}

View File

@ -20,4 +20,4 @@
Complex number type and implementations of complex transcendental
functions.
</body>
</html>
</html>

View File

@ -29,7 +29,7 @@ import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
* Base class for continuous distributions. Default implementations are
* provided for some of the methods that do not vary from distribution to
* distribution.
*
*
* @version $Revision$ $Date$
*/
public abstract class AbstractContinuousDistribution
@ -38,7 +38,7 @@ public abstract class AbstractContinuousDistribution
/** Serializable version identifier */
private static final long serialVersionUID = -38038050983108802L;
/**
* Default constructor.
*/
@ -76,8 +76,8 @@ public abstract class AbstractContinuousDistribution
}
}
};
// Try to bracket root, test domain endoints if this fails
// Try to bracket root, test domain endoints if this fails
double lowerBound = getDomainLowerBound(p);
double upperBound = getDomainUpperBound(p);
double[] bracket = null;
@ -86,20 +86,20 @@ public abstract class AbstractContinuousDistribution
rootFindingFunction, getInitialDomain(p),
lowerBound, upperBound);
} catch (ConvergenceException ex) {
/*
/*
* Check domain endpoints to see if one gives value that is within
* the default solver's defaultAbsoluteAccuracy of 0 (will be the
* case if density has bounded support and p is 0 or 1).
*
*
* TODO: expose the default solver, defaultAbsoluteAccuracy as
* a constant.
*/
*/
if (Math.abs(rootFindingFunction.value(lowerBound)) < 1E-6) {
return lowerBound;
}
if (Math.abs(rootFindingFunction.value(upperBound)) < 1E-6) {
return upperBound;
}
}
// Failed bracket convergence was not because of corner solution
throw new MathException(ex);
}
@ -114,7 +114,7 @@ public abstract class AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -124,10 +124,10 @@ public abstract class AbstractContinuousDistribution
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
protected abstract double getDomainLowerBound(double p);
@ -135,10 +135,10 @@ public abstract class AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
protected abstract double getDomainUpperBound(double p);
}

View File

@ -22,8 +22,8 @@ import org.apache.commons.math.MathException;
import org.apache.commons.math.MathRuntimeException;
/**
* Base class for probability distributions.
*
* Base class for probability distributions.
*
* @version $Revision$ $Date$
*/
public abstract class AbstractDistribution
@ -31,7 +31,7 @@ public abstract class AbstractDistribution
/** Serializable version identifier */
private static final long serialVersionUID = -38038050983108802L;
/**
* Default constructor.
*/
@ -46,7 +46,7 @@ public abstract class AbstractDistribution
* The default implementation uses the identity</p>
* <p>
* P(x0 &le; X &le; x1) = P(X &le; x1) - P(X &le; x0) </p>
*
*
* @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution

View File

@ -26,31 +26,31 @@ import org.apache.commons.math.MathRuntimeException;
* Base class for integer-valued discrete distributions. Default
* implementations are provided for some of the methods that do not vary
* from distribution to distribution.
*
*
* @version $Revision$ $Date$
*/
public abstract class AbstractIntegerDistribution extends AbstractDistribution
implements IntegerDistribution, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -1146319659338487221L;
/**
* Default constructor.
*/
protected AbstractIntegerDistribution() {
super();
}
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(X &le; x). In other words,
* this method represents the (cumulative) distribution function, or
* CDF, for this distribution.
* <p>
* If <code>x</code> does not represent an integer value, the CDF is
* If <code>x</code> does not represent an integer value, the CDF is
* evaluated at the greatest integer less than x.
*
*
* @param x the value at which the distribution function is evaluated.
* @return cumulative probability that a random variable with this
* distribution takes a value less than or equal to <code>x</code>
@ -58,13 +58,13 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException {
return cumulativeProbability((int) Math.floor(x));
return cumulativeProbability((int) Math.floor(x));
}
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(x0 &le; X &le; x1).
*
*
* @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution
@ -87,30 +87,30 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
(int) Math.floor(x1)); // don't want to count mass below x0
} else { // x0 is mathematical integer, so use as is
return cumulativeProbability((int) Math.floor(x0),
(int) Math.floor(x1));
(int) Math.floor(x1));
}
}
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(X &le; x). In other words,
* this method represents the probability distribution function, or PDF,
* for this distribution.
*
*
* @param x the value at which the PDF is evaluated.
* @return PDF for this distribution.
* @return PDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
abstract public double cumulativeProbability(int x) throws MathException;
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(X = x). In other words, this
* method represents the probability mass function, or PMF, for the distribution.
* <p>
* If <code>x</code> does not represent an integer value, 0 is returned.
*
*
* @param x the value at which the probability density function is evaluated
* @return the value of the probability density function at x
*/
@ -122,14 +122,14 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
return 0;
}
}
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(x0 &le; X &le; x1).
*
*
* @param x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound
* @return the cumulative probability.
* @return the cumulative probability.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
* @throws IllegalArgumentException if x0 > x1
@ -142,7 +142,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
}
return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns the largest x, such
@ -159,7 +159,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
throw MathRuntimeException.createIllegalArgumentException(
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
// by default, do simple bisection.
// subclasses can override if there is a better method.
int x0 = getDomainLowerBound(p);
@ -190,36 +190,36 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
}
}
}
// insure x0 is the correct critical point
pm = cumulativeProbability(x0);
while (pm > p) {
--x0;
pm = cumulativeProbability(x0);
}
return x0;
return x0;
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
protected abstract int getDomainLowerBound(double p);
/**
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
protected abstract int getDomainUpperBound(double p);
}

View File

@ -35,22 +35,22 @@ public interface BinomialDistribution extends IntegerDistribution {
* @return the number of trials.
*/
int getNumberOfTrials();
/**
* Access the probability of success for this distribution.
* @return the probability of success.
*/
double getProbabilityOfSuccess();
/**
* Change the number of trials for this distribution.
* @param trials the new number of trials.
*/
void setNumberOfTrials(int trials);
/**
* Change the probability of success for this distribution.
* @param p the new probability of success.
*/
void setProbabilityOfSuccess(double p);
}
}

View File

@ -100,10 +100,10 @@ public class BinomialDistributionImpl
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected int getDomainLowerBound(double p) {
@ -113,10 +113,10 @@ public class BinomialDistributionImpl
/**
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected int getDomainUpperBound(double p) {
@ -126,7 +126,7 @@ public class BinomialDistributionImpl
/**
* For this distribution, X, this method returns P(X &le; x).
* @param x the value at which the PDF is evaluated.
* @return PDF for this distribution.
* @return PDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
@ -149,9 +149,9 @@ public class BinomialDistributionImpl
/**
* For this distribution, X, this method returns P(X = x).
*
*
* @param x the value at which the PMF is evaluated.
* @return PMF for this distribution.
* @return PMF for this distribution.
*/
public double probability(int x) {
double ret;
@ -166,7 +166,7 @@ public class BinomialDistributionImpl
}
return ret;
}
/**
* For this distribution, X, this method returns the largest x, such
* that P(X &le; x) &le; <code>p</code>.
@ -185,11 +185,11 @@ public class BinomialDistributionImpl
// handle extreme values explicitly
if (p == 0) {
return -1;
}
if (p == 1) {
return Integer.MAX_VALUE;
}
if (p == 1) {
return Integer.MAX_VALUE;
}
// use default bisection impl
return super.inverseCumulativeProbability(p);
}

View File

@ -32,25 +32,25 @@ package org.apache.commons.math.distribution;
* @version $Revision$ $Date$
*/
public interface CauchyDistribution extends ContinuousDistribution {
/**
* Access the median.
* @return median for this distribution
*/
double getMedian();
/**
* Access the scale parameter.
* @return scale parameter for this distribution
*/
double getScale();
/**
* Modify the median.
* @param median for this distribution
*/
void setMedian(double median);
/**
* Modify the scale parameter.
* @param s scale parameter for this distribution

View File

@ -28,26 +28,26 @@ import org.apache.commons.math.MathRuntimeException;
* @since 1.1
* @version $Revision$ $Date$
*/
public class CauchyDistributionImpl extends AbstractContinuousDistribution
public class CauchyDistributionImpl extends AbstractContinuousDistribution
implements CauchyDistribution, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = 8589540077390120676L;
/** The median of this distribution. */
private double median = 0;
/** The scale of this distribution. */
private double scale = 1;
/**
* Creates cauchy distribution with the medain equal to zero and scale
* equal to one.
* equal to one.
*/
public CauchyDistributionImpl(){
this(0.0, 1.0);
}
/**
* Create a cauchy distribution using the given median and scale.
* @param median median for this distribution
@ -62,16 +62,16 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
/**
* For this distribution, X, this method returns P(X &lt; <code>x</code>).
* @param x the value at which the CDF is evaluated.
* @return CDF evaluted at <code>x</code>.
* @return CDF evaluted at <code>x</code>.
*/
public double cumulativeProbability(double x) {
return 0.5 + (Math.atan((x - median) / scale) / Math.PI);
}
/**
* Access the median.
* @return median for this distribution
*/
*/
public double getMedian() {
return median;
}
@ -83,12 +83,12 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
public double getScale() {
return scale;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
* <p>
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
*
* @param p the desired probability
@ -111,7 +111,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
}
return ret;
}
/**
* Modify the median.
* @param median for this distribution
@ -129,18 +129,18 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
if (s <= 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"scale must be positive ({0})", s);
}
}
scale = s;
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -151,7 +151,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
} else {
ret = getMedian();
}
return ret;
}
@ -159,10 +159,10 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -173,7 +173,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
} else {
ret = Double.MAX_VALUE;
}
return ret;
}
@ -181,7 +181,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -196,7 +196,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
} else {
ret = getMedian();
}
return ret;
}
}

View File

@ -35,7 +35,7 @@ public interface ChiSquaredDistribution extends ContinuousDistribution, HasDensi
* @param degreesOfFreedom the new degrees of freedom.
*/
void setDegreesOfFreedom(double degreesOfFreedom);
/**
* Access the degrees of freedom.
* @return the degrees of freedom.
@ -48,4 +48,4 @@ public interface ChiSquaredDistribution extends ContinuousDistribution, HasDensi
* @return The pdf at point x.
*/
double density(Double x);
}
}

View File

@ -28,13 +28,13 @@ import org.apache.commons.math.MathException;
public class ChiSquaredDistributionImpl
extends AbstractContinuousDistribution
implements ChiSquaredDistribution, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -8352658048349159782L;
/** Internal Gamma distribution. */
/** Internal Gamma distribution. */
private GammaDistribution gamma;
/**
* Create a Chi-Squared distribution with the given degrees of freedom.
* @param df degrees of freedom.
@ -42,7 +42,7 @@ public class ChiSquaredDistributionImpl
public ChiSquaredDistributionImpl(double df) {
this(df, new GammaDistributionImpl(df / 2.0, 2.0));
}
/**
* Create a Chi-Squared distribution with the given degrees of freedom.
* @param df degrees of freedom.
@ -54,7 +54,7 @@ public class ChiSquaredDistributionImpl
setGamma(g);
setDegreesOfFreedom(df);
}
/**
* Modify the degrees of freedom.
* @param degreesOfFreedom the new degrees of freedom.
@ -62,7 +62,7 @@ public class ChiSquaredDistributionImpl
public void setDegreesOfFreedom(double degreesOfFreedom) {
getGamma().setAlpha(degreesOfFreedom / 2.0);
}
/**
* Access the degrees of freedom.
* @return the degrees of freedom.
@ -84,14 +84,14 @@ public class ChiSquaredDistributionImpl
/**
* For this distribution, X, this method returns P(X &lt; x).
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
* @return CDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException {
return getGamma().cumulativeProbability(x);
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
@ -116,15 +116,15 @@ public class ChiSquaredDistributionImpl
}
return super.inverseCumulativeProbability(p);
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -135,10 +135,10 @@ public class ChiSquaredDistributionImpl
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -154,7 +154,7 @@ public class ChiSquaredDistributionImpl
// use max
ret = Double.MAX_VALUE;
}
return ret;
}
@ -162,7 +162,7 @@ public class ChiSquaredDistributionImpl
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -170,7 +170,7 @@ public class ChiSquaredDistributionImpl
protected double getInitialDomain(double p) {
// NOTE: chi squared is skewed to the left
// NOTE: therefore, P(X < &mu;) > .5
double ret;
if (p < .5) {
@ -180,10 +180,10 @@ public class ChiSquaredDistributionImpl
// use mean
ret = getDegreesOfFreedom();
}
return ret;
}
/**
* Modify the underlying gamma distribution. The caller is responsible for
* insuring the gamma distribution has the proper parameter settings.
@ -192,7 +192,7 @@ public class ChiSquaredDistributionImpl
*/
public void setGamma(GammaDistribution g) {
this.gamma = g;
}
/**

View File

@ -24,11 +24,11 @@ import org.apache.commons.math.MathException;
* @version $Revision$ $Date$
*/
public interface ContinuousDistribution extends Distribution {
/**
* For this distribution, X, this method returns x such that P(X &lt; x) = p.
* @param p the cumulative probability.
* @return x.
* @return x.
* @throws MathException if the inverse cumulative probability can not be
* computed due to convergence or other numerical errors.
*/

View File

@ -27,7 +27,7 @@ public interface DiscreteDistribution extends Distribution {
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(X = x). In other words, this
* method represents the probability mass function, or PMF for the distribution.
*
*
* @param x the value at which the probability mass function is evaluated.
* @return the value of the probability mass function at x
*/

View File

@ -29,7 +29,7 @@ public interface Distribution {
* to this distribution, this method returns P(X &le; x). In other words,
* this method represents the (cumulative) distribution function, or
* CDF, for this distribution.
*
*
* @param x the value at which the distribution function is evaluated.
* @return the probability that a random variable with this
* distribution takes a value less than or equal to <code>x</code>
@ -37,15 +37,15 @@ public interface Distribution {
* computed due to convergence or other numerical errors.
*/
double cumulativeProbability(double x) throws MathException;
/**
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(x0 &le; X &le; x1).
*
*
* @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution
* will take a value between <code>x0</code> and <code>x1</code>,
* will take a value between <code>x0</code> and <code>x1</code>,
* including the endpoints
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.

View File

@ -35,7 +35,7 @@ public interface ExponentialDistribution extends ContinuousDistribution, HasDens
* @param mean the new mean.
*/
void setMean(double mean);
/**
* Access the mean.
* @return the mean.
@ -48,4 +48,4 @@ public interface ExponentialDistribution extends ContinuousDistribution, HasDens
* @return The pdf at point x.
*/
double density(Double x);
}
}

View File

@ -31,10 +31,10 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
/** Serializable version identifier */
private static final long serialVersionUID = 2401296428283614780L;
/** The mean of this distribution. */
private double mean;
/**
* Create a exponential distribution with the given mean.
* @param mean mean of this distribution.
@ -80,14 +80,14 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
/**
* For this distribution, X, this method returns P(X &lt; x).
*
*
* The implementation of this method is based on:
* <ul>
* <li>
* <a href="http://mathworld.wolfram.com/ExponentialDistribution.html">
* Exponential Distribution</a>, equation (1).</li>
* </ul>
*
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
* @throws MathException if the cumulative probability can not be
@ -102,13 +102,13 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
}
return ret;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
* <p>
* Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
*
*
* @param p the desired probability
* @return x, such that P(X &lt; x) = <code>p</code>
* @throws MathException if the inverse cumulative probability can not be
@ -118,7 +118,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
@Override
public double inverseCumulativeProbability(double p) throws MathException {
double ret;
if (p < 0.0 || p > 1.0) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
@ -127,14 +127,14 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
} else {
ret = -getMean() * Math.log(1.0 - p);
}
return ret;
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root.
*
* bracket a CDF root.
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
@ -143,14 +143,14 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
protected double getDomainLowerBound(double p) {
return 0;
}
/**
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root.
*
* bracket a CDF root.
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -165,11 +165,11 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
return Double.MAX_VALUE;
}
}
/**
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root.
*
* bracket a CDF root.
*
* @param p the desired probability for the critical value
* @return initial domain value
*/

View File

@ -35,19 +35,19 @@ public interface FDistribution extends ContinuousDistribution {
* @param degreesOfFreedom the new numerator degrees of freedom.
*/
void setNumeratorDegreesOfFreedom(double degreesOfFreedom);
/**
* Access the numerator degrees of freedom.
* @return the numerator degrees of freedom.
*/
double getNumeratorDegreesOfFreedom();
/**
* Modify the denominator degrees of freedom.
* @param degreesOfFreedom the new denominator degrees of freedom.
*/
void setDenominatorDegreesOfFreedom(double degreesOfFreedom);
/**
* Access the denominator degrees of freedom.
* @return the denominator degrees of freedom.

View File

@ -40,7 +40,7 @@ public class FDistributionImpl
/** The numerator degrees of freedom*/
private double denominatorDegreesOfFreedom;
/**
* Create a F distribution using the given degrees of freedom.
* @param numeratorDegreesOfFreedom the numerator degrees of freedom.
@ -52,19 +52,19 @@ public class FDistributionImpl
setNumeratorDegreesOfFreedom(numeratorDegreesOfFreedom);
setDenominatorDegreesOfFreedom(denominatorDegreesOfFreedom);
}
/**
* For this distribution, X, this method returns P(X &lt; x).
*
*
* The implementation of this method is based on:
* <ul>
* <li>
* <a href="http://mathworld.wolfram.com/F-Distribution.html">
* F-Distribution</a>, equation (4).</li>
* </ul>
*
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
* @return CDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
@ -75,14 +75,14 @@ public class FDistributionImpl
} else {
double n = getNumeratorDegreesOfFreedom();
double m = getDenominatorDegreesOfFreedom();
ret = Beta.regularizedBeta((n * x) / (m + n * x),
0.5 * n,
0.5 * m);
}
return ret;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
@ -97,7 +97,7 @@ public class FDistributionImpl
* probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p == 0) {
return 0d;
@ -107,15 +107,15 @@ public class FDistributionImpl
}
return super.inverseCumulativeProbability(p);
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -126,10 +126,10 @@ public class FDistributionImpl
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -140,7 +140,7 @@ public class FDistributionImpl
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -154,7 +154,7 @@ public class FDistributionImpl
}
return ret;
}
/**
* Modify the numerator degrees of freedom.
* @param degreesOfFreedom the new numerator degrees of freedom.
@ -169,7 +169,7 @@ public class FDistributionImpl
}
this.numeratorDegreesOfFreedom = degreesOfFreedom;
}
/**
* Access the numerator degrees of freedom.
* @return the numerator degrees of freedom.
@ -177,7 +177,7 @@ public class FDistributionImpl
public double getNumeratorDegreesOfFreedom() {
return numeratorDegreesOfFreedom;
}
/**
* Modify the denominator degrees of freedom.
* @param degreesOfFreedom the new denominator degrees of freedom.
@ -192,7 +192,7 @@ public class FDistributionImpl
}
this.denominatorDegreesOfFreedom = degreesOfFreedom;
}
/**
* Access the denominator degrees of freedom.
* @return the denominator degrees of freedom.

View File

@ -35,19 +35,19 @@ public interface GammaDistribution extends ContinuousDistribution, HasDensity<Do
* @param alpha the new shape parameter.
*/
void setAlpha(double alpha);
/**
* Access the shape parameter, alpha
* @return alpha.
*/
double getAlpha();
/**
* Modify the scale parameter, beta.
* @param beta the new scale parameter.
*/
void setBeta(double beta);
/**
* Access the scale parameter, beta
* @return beta.

View File

@ -35,10 +35,10 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
/** The shape parameter. */
private double alpha;
/** The scale parameter. */
private double beta;
/**
* Create a new gamma distribution with the given alpha and beta values.
* @param alpha the shape parameter.
@ -49,10 +49,10 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
setAlpha(alpha);
setBeta(beta);
}
/**
* For this distribution, X, this method returns P(X &lt; x).
*
*
* The implementation of this method is based on:
* <ul>
* <li>
@ -61,24 +61,24 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* <li>Casella, G., & Berger, R. (1990). <i>Statistical Inference</i>.
* Belmont, CA: Duxbury Press.</li>
* </ul>
*
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
* @return CDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException{
double ret;
if (x <= 0.0) {
ret = 0.0;
} else {
ret = Gamma.regularizedGammaP(getAlpha(), x / getBeta());
}
return ret;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
@ -93,7 +93,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p == 0) {
return 0d;
@ -103,7 +103,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
}
return super.inverseCumulativeProbability(p);
}
/**
* Modify the shape parameter, alpha.
* @param alpha the new shape parameter.
@ -117,7 +117,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
}
this.alpha = alpha;
}
/**
* Access the shape parameter, alpha
* @return alpha.
@ -125,7 +125,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
public double getAlpha() {
return alpha;
}
/**
* Modify the scale parameter, beta.
* @param beta the new scale parameter.
@ -139,7 +139,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
}
this.beta = beta;
}
/**
* Access the scale parameter, beta
* @return beta.
@ -163,7 +163,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
@ -178,10 +178,10 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -198,7 +198,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
// use max value
ret = Double.MAX_VALUE;
}
return ret;
}
@ -206,7 +206,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -224,7 +224,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
// use mean
ret = getAlpha() * getBeta();
}
return ret;
}
}

View File

@ -36,31 +36,31 @@ public interface HypergeometricDistribution extends IntegerDistribution {
* @return the number of successes.
*/
public abstract int getNumberOfSuccesses();
/**
* Access the population size.
* @return the population size.
*/
public abstract int getPopulationSize();
/**
* Access the sample size.
* @return the sample size.
*/
public abstract int getSampleSize();
/**
* Modify the number of successes.
* @param num the new number of successes.
*/
public abstract void setNumberOfSuccesses(int num);
/**
* Modify the population size.
* @param size the new population size.
*/
public abstract void setPopulationSize(int size);
/**
* Modify the sample size.
* @param size the new sample size.

View File

@ -28,7 +28,7 @@ import org.apache.commons.math.util.MathUtils;
* @version $Revision$ $Date$
*/
public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
implements HypergeometricDistribution, Serializable
implements HypergeometricDistribution, Serializable
{
/** Serializable version identifier */
@ -36,13 +36,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
/** The number of successes in the population. */
private int numberOfSuccesses;
/** The population size. */
private int populationSize;
/** The sample size. */
private int sampleSize;
/**
* Construct a new hypergeometric distribution with the given the population
* size, the number of successes in the population, and the sample size.
@ -71,12 +71,12 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
/**
* For this distribution, X, this method returns P(X &le; x).
* @param x the value at which the PDF is evaluated.
* @return PDF for this distribution.
* @return PDF for this distribution.
*/
@Override
public double cumulativeProbability(int x) {
double ret;
int n = getPopulationSize();
int m = getNumberOfSuccesses();
int k = getSampleSize();
@ -89,7 +89,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else {
ret = innerCumulativeProbability(domain[0], x, 1, n, m, k);
}
return ret;
}
@ -99,7 +99,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* @param m number of successes in the population.
* @param k the sample size.
* @return a two element array containing the lower and upper bounds of the
* hypergeometric distribution.
* hypergeometric distribution.
*/
private int[] getDomain(int n, int m, int k){
return new int[]{
@ -107,28 +107,28 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
getUpperDomain(m, k)
};
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected int getDomainLowerBound(double p) {
return getLowerDomain(getPopulationSize(), getNumberOfSuccesses(),
getSampleSize());
}
/**
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected int getDomainUpperBound(double p) {
@ -141,7 +141,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* @param n the population size.
* @param m number of successes in the population.
* @param k the sample size.
* @return the lowest domain value of the hypergeometric distribution.
* @return the lowest domain value of the hypergeometric distribution.
*/
private int getLowerDomain(int n, int m, int k) {
return Math.max(0, m - (n - k));
@ -176,7 +176,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* parameters.
* @param m number of successes in the population.
* @param k the sample size.
* @return the highest domain value of the hypergeometric distribution.
* @return the highest domain value of the hypergeometric distribution.
*/
private int getUpperDomain(int m, int k){
return Math.min(k, m);
@ -184,13 +184,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
/**
* For this distribution, X, this method returns P(X = x).
*
*
* @param x the value at which the PMF is evaluated.
* @return PMF for this distribution.
* @return PMF for this distribution.
*/
public double probability(int x) {
double ret;
int n = getPopulationSize();
int m = getNumberOfSuccesses();
int k = getSampleSize();
@ -201,19 +201,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else {
ret = probability(n, m, k, x);
}
return ret;
}
/**
* For the distribution, X, defined by the given hypergeometric distribution
* parameters, this method returns P(X = x).
*
*
* @param n the population size.
* @param m number of successes in the population.
* @param k the sample size.
* @param x the value at which the PMF is evaluated.
* @return PMF for the distribution.
* @return PMF for the distribution.
*/
private double probability(int n, int m, int k, int x) {
return Math.exp(MathUtils.binomialCoefficientLog(m, x) +
@ -248,7 +248,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
}
populationSize = size;
}
/**
* Modify the sample size.
* @param size the new sample size.
@ -259,7 +259,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
throw MathRuntimeException.createIllegalArgumentException(
"sample size must be positive ({0})",
size);
}
}
sampleSize = size;
}
@ -271,7 +271,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
*/
public double upperCumulativeProbability(int x) {
double ret;
int n = getPopulationSize();
int m = getNumberOfSuccesses();
int k = getSampleSize();
@ -284,14 +284,14 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else {
ret = innerCumulativeProbability(domain[1], x, -1, n, m, k);
}
return ret;
}
/**
* For this distribution, X, this method returns P(x0 &le; X &le; x1). This
* probability is computed by summing the point probabilities for the values
* x0, x0 + 1, x0 + 2, ..., x1, in the order directed by dx.
* x0, x0 + 1, x0 + 2, ..., x1, in the order directed by dx.
* @param x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound
* @param dx the direction of summation. 1 indicates summing from x0 to x1.
@ -299,7 +299,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* @param n the population size.
* @param m number of successes in the population.
* @param k the sample size.
* @return P(x0 &le; X &le; x1).
* @return P(x0 &le; X &le; x1).
*/
private double innerCumulativeProbability(
int x0, int x1, int dx, int n, int m, int k)

View File

@ -28,7 +28,7 @@ public interface IntegerDistribution extends DiscreteDistribution {
* For a random variable X whose values are distributed according
* to this distribution, this method returns P(X = x). In other words, this
* method represents the probability mass function for the distribution.
*
*
* @param x the value at which the probability density function is evaluated.
* @return the value of the probability density function at x
*/
@ -39,25 +39,25 @@ public interface IntegerDistribution extends DiscreteDistribution {
* to this distribution, this method returns P(X &le; x). In other words,
* this method represents the probability distribution function, or PDF
* for the distribution.
*
*
* @param x the value at which the PDF is evaluated.
* @return PDF for this distribution.
* @return PDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
double cumulativeProbability(int x) throws MathException;
/**
* For this distribution, X, this method returns P(x0 &le; X &le; x1).
* @param x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound
* @return the cumulative probability.
* @return the cumulative probability.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
* @throws IllegalArgumentException if x0 > x1
*/
double cumulativeProbability(int x0, int x1) throws MathException;
/**
* For this distribution, X, this method returns the largest x such that
* P(X &le; x) <= p.
@ -66,14 +66,14 @@ public interface IntegerDistribution extends DiscreteDistribution {
* <li> If there is a minimum value, <code>m</code>, with postive
* probablility under (the density of) X, then <code>m - 1</code> is
* returned by <code>inverseCumulativeProbability(0).</code> If there is
* no such value <code>m, Integer.MIN_VALUE</code> is
* no such value <code>m, Integer.MIN_VALUE</code> is
* returned.</li>
* <li> If there is a maximum value, <code>M</code>, such that
* P(X &le; M) =1, then <code>M</code> is returned by
* P(X &le; M) =1, then <code>M</code> is returned by
* <code>inverseCumulativeProbability(1).</code>
* If there is no such value, <code>M, Integer.MAX_VALUE</code> is
* If there is no such value, <code>M, Integer.MAX_VALUE</code> is
* returned.</li></ul></p>
*
*
* @param p the cumulative probability.
* @return the largest x such that P(X &le; x) <= p
* @throws MathException if the inverse cumulative probability can not be

View File

@ -30,9 +30,9 @@ import org.apache.commons.math.special.Erf;
*
* @version $Revision$ $Date$
*/
public class NormalDistributionImpl extends AbstractContinuousDistribution
public class NormalDistributionImpl extends AbstractContinuousDistribution
implements NormalDistribution, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = 8589540077390120676L;
@ -41,7 +41,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
/** The mean of this distribution. */
private double mean = 0;
/** The standard deviation of this distribution. */
private double standardDeviation = 1;
@ -55,23 +55,23 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
setMean(mean);
setStandardDeviation(sd);
}
/**
* Creates normal distribution with the mean equal to zero and standard
* deviation equal to one.
* deviation equal to one.
*/
public NormalDistributionImpl(){
this(0.0, 1.0);
}
/**
* Access the mean.
* @return mean for this distribution
*/
*/
public double getMean() {
return mean;
}
/**
* Modify the mean.
* @param mean for this distribution
@ -98,7 +98,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
throw MathRuntimeException.createIllegalArgumentException(
"standard deviation must be positive ({0})",
sd);
}
}
standardDeviation = sd;
}
@ -116,7 +116,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
/**
* For this distribution, X, this method returns P(X &lt; <code>x</code>).
* @param x the value at which the CDF is evaluated.
* @return CDF evaluted at <code>x</code>.
* @return CDF evaluted at <code>x</code>.
* @throws MathException if the algorithm fails to converge; unless
* x is more than 20 standard deviations from the mean, in which case the
* convergence exception is caught and 0 or 1 is returned.
@ -135,12 +135,12 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
}
}
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
* <p>
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
*
* @param p the desired probability
@ -151,7 +151,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p == 0) {
return Double.NEGATIVE_INFINITY;
@ -161,15 +161,15 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
}
return super.inverseCumulativeProbability(p);
}
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -180,7 +180,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else {
ret = getMean();
}
return ret;
}
@ -188,10 +188,10 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -202,7 +202,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else {
ret = Double.MAX_VALUE;
}
return ret;
}
@ -210,7 +210,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/
@ -225,7 +225,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else {
ret = getMean();
}
return ret;
}
}

View File

@ -20,7 +20,7 @@ package org.apache.commons.math.distribution;
* The Pascal distribution. The Pascal distribution is a special case of the
* Negative Binomial distribution where the number of successes parameter is an
* integer.
*
*
* There are various ways to express the probability mass and distribution
* functions for the Pascal distribution. The convention employed by the
* library is to express these functions in terms of the number of failures in
@ -41,29 +41,29 @@ package org.apache.commons.math.distribution;
public interface PascalDistribution extends IntegerDistribution {
/**
* Access the number of successes for this distribution.
*
*
* @return the number of successes
*/
int getNumberOfSuccesses();
/**
* Access the probability of success for this distribution.
*
*
* @return the probability of success
*/
double getProbabilityOfSuccess();
/**
* Change the number of successes for this distribution.
*
*
* @param successes the new number of successes
*/
void setNumberOfSuccesses(int successes);
/**
* Change the probability of success for this distribution.
*
*
* @param p the new probability of success
*/
void setProbabilityOfSuccess(double p);
}
}

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.MathException;
/**
* Interface representing the Poisson Distribution.
*
*
* <p>
* References:
* <ul>
@ -28,23 +28,23 @@ import org.apache.commons.math.MathException;
* Poisson distribution</a></li>
* </ul>
* </p>
*
*
* @version $Revision$ $Date$
*/
public interface PoissonDistribution extends IntegerDistribution {
/**
* Get the mean for the distribution.
*
*
* @return the mean for the distribution.
*/
public double getMean();
/**
* Set the mean for the distribution.
* The parameter value must be positive; otherwise an
* The parameter value must be positive; otherwise an
* <code>IllegalArgument</code> is thrown.
*
*
* @param p the mean
* @throws IllegalArgumentException if p &le; 0
*/
@ -52,10 +52,10 @@ public interface PoissonDistribution extends IntegerDistribution {
/**
* Calculates the Poisson distribution function using a normal approximation.
*
*
* @param x the upper bound, inclusive
* @return the distribution function value calculated using a normal approximation
* @throws MathException if an error occurs computing the normal approximation
*/
public double normalApproximateProbability(int x) throws MathException;
}
}

View File

@ -25,7 +25,7 @@ import org.apache.commons.math.util.MathUtils;
/**
* Implementation for the {@link PoissonDistribution}.
*
*
* @version $Revision$ $Date$
*/
public class PoissonDistributionImpl extends AbstractIntegerDistribution
@ -36,7 +36,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/** Distribution used to compute normal approximation. */
private NormalDistribution normal;
/**
* Holds the Poisson mean for the distribution.
*/
@ -44,9 +44,9 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/**
* Create a new Poisson distribution with the given the mean.
* The mean value must be positive; otherwise an
* The mean value must be positive; otherwise an
* <code>IllegalArgument</code> is thrown.
*
*
* @param p the Poisson mean
* @throws IllegalArgumentException if p &le; 0
*/
@ -56,9 +56,9 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/**
* Create a new Poisson distribution with the given the mean.
* The mean value must be positive; otherwise an
* The mean value must be positive; otherwise an
* <code>IllegalArgument</code> is thrown.
*
*
* @param p the Poisson mean
* @param z a normal distribution used to compute normal approximations.
* @throws IllegalArgumentException if p &le; 0
@ -72,7 +72,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/**
* Get the Poisson mean for the distribution.
*
*
* @return the Poisson mean for the distribution.
*/
public double getMean() {
@ -81,9 +81,9 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/**
* Set the Poisson mean for the distribution.
* The mean value must be positive; otherwise an
* The mean value must be positive; otherwise an
* <code>IllegalArgument</code> is thrown.
*
*
* @param p the Poisson mean value
* @throws IllegalArgumentException if p &le; 0
*/
@ -100,7 +100,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
/**
* The probability mass function P(X = x) for a Poisson distribution.
*
*
* @param x the value at which the probability density function is evaluated.
* @return the value of the probability mass function at x
*/
@ -108,13 +108,13 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
if (x < 0 || x == Integer.MAX_VALUE) {
return 0;
}
return Math.pow(getMean(), x) /
return Math.pow(getMean(), x) /
MathUtils.factorialDouble(x) * Math.exp(-mean);
}
/**
* The probability distribution function P(X <= x) for a Poisson distribution.
*
*
* @param x the value at which the PDF is evaluated.
* @return Poisson distribution function evaluated at x
* @throws MathException if the cumulative probability can not be
@ -128,7 +128,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
if (x == Integer.MAX_VALUE) {
return 1;
}
return Gamma.regularizedGammaQ((double)x + 1, mean,
return Gamma.regularizedGammaQ((double)x + 1, mean,
1E-12, Integer.MAX_VALUE);
}
@ -139,7 +139,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
* <p>
* The computation uses "half-correction" -- evaluating the normal
* distribution function at <code>x + 0.5</code></p>
*
*
* @param x the upper bound, inclusive
* @return the distribution function value calculated using a normal approximation
* @throws MathException if an error occurs computing the normal approximation
@ -153,7 +153,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain lower bound
*/
@ -166,7 +166,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain upper bound
*/
@ -174,7 +174,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
protected int getDomainUpperBound(double p) {
return Integer.MAX_VALUE;
}
/**
* Modify the normal distribution used to compute normal approximations.
* The caller is responsible for insuring the normal distribution has the
@ -185,5 +185,5 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
public void setNormal(NormalDistribution value) {
normal = value;
}
}
}

View File

@ -35,7 +35,7 @@ public interface TDistribution extends ContinuousDistribution {
* @param degreesOfFreedom the new degrees of freedom.
*/
void setDegreesOfFreedom(double degreesOfFreedom);
/**
* Access the degrees of freedom.
* @return the degrees of freedom.

View File

@ -34,7 +34,7 @@ public class TDistributionImpl
/** Serializable version identifier */
private static final long serialVersionUID = -5852615386664158222L;
/** The degrees of freedom*/
private double degreesOfFreedom;
@ -71,7 +71,7 @@ public class TDistributionImpl
/**
* For this distribution, X, this method returns P(X &lt; <code>x</code>).
* @param x the value at which the CDF is evaluated.
* @return CDF evaluted at <code>x</code>.
* @return CDF evaluted at <code>x</code>.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
@ -94,12 +94,12 @@ public class TDistributionImpl
return ret;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
* <p>
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
*
* @param p the desired probability
@ -110,7 +110,7 @@ public class TDistributionImpl
* probability.
*/
@Override
public double inverseCumulativeProbability(final double p)
public double inverseCumulativeProbability(final double p)
throws MathException {
if (p == 0) {
return Double.NEGATIVE_INFINITY;
@ -125,10 +125,10 @@ public class TDistributionImpl
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -139,10 +139,10 @@ public class TDistributionImpl
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -153,7 +153,7 @@ public class TDistributionImpl
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/

View File

@ -41,19 +41,19 @@ public interface WeibullDistribution extends ContinuousDistribution {
* @return the shape parameter.
*/
double getShape();
/**
* Access the scale parameter.
* @return the scale parameter.
*/
double getScale();
/**
* Modify the shape parameter.
* @param alpha The new shape parameter value.
*/
void setShape(double alpha);
/**
* Modify the scale parameter.
* @param beta The new scale parameter value.

View File

@ -30,16 +30,16 @@ import org.apache.commons.math.MathRuntimeException;
*/
public class WeibullDistributionImpl extends AbstractContinuousDistribution
implements WeibullDistribution, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = 8589540077390120676L;
/** The shape parameter. */
private double shape;
/** The scale parameter. */
private double scale;
/**
* Creates weibull distribution with the given shape and scale and a
* location equal to zero.
@ -55,7 +55,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
/**
* For this distribution, X, this method returns P(X &lt; <code>x</code>).
* @param x the value at which the CDF is evaluated.
* @return CDF evaluted at <code>x</code>.
* @return CDF evaluted at <code>x</code>.
*/
public double cumulativeProbability(double x) {
double ret;
@ -74,7 +74,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
public double getShape() {
return shape;
}
/**
* Access the scale parameter.
* @return the scale parameter.
@ -82,12 +82,12 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
public double getScale() {
return scale;
}
/**
* For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>.
* <p>
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and
* <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
*
* @param p the desired probability
@ -110,7 +110,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
}
return ret;
}
/**
* Modify the shape parameter.
* @param alpha the new shape parameter value.
@ -120,10 +120,10 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
throw MathRuntimeException.createIllegalArgumentException(
"shape must be positive ({0})",
alpha);
}
}
this.shape = alpha;
}
/**
* Modify the scale parameter.
* @param beta the new scale parameter value.
@ -133,7 +133,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
throw MathRuntimeException.createIllegalArgumentException(
"scale must be positive ({0})",
beta);
}
}
this.scale = beta;
}
@ -141,10 +141,10 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected double getDomainLowerBound(double p) {
@ -155,10 +155,10 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected double getDomainUpperBound(double p) {
@ -169,7 +169,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values.
*
*
* @param p the desired probability for the critical value
* @return initial domain value
*/

View File

@ -22,26 +22,26 @@ package org.apache.commons.math.distribution;
* <p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/ZipfDistribution.html">Zipf
* <li><a href="http://mathworld.wolfram.com/ZipfDistribution.html">Zipf
* Distribution</a></li>
* </ul>
* </p>
*
*
* @version $Revision$ $Date$
*/
public interface ZipfDistribution extends IntegerDistribution {
/**
* Get the number of elements (e.g. corpus size) for the distribution.
*
*
* @return the number of elements
*/
public int getNumberOfElements();
/**
* Set the number of elements (e.g. corpus size) for the distribution.
* The parameter value must be positive; otherwise an
* The parameter value must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown.
*
*
* @param n the number of elements
* @throws IllegalArgumentException if n &le; 0
*/
@ -49,18 +49,18 @@ public interface ZipfDistribution extends IntegerDistribution {
/**
* Get the exponent characterising the distribution.
*
*
* @return the exponent
*/
public double getExponent();
/**
* Set the exponent characterising the distribution.
* The parameter value must be positive; otherwise an
* The parameter value must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown.
*
*
* @param s the exponent
* @throws IllegalArgumentException if s &le; 0.0
*/
public void setExponent(double s);
}
}

View File

@ -23,10 +23,10 @@ import org.apache.commons.math.MathRuntimeException;
/**
* Implementation for the {@link ZipfDistribution}.
*
*
* @version $Revision$ $Date$
*/
public class ZipfDistributionImpl extends AbstractIntegerDistribution
public class ZipfDistributionImpl extends AbstractIntegerDistribution
implements ZipfDistribution, Serializable {
/** Serializable version identifier. */
@ -39,10 +39,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
private double exponent;
/**
* Create a new Zipf distribution with the given number of elements and
* exponent. Both values must be positive; otherwise an
* Create a new Zipf distribution with the given number of elements and
* exponent. Both values must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown.
*
*
* @param numberOfElements the number of elements
* @param exponent the exponent
* @exception IllegalArgumentException if n &le; 0 or s &le; 0.0
@ -55,7 +55,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Get the number of elements (e.g. corpus size) for the distribution.
*
*
* @return the number of elements
*/
public int getNumberOfElements() {
@ -64,9 +64,9 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Set the number of elements (e.g. corpus size) for the distribution.
* The parameter value must be positive; otherwise an
* The parameter value must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown.
*
*
* @param n the number of elements
* @exception IllegalArgumentException if n &le; 0
*/
@ -79,10 +79,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
}
this.numberOfElements = n;
}
/**
* Get the exponent characterising the distribution.
*
*
* @return the exponent
*/
public double getExponent() {
@ -91,9 +91,9 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Set the exponent characterising the distribution.
* The parameter value must be positive; otherwise an
* The parameter value must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown.
*
*
* @param s the exponent
* @exception IllegalArgumentException if s &le; 0.0
*/
@ -109,7 +109,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* The probability mass function P(X = x) for a Zipf distribution.
*
*
* @param x the value at which the probability density function is evaluated.
* @return the value of the probability mass function at x
*/
@ -121,10 +121,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
return (1.0 / Math.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
}
/**
* The probability distribution function P(X <= x) for a Zipf distribution.
*
*
* @param x the value at which the PDF is evaluated.
* @return Zipf distribution function evaluated at x
*/
@ -143,10 +143,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
@Override
protected int getDomainLowerBound(final double p) {
@ -156,10 +156,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root.
*
*
* @param p the desired probability for the critical value
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
@Override
protected int getDomainUpperBound(final double p) {
@ -168,10 +168,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/**
* Calculates the Nth generalized harmonic number. See
* <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic
* Calculates the Nth generalized harmonic number. See
* <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic
* Series</a>.
*
*
* @param n the term in the series to calculate (must be &ge; 1)
* @param m the exponent; special case m == 1.0 is the harmonic series
* @return the nth generalized harmonic number

View File

@ -51,7 +51,7 @@ public abstract class AbstractEstimator implements Estimator {
/**
* Set the maximal number of cost evaluations allowed.
*
*
* @param maxCostEval maximal number of cost evaluations allowed
* @see #estimate
*/
@ -61,23 +61,23 @@ public abstract class AbstractEstimator implements Estimator {
/**
* Get the number of cost evaluations.
*
*
* @return number of cost evaluations
* */
public final int getCostEvaluations() {
return costEvaluations;
}
/**
/**
* Get the number of jacobian evaluations.
*
*
* @return number of jacobian evaluations
* */
public final int getJacobianEvaluations() {
return jacobianEvaluations;
}
/**
/**
* Update the jacobian matrix.
*/
protected void updateJacobian() {
@ -99,7 +99,7 @@ public abstract class AbstractEstimator implements Estimator {
++jacobianEvaluations;
}
/**
/**
* Update the residuals array and cost function value.
* @exception EstimationException if the number of cost evaluations
* exceeds the maximum allowed
@ -123,14 +123,14 @@ public abstract class AbstractEstimator implements Estimator {
}
/**
/**
* Get the Root Mean Square value.
* Get the Root Mean Square value, i.e. the root of the arithmetic
* mean of the square of all weighted residuals. This is related to the
* criterion that is minimized by the estimator as follows: if
* <em>c</em> if the criterion, and <em>n</em> is the number of
* measurements, then the RMS is <em>sqrt (c/n)</em>.
*
*
* @param problem estimation problem
* @return RMS value
*/
@ -168,7 +168,7 @@ public abstract class AbstractEstimator implements Estimator {
*/
public double[][] getCovariances(EstimationProblem problem)
throws EstimationException {
// set up the jacobian
updateJacobian();
@ -253,7 +253,7 @@ public abstract class AbstractEstimator implements Estimator {
}
/**
/**
* Solve an estimation problem.
*
* <p>The method should set the parameters of the problem to several
@ -276,7 +276,7 @@ public abstract class AbstractEstimator implements Estimator {
/** Array of parameters. */
protected EstimatedParameter[] parameters;
/**
/**
* Jacobian matrix.
* <p>This matrix is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver
@ -311,4 +311,4 @@ public abstract class AbstractEstimator implements Estimator {
/** Number of jacobian evaluations. */
private int jacobianEvaluations;
}
}

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.estimation;
import org.apache.commons.math.MathException;
/**
/**
* This class represents exceptions thrown by the estimation solvers.
*
* @version $Revision$ $Date$
@ -35,7 +35,7 @@ extends MathException {
/** Serializable version identifier. */
private static final long serialVersionUID = -573038581493881337L;
/**
/**
* Simple constructor.
* Build an exception by translating and formating a message
* @param specifier format specifier (to be translated)

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.estimation;
/**
/**
* This interface represents an estimation problem.
*
* <p>This interface should be implemented by all real estimation
@ -46,19 +46,19 @@ package org.apache.commons.math.estimation;
*/
@Deprecated
public interface EstimationProblem {
/**
/**
* Get the measurements of an estimation problem.
* @return measurements
*/
public WeightedMeasurement[] getMeasurements();
/**
/**
* Get the unbound parameters of the problem.
* @return unbound parameters
*/
public EstimatedParameter[] getUnboundParameters();
/**
/**
* Get all the parameters of the problem.
* @return parameters
*/

View File

@ -39,7 +39,7 @@ package org.apache.commons.math.estimation;
@Deprecated
public interface Estimator {
/**
/**
* Solve an estimation problem.
*
* <p>The method should set the parameters of the problem to several
@ -56,7 +56,7 @@ public interface Estimator {
public void estimate(EstimationProblem problem)
throws EstimationException;
/**
/**
* Get the Root Mean Square value.
* Get the Root Mean Square value, i.e. the root of the arithmetic
* mean of the square of all weighted residuals. This is related to the
@ -64,7 +64,7 @@ public interface Estimator {
* <em>c</em> is the criterion, and <em>n</em> is the number of
* measurements, then the RMS is <em>sqrt (c/n)</em>.
* @see #guessParametersErrors(EstimationProblem)
*
*
* @param problem estimation problem
* @return RMS value
*/

View File

@ -26,7 +26,7 @@ import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.linear.ArrayRealVector;
/**
/**
* This class implements a solver for estimation problems.
*
* <p>This class solves estimation problems using a weighted least
@ -67,10 +67,10 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa
*/
public GaussNewtonEstimator() {
this.steadyStateThreshold = DEFAULT_STEADY_STATE_THRESHOLD;
this.convergence = DEFAULT_CONVERGENCE;
this.convergence = DEFAULT_CONVERGENCE;
}
/**
/**
* Simple constructor.
*
* <p>This constructor builds an estimator and stores its convergence
@ -132,7 +132,7 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa
this.steadyStateThreshold = steadyStateThreshold;
}
/**
/**
* Solve an estimation problem using a least squares criterion.
*
* <p>This method set the unbound parameters of the given problem

View File

@ -20,7 +20,7 @@ import java.io.Serializable;
import java.util.Arrays;
/**
/**
* This class solves a least squares problem.
*
* <p>This implementation <em>should</em> work even for over-determined systems
@ -101,7 +101,7 @@ import java.util.Arrays;
@Deprecated
public class LevenbergMarquardtEstimator extends AbstractEstimator implements Serializable {
/**
/**
* Build an estimator for least squares problems.
* <p>The default values for the algorithm settings are:
* <ul>
@ -126,12 +126,12 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
}
/**
/**
* Set the positive input variable used in determining the initial step bound.
* This bound is set to the product of initialStepBoundFactor and the euclidean norm of diag*x if nonzero,
* or else to initialStepBoundFactor itself. In most cases factor should lie
* in the interval (0.1, 100.0). 100.0 is a generally recommended value
*
*
* @param initialStepBoundFactor initial step bound factor
* @see #estimate
*/
@ -139,9 +139,9 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
this.initialStepBoundFactor = initialStepBoundFactor;
}
/**
/**
* Set the desired relative error in the sum of squares.
*
*
* @param costRelativeTolerance desired relative error in the sum of squares
* @see #estimate
*/
@ -149,9 +149,9 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
this.costRelativeTolerance = costRelativeTolerance;
}
/**
/**
* Set the desired relative error in the approximate solution parameters.
*
*
* @param parRelativeTolerance desired relative error
* in the approximate solution parameters
* @see #estimate
@ -160,9 +160,9 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
this.parRelativeTolerance = parRelativeTolerance;
}
/**
/**
* Set the desired max cosine on the orthogonality.
*
*
* @param orthoTolerance desired max cosine on the orthogonality
* between the function vector and the columns of the jacobian
* @see #estimate
@ -171,7 +171,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
this.orthoTolerance = orthoTolerance;
}
/**
/**
* Solve an estimation problem using the Levenberg-Marquardt algorithm.
* <p>The algorithm used is a modified Levenberg-Marquardt one, based
* on the MINPACK <a href="http://www.netlib.org/minpack/lmder.f">lmder</a>
@ -189,7 +189,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
* <li>Jorge J. More</li>
* </ul>
* <p>Luc Maisonobe did the Java translation.</p>
*
*
* @param problem estimation problem to solve
* @exception EstimationException if convergence cannot be
* reached with the specified algorithm settings or if there are more variables
@ -224,7 +224,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
// evaluate the function at the starting point and calculate its norm
updateResidualsAndCost();
// outer loop
lmPar = 0;
boolean firstIteration = true;
@ -259,10 +259,10 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
diag[k] = dk;
}
xNorm = Math.sqrt(xNorm);
// initialize the step bound delta
delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm);
}
// check orthogonality between function vector and jacobian columns
@ -301,7 +301,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
double[] tmpVec = residuals;
residuals = oldRes;
oldRes = tmpVec;
// determine the Levenberg-Marquardt parameter
determineLMParameter(oldRes, delta, diag, work1, work2, work3);
@ -389,7 +389,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
residuals = oldRes;
oldRes = tmpVec;
}
// tests for convergence.
if (((Math.abs(actRed) <= costRelativeTolerance) &&
(preRed <= costRelativeTolerance) &&
@ -422,7 +422,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
}
/**
/**
* Determine the Levenberg-Marquardt parameter.
* <p>This implementation is a translation in Java of the MINPACK
* <a href="http://www.netlib.org/minpack/lmpar.f">lmpar</a>
@ -436,7 +436,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
* <li>Jorge J. More</li>
* </ul>
* <p>Luc Maisonobe did the Java translation.</p>
*
*
* @param qy array containing qTy
* @param delta upper bound on the euclidean norm of diagR * lmDir
* @param diag diagonal matrix
@ -487,7 +487,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
if (rank == solvedCols) {
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
work1[pj] *= diag[pj] / dxNorm;
work1[pj] *= diag[pj] / dxNorm;
}
sum2 = 0;
for (int j = 0; j < solvedCols; ++j) {
@ -558,11 +558,11 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
((parl == 0) && (fp <= previousFP) && (previousFP < 0))) {
return;
}
// compute the Newton correction
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
work1[pj] = work3[pj] * diag[pj] / dxNorm;
work1[pj] = work3[pj] * diag[pj] / dxNorm;
}
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
@ -592,7 +592,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
}
}
/**
/**
* Solve a*x = b and d*x = 0 in the least squares sense.
* <p>This implementation is a translation in Java of the MINPACK
* <a href="http://www.netlib.org/minpack/qrsolv.f">qrsolv</a>
@ -606,7 +606,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
* <li>Jorge J. More</li>
* </ul>
* <p>Luc Maisonobe did the Java translation.</p>
*
*
* @param qy array containing qTy
* @param diag diagonal matrix
* @param lmDiag diagonal elements associated with lmDir
@ -716,7 +716,7 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
}
/**
/**
* Decompose a matrix A as A.P = Q.R using Householder transforms.
* <p>As suggested in the P. Lascaux and R. Theodor book
* <i>Analyse num&eacute;rique matricielle appliqu&eacute;e &agrave;
@ -812,9 +812,9 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
}
/**
/**
* Compute the product Qt.y for some Q.R. decomposition.
*
*
* @param y vector to multiply (will be overwritten with the result)
*/
private void qTy(double[] y) {

View File

@ -52,7 +52,7 @@ public class SimpleEstimationProblem implements EstimationProblem {
measurements = new ArrayList<WeightedMeasurement>();
}
/**
/**
* Get all the parameters of the problem.
* @return parameters
*/
@ -60,7 +60,7 @@ public class SimpleEstimationProblem implements EstimationProblem {
return parameters.toArray(new EstimatedParameter[parameters.size()]);
}
/**
/**
* Get the unbound parameters of the problem.
* @return unbound parameters
*/
@ -76,10 +76,10 @@ public class SimpleEstimationProblem implements EstimationProblem {
// convert to an array
return unbound.toArray(new EstimatedParameter[unbound.size()]);
}
/**
/**
* Get the measurements of an estimation problem.
* @return measurements
*/

Some files were not shown because too many files have changed in this diff Show More