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="ignoreConstructorParameter" value="true" />
<property name="ignoreSetter" value="true" /> <property name="ignoreSetter" value="true" />
</module> </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" /> <module name="DeclarationOrder" />

View File

@ -31,7 +31,7 @@ public class ArgumentOutsideDomainException extends FunctionEvaluationException
/** /**
* Constructs an exception with specified formatted detail message. * Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}. * 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 lower lower bound of the domain
* @param upper upper 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$ * @version $Revision$ $Date$
*/ */
public class ConvergenceException extends MathException { public class ConvergenceException extends MathException {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = 4883703247677159141L; private static final long serialVersionUID = 4883703247677159141L;
@ -33,7 +33,7 @@ public class ConvergenceException extends MathException {
public ConvergenceException() { public ConvergenceException() {
super("Convergence failed"); super("Convergence failed");
} }
/** /**
* Constructs an exception with specified formatted detail message. * Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}. * Message formatting is delegated to {@link java.text.MessageFormat}.

View File

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

View File

@ -18,12 +18,12 @@ package org.apache.commons.math;
/** /**
* Error thrown when two dimensions differ. * Error thrown when two dimensions differ.
* *
* @since 1.2 * @since 1.2
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class DimensionMismatchException extends MathException { public class DimensionMismatchException extends MathException {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -1316089546353786411L; private static final long serialVersionUID = -1316089546353786411L;
@ -45,7 +45,7 @@ public class DimensionMismatchException extends MathException {
public int getDimension1() { public int getDimension1() {
return dimension1; return dimension1;
} }
/** /**
* Get the second dimension * Get the second dimension
* @return second dimension * @return second dimension
@ -56,8 +56,8 @@ public class DimensionMismatchException extends MathException {
/** First dimension. */ /** First dimension. */
private int dimension1; private int dimension1;
/** Second dimension. */ /** Second dimension. */
private int dimension2; 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. * Exeption thrown when a sample contains several entries at the same abscissa.
* *
* @since 1.2 * @since 1.2
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class DuplicateSampleAbscissaException extends MathException { public class DuplicateSampleAbscissaException extends MathException {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -2271007547170169872L; private static final long serialVersionUID = -2271007547170169872L;
@ -45,5 +45,5 @@ public class DuplicateSampleAbscissaException extends MathException {
public double getDuplicateAbscissa() { public double getDuplicateAbscissa() {
return ((Double) getArguments()[0]).doubleValue(); return ((Double) getArguments()[0]).doubleValue();
} }
} }

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ public class MathConfigurationException extends MathException implements Seriali
public MathConfigurationException() { public MathConfigurationException() {
super(); super();
} }
/** /**
* Constructs an exception with specified formatted detail message. * Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}. * 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> * Supports nesting, emulating JDK 1.4 behavior if necessary.</p>
* <p> * <p>
* Adapted from <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/FunctorException.html"/>.</p> * Adapted from <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/FunctorException.html"/>.</p>
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class MathException extends Exception { public class MathException extends Exception {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = -9004610152740737812L; private static final long serialVersionUID = -9004610152740737812L;
@ -63,7 +63,7 @@ public class MathException extends Exception {
// the value of the resource is the translated string // the value of the resource is the translated string
return bundle.getString(s); return bundle.getString(s);
} }
} catch (MissingResourceException mre) { } catch (MissingResourceException mre) {
// do nothing here // do nothing here
} }
@ -82,7 +82,7 @@ public class MathException extends Exception {
* @return a message string * @return a message string
*/ */
private static String buildMessage(Locale locale, String pattern, Object ... arguments) { 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.pattern = null;
this.arguments = new Object[0]; this.arguments = new Object[0];
} }
/** /**
* Constructs a new <code>MathException</code> with specified * Constructs a new <code>MathException</code> with specified
* formatted detail message. * formatted detail message.
@ -120,7 +120,7 @@ public class MathException extends Exception {
this.pattern = getMessage(); this.pattern = getMessage();
this.arguments = new Object[0]; this.arguments = new Object[0];
} }
/** /**
* Constructs a new <code>MathException</code> with specified * Constructs a new <code>MathException</code> with specified
* formatted detail message and nested <code>Throwable</code> root cause. * 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. /** Gets the message in a specified locale.
* *
* @param locale Locale in which the message should be translated * @param locale Locale in which the message should be translated
* *
* @return localized message * @return localized message
* @since 1.2 * @since 1.2
*/ */
@ -179,7 +179,7 @@ public class MathException extends Exception {
public void printStackTrace() { public void printStackTrace() {
printStackTrace(System.err); printStackTrace(System.err);
} }
/** /**
* Prints the stack trace of this exception to the specified stream. * 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. * Base class for commons-math unchecked exceptions.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 2.0 * @since 2.0
*/ */
public class MathRuntimeException extends RuntimeException { public class MathRuntimeException extends RuntimeException {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = -5128983364075381060L; private static final long serialVersionUID = -5128983364075381060L;
@ -64,7 +64,7 @@ public class MathRuntimeException extends RuntimeException {
// the value of the resource is the translated string // the value of the resource is the translated string
return bundle.getString(s); return bundle.getString(s);
} }
} catch (MissingResourceException mre) { } catch (MissingResourceException mre) {
// do nothing here // do nothing here
} }
@ -84,7 +84,7 @@ public class MathRuntimeException extends RuntimeException {
*/ */
private static String buildMessage(final Locale locale, final String pattern, private static String buildMessage(final Locale locale, final String pattern,
final Object ... arguments) { 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.pattern = getMessage();
this.arguments = new Object[0]; this.arguments = new Object[0];
} }
/** /**
* Constructs a new <code>MathRuntimeException</code> with specified * Constructs a new <code>MathRuntimeException</code> with specified
* formatted detail message and nested <code>Throwable</code> root cause. * 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. /** Gets the message in a specified locale.
* *
* @param locale Locale in which the message should be translated * @param locale Locale in which the message should be translated
* *
* @return localized message * @return localized message
*/ */
public String getMessage(final Locale locale) { public String getMessage(final Locale locale) {
@ -168,7 +168,7 @@ public class MathRuntimeException extends RuntimeException {
public void printStackTrace() { public void printStackTrace() {
printStackTrace(System.err); printStackTrace(System.err);
} }
/** /**
* Prints the stack trace of this exception to the specified stream. * 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; import java.util.ListResourceBundle;
/** /**
* French localization message resources for the commons-math library. * French localization message resources for the commons-math library.
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 1.2 * @since 1.2
@ -27,13 +27,13 @@ import java.util.ListResourceBundle;
public class MessagesResources_fr public class MessagesResources_fr
extends ListResourceBundle { extends ListResourceBundle {
/** /**
* Simple constructor. * Simple constructor.
*/ */
public MessagesResources_fr() { public MessagesResources_fr() {
} }
/** /**
* Get the non-translated/translated messages arrays from this resource bundle. * Get the non-translated/translated messages arrays from this resource bundle.
* @return non-translated/translated messages arrays * @return non-translated/translated messages arrays
*/ */
@ -405,7 +405,7 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.SparseRealVector // org.apache.commons.math.linear.SparseRealVector
{ "vector length mismatch: got {0} but expected {1}", { "vector length mismatch: got {0} but expected {1}",
"dimension de vecteur erronn\u00e9e : {0} \u00e0 la place de {1}" }, "dimension de vecteur erronn\u00e9e : {0} \u00e0 la place de {1}" },
// org.apache.commons.math.linear.ArrayRealVector // org.apache.commons.math.linear.ArrayRealVector
// org.apache.commons.math.linear.ArrayFieldVector // org.apache.commons.math.linear.ArrayFieldVector
// org.apache.commons.math.linear.SparseRealVector // 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.AbstractRealMatrix
// org.apache.commons.math.linear.AbstractFieldMatrix // 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}", { "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}" }, "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; package org.apache.commons.math.analysis;
/** /**
* Extension of {@link MultivariateRealFunction} representing a differentiable * Extension of {@link MultivariateRealFunction} representing a differentiable
* multivariate real function. * multivariate real function.
* @version $Revision$ $Date$ * @version $Revision$ $Date$

View File

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

View File

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

View File

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

View File

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

View File

@ -20,14 +20,14 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a multivariate matrix function. * An interface representing a multivariate matrix function.
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 2.0 * @since 2.0
*/ */
public interface MultivariateMatrixFunction { public interface MultivariateMatrixFunction {
/** /**
* Compute the value for the function at the given point. * Compute the value for the function at the given point.
* @param point point at which the function must be evaluated * @param point point at which the function must be evaluated
* @return function value for the given point * @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; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a multivariate real function. * An interface representing a multivariate real function.
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 2.0 * @since 2.0
*/ */
public interface MultivariateRealFunction { public interface MultivariateRealFunction {
/** /**
* Compute the value for the function at the given point. * Compute the value for the function at the given point.
* @param point point at which the function must be evaluated * @param point point at which the function must be evaluated
* @return function value for the given point * @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; import org.apache.commons.math.FunctionEvaluationException;
/** /**
* An interface representing a multivariate vectorial function. * An interface representing a multivariate vectorial function.
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 2.0 * @since 2.0
*/ */
public interface MultivariateVectorialFunction { public interface MultivariateVectorialFunction {
/** /**
* Compute the value for the function at the given point. * Compute the value for the function at the given point.
* @param point point at which the function must be evaluated * @param point point at which the function must be evaluated
* @return function value for the given point * @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. * An interface representing a univariate matrix function.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 2.0 * @since 2.0
*/ */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
/** /**
* Interface for univariate real integration algorithms. * Interface for univariate real integration algorithms.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 1.2 * @since 1.2
*/ */
@ -45,7 +45,7 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
/** /**
* Get the lower limit for the number of iterations. * Get the lower limit for the number of iterations.
* *
* @return the actual lower limit * @return the actual lower limit
*/ */
int getMinimalIterationCount(); int getMinimalIterationCount();
@ -54,14 +54,14 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
* Reset the lower limit for the number of iterations to the default. * Reset the lower limit for the number of iterations to the default.
* <p> * <p>
* The default value is supplied by the implementation.</p> * The default value is supplied by the implementation.</p>
* *
* @see #setMinimalIterationCount(int) * @see #setMinimalIterationCount(int)
*/ */
void resetMinimalIterationCount(); void resetMinimalIterationCount();
/** /**
* Integrate the function in the given interval. * Integrate the function in the given interval.
* *
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper bound for the interval * @param max the upper bound for the interval
* @return the value of integral * @return the value of integral
@ -75,12 +75,12 @@ public interface UnivariateRealIntegrator extends ConvergingAlgorithm {
* since 2.0 * since 2.0
*/ */
@Deprecated @Deprecated
double integrate(double min, double max) throws ConvergenceException, double integrate(double min, double max) throws ConvergenceException,
FunctionEvaluationException, IllegalArgumentException; FunctionEvaluationException, IllegalArgumentException;
/** /**
* Integrate the function in the given interval. * Integrate the function in the given interval.
* *
* @param f the integrand function * @param f the integrand function
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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 * @throws IllegalArgumentException if min > max or the endpoints do not
* satisfy the requirements specified by the integrator * 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; FunctionEvaluationException, IllegalArgumentException;
/** /**
* Get the result of the last run of the integrator. * Get the result of the last run of the integrator.
* *
* @return the last result * @return the last result
* @throws IllegalStateException if there is no result available, either * @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed * 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. * Provide a default implementation for several generic functions.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 1.2 * @since 1.2
*/ */
@ -52,7 +52,7 @@ public abstract class UnivariateRealIntegratorImpl
/** /**
* Construct an integrator with given iteration count and accuracy. * Construct an integrator with given iteration count and accuracy.
* *
* @param f the integrand function * @param f the integrand function
* @param defaultMaximalIterationCount maximum number of iterations * @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the iteration * @throws IllegalArgumentException if f is null or the iteration
@ -75,13 +75,13 @@ public abstract class UnivariateRealIntegratorImpl
setRelativeAccuracy(1.0e-6); setRelativeAccuracy(1.0e-6);
this.defaultMinimalIterationCount = 3; this.defaultMinimalIterationCount = 3;
this.minimalIterationCount = defaultMinimalIterationCount; this.minimalIterationCount = defaultMinimalIterationCount;
verifyIterationCount(); verifyIterationCount();
} }
/** /**
* Construct an integrator with given iteration count and accuracy. * Construct an integrator with given iteration count and accuracy.
* *
* @param defaultMaximalIterationCount maximum number of iterations * @param defaultMaximalIterationCount maximum number of iterations
* @throws IllegalArgumentException if f is null or the iteration * @throws IllegalArgumentException if f is null or the iteration
* limits are not valid * limits are not valid
@ -94,13 +94,13 @@ public abstract class UnivariateRealIntegratorImpl
setRelativeAccuracy(1.0e-6); setRelativeAccuracy(1.0e-6);
this.defaultMinimalIterationCount = 3; this.defaultMinimalIterationCount = 3;
this.minimalIterationCount = defaultMinimalIterationCount; this.minimalIterationCount = defaultMinimalIterationCount;
verifyIterationCount(); verifyIterationCount();
} }
/** /**
* Access the last computed integral. * Access the last computed integral.
* *
* @return the last computed integral * @return the last computed integral
* @throws IllegalStateException if no integral has been computed * @throws IllegalStateException if no integral has been computed
*/ */
@ -114,7 +114,7 @@ public abstract class UnivariateRealIntegratorImpl
/** /**
* Convenience function for implementations. * Convenience function for implementations.
* *
* @param newResult the result to set * @param newResult the result to set
* @param iterationCount the iteration count to set * @param iterationCount the iteration count to set
*/ */
@ -149,7 +149,7 @@ public abstract class UnivariateRealIntegratorImpl
/** /**
* Verifies that the endpoints specify an interval. * Verifies that the endpoints specify an interval.
* *
* @param lower lower endpoint * @param lower lower endpoint
* @param upper upper endpoint * @param upper upper endpoint
* @throws IllegalArgumentException if not interval * @throws IllegalArgumentException if not interval
@ -160,12 +160,12 @@ public abstract class UnivariateRealIntegratorImpl
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"endpoints do not specify an interval: [{0}, {1}]", "endpoints do not specify an interval: [{0}, {1}]",
lower, upper); lower, upper);
} }
} }
/** /**
* Verifies that the upper and lower limits of iterations are valid. * Verifies that the upper and lower limits of iterations are valid.
* *
* @throws IllegalArgumentException if not valid * @throws IllegalArgumentException if not valid
*/ */
protected void verifyIterationCount() throws IllegalArgumentException { protected void verifyIterationCount() throws IllegalArgumentException {
@ -173,6 +173,6 @@ public abstract class UnivariateRealIntegratorImpl
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"invalid iteration limits: min={0}, max={1}", "invalid iteration limits: min={0}, max={1}",
minimalIterationCount, maximalIterationCount); minimalIterationCount, maximalIterationCount);
} }
} }
} }

View File

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

View File

@ -81,7 +81,7 @@ public class DividedDifferenceInterpolator implements UnivariateRealInterpolator
/** /**
* Returns a copy of the divided difference array. * Returns a copy of the divided difference array.
* <p> * <p>
* The divided difference array is defined recursively by <pre> * The divided difference array is defined recursively by <pre>
* f[x0] = f(x0) * f[x0] = f(x0)
* f[x0,x1,...,xk] = (f(x1,...,xk) - f(x0,...,x[k-1])) / (xk - 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. // Recompute the robustness weights.
// Find the median residual. // 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 // because the preceding loop is a lot more expensive
System.arraycopy(residuals, 0, sortedResiduals, 0, n); System.arraycopy(residuals, 0, sortedResiduals, 0, n);
Arrays.sort(sortedResiduals); 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> * <a href="http://en.wikipedia.org/wiki/Local_regression#Weight_function">tricube</a>
* weight function * 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. * Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set.
* <p> * <p>
* The {@link #interpolate(double[], double[])} method returns a {@link PolynomialSplineFunction} * 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> * x[0] < x[i] ... < x[n]. The x values are referred to as "knot points."</p>
* <p> * <p>
* The value of the PolynomialSplineFunction at a point x that is greater than or equal to the smallest * 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>
* <p> * <p>
* The interpolating polynomials satisfy: <ol> * 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> * 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> * "match up" at the knot points, as do their first and second derivatives).</li>
* </ol></p> * </ol></p>
* <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. * <u>Numerical Analysis</u>, 4th Ed., 1989, PWS-Kent, ISBN 0-53491-585-X, pp 126-131.
* </p> * </p>
* *
@ -48,7 +48,7 @@ import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
* *
*/ */
public class SplineInterpolator implements UnivariateRealInterpolator { public class SplineInterpolator implements UnivariateRealInterpolator {
/** /**
* Computes an interpolating function for the data set. * Computes an interpolating function for the data set.
* @param x the arguments for the interpolation points * @param x the arguments for the interpolation points
@ -60,15 +60,15 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"dimension mismatch {0} != {1}", x.length, y.length); "dimension mismatch {0} != {1}", x.length, y.length);
} }
if (x.length < 3) { if (x.length < 3) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"{0} points are required, got only {1}", 3, x.length); "{0} points are required, got only {1}", 3, x.length);
} }
// Number of intervals. The number of data points is n + 1. // 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++) { for (int i = 0; i < n; i++) {
if (x[i] >= x[i + 1]) { if (x[i] >= x[i + 1]) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
@ -76,13 +76,13 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
i, i+1, x[i], x[i+1]); i, i+1, x[i], x[i+1]);
} }
} }
// Differences between knot points // Differences between knot points
double h[] = new double[n]; double h[] = new double[n];
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
h[i] = x[i + 1] - x[i]; h[i] = x[i + 1] - x[i];
} }
double mu[] = new double[n]; double mu[] = new double[n];
double z[] = new double[n + 1]; double z[] = new double[n + 1];
mu[0] = 0d; 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]) / 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; (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) // cubic spline coefficients -- b is linear, c quadratic, d is cubic (original y's are constants)
double b[] = new double[n]; double b[] = new double[n];
double c[] = new double[n + 1]; double c[] = new double[n + 1];
double d[] = new double[n]; double d[] = new double[n];
z[n] = 0d; z[n] = 0d;
c[n] = 0d; c[n] = 0d;
for (int j = n -1; j >=0; j--) { for (int j = n -1; j >=0; j--) {
c[j] = z[j] - mu[j] * c[j + 1]; 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; 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]); d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
} }
PolynomialFunction polynomials[] = new PolynomialFunction[n]; PolynomialFunction polynomials[] = new PolynomialFunction[n];
double coefficients[] = new double[4]; double coefficients[] = new double[4];
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
@ -118,7 +118,7 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
coefficients[3] = d[i]; coefficients[3] = d[i];
polynomials[i] = new PolynomialFunction(coefficients); polynomials[i] = new PolynomialFunction(coefficients);
} }
return new PolynomialSplineFunction(x, polynomials); 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. * Interface representing a univariate real interpolating function.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public interface UnivariateRealInterpolator { public interface UnivariateRealInterpolator {

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
/** /**
* The coefficients of the polynomial, ordered by degree -- i.e. * 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. * coefficient of x^n where n is the degree of the polynomial.
*/ */
private double coefficients[]; private double coefficients[];
@ -57,7 +57,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* values. The order of interpolating points are not important. * values. The order of interpolating points are not important.
* <p> * <p>
* The constructor makes copy of the input arrays and assigns them.</p> * The constructor makes copy of the input arrays and assigns them.</p>
* *
* @param x interpolating points * @param x interpolating points
* @param y function values at interpolating points * @param y function values at interpolating points
* @throws IllegalArgumentException if input arrays are not valid * @throws IllegalArgumentException if input arrays are not valid
@ -91,7 +91,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
/** /**
* Returns the degree of the polynomial. * Returns the degree of the polynomial.
* *
* @return the degree of the polynomial * @return the degree of the polynomial
*/ */
public int degree() { public int degree() {
@ -102,7 +102,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the interpolating points array. * Returns a copy of the interpolating points array.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of the interpolating points array * @return a fresh copy of the interpolating points array
*/ */
public double[] getInterpolatingPoints() { public double[] getInterpolatingPoints() {
@ -115,7 +115,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the interpolating values array. * Returns a copy of the interpolating values array.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of the interpolating values array * @return a fresh copy of the interpolating values array
*/ */
public double[] getInterpolatingValues() { public double[] getInterpolatingValues() {
@ -128,7 +128,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* Returns a copy of the coefficients array. * Returns a copy of the coefficients array.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of the coefficients array * @return a fresh copy of the coefficients array
*/ */
public double[] getCoefficients() { 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"> * <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
* Neville's Algorithm</a>. It takes O(N^2) time. * Neville's Algorithm</a>. It takes O(N^2) time.
* <p> * <p>
@ -276,7 +276,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction {
* <p> * <p>
* The interpolating points must be distinct. However it is not * The interpolating points must be distinct. However it is not
* verified here, it is checked in evaluate() and computeCoefficients().</p> * verified here, it is checked in evaluate() and computeCoefficients().</p>
* *
* @param x the interpolating points array * @param x the interpolating points array
* @param y the interpolating values array * @param y the interpolating values array
* @throws IllegalArgumentException if not valid * @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. * 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. * coefficient of x^n where n is the degree of the polynomial.
*/ */
private double coefficients[]; private double coefficients[];
@ -60,7 +60,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* completely change, not just a permutation of old a[]. * completely change, not just a permutation of old a[].
* <p> * <p>
* The constructor makes copy of the input arrays and assigns them.</p> * The constructor makes copy of the input arrays and assigns them.</p>
* *
* @param a the coefficients in Newton form formula * @param a the coefficients in Newton form formula
* @param c the centers * @param c the centers
* @throws IllegalArgumentException if input arrays are not valid * @throws IllegalArgumentException if input arrays are not valid
@ -90,7 +90,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
/** /**
* Returns the degree of the polynomial. * Returns the degree of the polynomial.
* *
* @return the degree of the polynomial * @return the degree of the polynomial
*/ */
public int degree() { public int degree() {
@ -101,7 +101,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of coefficients in Newton form formula. * Returns a copy of coefficients in Newton form formula.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of coefficients in Newton form formula * @return a fresh copy of coefficients in Newton form formula
*/ */
public double[] getNewtonCoefficients() { public double[] getNewtonCoefficients() {
@ -114,7 +114,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of the centers array. * Returns a copy of the centers array.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of the centers array * @return a fresh copy of the centers array
*/ */
public double[] getCenters() { public double[] getCenters() {
@ -127,7 +127,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* Returns a copy of the coefficients array. * Returns a copy of the coefficients array.
* <p> * <p>
* Changes made to the returned copy will not affect the polynomial.</p> * Changes made to the returned copy will not affect the polynomial.</p>
* *
* @return a fresh copy of the coefficients array * @return a fresh copy of the coefficients array
*/ */
public double[] getCoefficients() { public double[] getCoefficients() {
@ -193,7 +193,7 @@ public class PolynomialFunctionNewtonForm implements UnivariateRealFunction {
* <p> * <p>
* The centers must be distinct for interpolation purposes, but not * The centers must be distinct for interpolation purposes, but not
* for general use. Thus it is not verified here.</p> * for general use. Thus it is not verified here.</p>
* *
* @param a the coefficients in Newton form formula * @param a the coefficients in Newton form formula
* @param c the centers * @param c the centers
* @throws IllegalArgumentException if not valid * @throws IllegalArgumentException if not valid

View File

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

View File

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

View File

@ -73,7 +73,7 @@ public class LaguerreSolver extends UnivariateRealSolverImpl {
/** /**
* Returns a copy of the polynomial function. * Returns a copy of the polynomial function.
* *
* @return a fresh 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. * @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. * Find a real root in the given interval with initial value.
* <p> * <p>
* Requires bracketing condition.</p> * Requires bracketing condition.</p>
* *
* @param f function to solve (must be polynomial) * @param f function to solve (must be polynomial)
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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 * @throws ConvergenceException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public double solve(final UnivariateRealFunction f, 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 * Returns true iff the given complex root is actually a real zero
* in the given interval, within the solver tolerance level. * in the given interval, within the solver tolerance level.
* *
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper bound for the interval * @param max the upper bound for the interval
* @param z the complex root * @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, * Find all complex roots for the polynomial with the given coefficients,
* starting from the given initial value. * starting from the given initial value.
* *
* @param coefficients the polynomial coefficients array * @param coefficients the polynomial coefficients array
* @param initial the start value to use * @param initial the start value to use
* @return the point at which the function value is zero * @return the point at which the function value is zero
* @throws ConvergenceException if the maximum iteration count is exceeded * @throws ConvergenceException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public Complex[] solveAll(double coefficients[], double initial) throws 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, * Find all complex roots for the polynomial with the given coefficients,
* starting from the given initial value. * starting from the given initial value.
* *
* @param coefficients the polynomial coefficients array * @param coefficients the polynomial coefficients array
* @param initial the start value to use * @param initial the start value to use
* @return the point at which the function value is zero * @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public Complex[] solveAll(Complex coefficients[], Complex initial) throws 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, * Find a complex root for the polynomial with the given coefficients,
* starting from the given initial value. * starting from the given initial value.
* *
* @param coefficients the polynomial coefficients array * @param coefficients the polynomial coefficients array
* @param initial the start value to use * @param initial the start value to use
* @return the point at which the function value is zero * @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public Complex solve(Complex coefficients[], Complex initial) throws 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. * Construct a solver for the given function.
* *
* @param f function to solve * @param f function to solve
* @deprecated as of 2.0 the function to solve is passed as an argument * @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or * 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. * Find a real root in the given interval with initial value.
* <p> * <p>
* Requires bracketing condition.</p> * Requires bracketing condition.</p>
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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> * bisection as a safety backup if it performs very poorly.</p>
* <p> * <p>
* The formulas here use divided differences directly.</p> * The formulas here use divided differences directly.</p>
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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 * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public double solve(final UnivariateRealFunction f, public double solve(final UnivariateRealFunction f,
@ -228,14 +228,14 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* approximation is often negligible.</p> * approximation is often negligible.</p>
* <p> * <p>
* The formulas here do not use divided differences directly.</p> * The formulas here do not use divided differences directly.</p>
* *
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper bound for the interval * @param max the upper bound for the interval
* @return the point at which the function value is zero * @return the point at which the function value is zero
* @throws MaxIterationsExceededException if the maximum iteration count is exceeded * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
* @deprecated replaced by {@link #solve2(UnivariateRealFunction, double, double)} * @deprecated replaced by {@link #solve2(UnivariateRealFunction, double, double)}
* since 2.0 * since 2.0
@ -261,7 +261,7 @@ public class MullerSolver extends UnivariateRealSolverImpl {
* approximation is often negligible.</p> * approximation is often negligible.</p>
* <p> * <p>
* The formulas here do not use divided differences directly.</p> * The formulas here do not use divided differences directly.</p>
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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 * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the solver detects convergence problems otherwise * or the solver detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public double solve2(final UnivariateRealFunction f, 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"> * Implements <a href="http://mathworld.wolfram.com/NewtonsMethod.html">
* Newton's Method</a> for finding zeros of real univariate functions. * Newton's Method</a> for finding zeros of real univariate functions.
* <p> * <p>
* The function should be continuous but not necessarily smooth.</p> * The function should be continuous but not necessarily smooth.</p>
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class NewtonSolver extends UnivariateRealSolverImpl { public class NewtonSolver extends UnivariateRealSolverImpl {
/** /**
* Construct a solver for the given function. * Construct a solver for the given function.
* @param f function to solve. * @param f function to solve.
@ -56,7 +56,7 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Deprecated @Deprecated
public double solve(final double min, final double max) public double solve(final double min, final double max)
throws MaxIterationsExceededException, throws MaxIterationsExceededException,
FunctionEvaluationException { FunctionEvaluationException {
return solve(f, min, max); 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>. * Find a zero near the midpoint of <code>min</code> and <code>max</code>.
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper bound for the interval * @param max the upper bound for the interval
* @return the value where the function is zero * @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 * @throws FunctionEvaluationException if an error occurs evaluating the
* function or derivative * function or derivative
* @throws IllegalArgumentException if min is not less than max * @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>. * Find a zero near the value <code>startValue</code>.
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval (ignored). * @param min the lower bound for the interval (ignored).
* @param max the upper bound for the interval (ignored). * @param max the upper bound for the interval (ignored).
* @param startValue the start value to use. * @param startValue the start value to use.
* @return the value where the function is zero * @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 * @throws FunctionEvaluationException if an error occurs evaluating the
* function or derivative * function or derivative
* @throws IllegalArgumentException if startValue is not between min and max or * @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"); 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. * Systems, 26 (1979), 979 - 980.
* <p> * <p>
* The function should be continuous but not necessarily smooth.</p> * The function should be continuous but not necessarily smooth.</p>
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 1.2 * @since 1.2
*/ */
@ -38,7 +38,7 @@ public class RiddersSolver extends UnivariateRealSolverImpl {
/** /**
* Construct a solver for the given function. * Construct a solver for the given function.
* *
* @param f function to solve * @param f function to solve
* @deprecated as of 2.0 the function to solve is passed as an argument * @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or * 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. * Find a root in the given interval with initial value.
* <p> * <p>
* Requires bracketing condition.</p> * Requires bracketing condition.</p>
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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. * Find a root in the given interval.
* <p> * <p>
* Requires bracketing condition.</p> * Requires bracketing condition.</p>
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper bound for the interval * @param max the upper bound for the interval
* @return the point at which the function value is zero * @return the point at which the function value 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 * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if any parameters are invalid * @throws IllegalArgumentException if any parameters are invalid
*/ */
public double solve(final UnivariateRealFunction f, 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> * <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> * <p>
* The algorithm is modified to maintain bracketing of a root by successive * The algorithm is modified to maintain bracketing of a root by successive
* approximations. Because of forced bracketing, convergence may be slower than * approximations. Because of forced bracketing, convergence may be slower than
* the unrestricted secant algorithm. However, this implementation should in * the unrestricted secant algorithm. However, this implementation should in
* general outperform the * general outperform the
* <a href="http://mathworld.wolfram.com/MethodofFalsePosition.html"> * <a href="http://mathworld.wolfram.com/MethodofFalsePosition.html">
* regula falsi method.</a></p> * regula falsi method.</a></p>
* <p> * <p>
* The function is assumed to be continuous but not necessarily smooth.</p> * The function is assumed to be continuous but not necessarily smooth.</p>
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class SecantSolver extends UnivariateRealSolverImpl { public class SecantSolver extends UnivariateRealSolverImpl {
/** /**
* Construct a solver for the given function. * Construct a solver for the given function.
* @param f function to solve. * @param f function to solve.
@ -77,7 +77,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
/** /**
* Find a zero in the given interval. * Find a zero in the given interval.
* *
* @param f the function to solve * @param f the function to solve
* @param min the lower bound for the interval * @param min the lower bound for the interval
* @param max the upper 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 * @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 * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if min is not less than max or the * @throws IllegalArgumentException if min is not less than max or the
* signs of the values of the function at the endpoints are not opposites * 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 { throws MaxIterationsExceededException, FunctionEvaluationException {
return solve(f, min, max); return solve(f, min, max);
} }
/** /**
* Find a zero in the given interval. * Find a zero in the given interval.
* @param f the function to solve * @param f the function to solve
@ -103,17 +103,17 @@ public class SecantSolver extends UnivariateRealSolverImpl {
* @return the value where the function is zero * @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 * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if min is not less than max or the * @throws IllegalArgumentException if min is not less than max or the
* signs of the values of the function at the endpoints are not opposites * signs of the values of the function at the endpoints are not opposites
*/ */
public double solve(final UnivariateRealFunction f, public double solve(final UnivariateRealFunction f,
final double min, final double max) final double min, final double max)
throws MaxIterationsExceededException, FunctionEvaluationException { throws MaxIterationsExceededException, FunctionEvaluationException {
clearResult(); clearResult();
verifyInterval(min, max); verifyInterval(min, max);
// Index 0 is the old approximation for the root. // Index 0 is the old approximation for the root.
// Index 1 is the last calculated 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. // 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 x1 = max;
double y0 = f.value(x0); double y0 = f.value(x0);
double y1 = f.value(x1); double y1 = f.value(x1);
// Verify bracketing // Verify bracketing
if (y0 * y1 >= 0) { if (y0 * y1 >= 0) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs, " + "function values at endpoints do not have different signs, " +
"endpoints: [{0}, {1}], values: [{2}, {3}]", "endpoints: [{0}, {1}], values: [{2}, {3}]",
min, max, y0, y1); min, max, y0, y1);
} }
double x2 = x0; double x2 = x0;
double y2 = y0; double y2 = y0;
double oldDelta = x2 - x1; double oldDelta = x2 - x1;
@ -171,7 +171,7 @@ public class SecantSolver extends UnivariateRealSolverImpl {
x1 = x1 + delta; x1 = x1 + delta;
y1 = f.value(x1); y1 = f.value(x1);
if ((y1 > 0) == (y2 > 0)) { if ((y1 > 0) == (y2 > 0)) {
// New bracket is (x0,x1). // New bracket is (x0,x1).
x2 = x0; x2 = x0;
y2 = y0; y2 = y0;
} }

View File

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

View File

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

View File

@ -25,7 +25,7 @@ package org.apache.commons.math.analysis.solvers;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory { public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory {
/** /**
* Default constructor. * Default constructor.
*/ */
@ -37,7 +37,7 @@ public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory
public UnivariateRealSolver newDefaultSolver() { public UnivariateRealSolver newDefaultSolver() {
return newBrentSolver(); return newBrentSolver();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public UnivariateRealSolver newBisectionSolver() { public UnivariateRealSolver newBisectionSolver() {
@ -49,13 +49,13 @@ public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory
public UnivariateRealSolver newBrentSolver() { public UnivariateRealSolver newBrentSolver() {
return new BrentSolver(); return new BrentSolver();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public UnivariateRealSolver newNewtonSolver() { public UnivariateRealSolver newNewtonSolver() {
return new NewtonSolver(); return new NewtonSolver();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public UnivariateRealSolver newSecantSolver() { 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 * Provide a default implementation for several functions useful to generic
* solvers. * solvers.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public abstract class UnivariateRealSolverImpl public abstract class UnivariateRealSolverImpl
@ -56,11 +56,11 @@ public abstract class UnivariateRealSolverImpl
/** /**
* Construct a solver with given iteration count and accuracy. * Construct a solver with given iteration count and accuracy.
* *
* @param f the function to solve. * @param f the function to solve.
* @param defaultAbsoluteAccuracy maximum absolute error * @param defaultAbsoluteAccuracy maximum absolute error
* @param defaultMaximalIterationCount maximum number of iterations * @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 * defaultAbsoluteAccuracy is not valid
* @deprecated as of 2.0 the function to solve is passed as an argument * @deprecated as of 2.0 the function to solve is passed as an argument
* to the {@link #solve(UnivariateRealFunction, double, double)} or * 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. * Construct a solver with given iteration count and accuracy.
* *
* @param defaultAbsoluteAccuracy maximum absolute error * @param defaultAbsoluteAccuracy maximum absolute error
* @param defaultMaximalIterationCount maximum number of iterations * @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 * defaultAbsoluteAccuracy is not valid
*/ */
protected UnivariateRealSolverImpl(final int defaultMaximalIterationCount, protected UnivariateRealSolverImpl(final int defaultMaximalIterationCount,
@ -133,7 +133,7 @@ public abstract class UnivariateRealSolverImpl
/** /**
* Convenience function for implementations. * Convenience function for implementations.
* *
* @param newResult the result to set * @param newResult the result to set
* @param iterationCount the iteration count to set * @param iterationCount the iteration count to set
*/ */
@ -145,7 +145,7 @@ public abstract class UnivariateRealSolverImpl
/** /**
* Convenience function for implementations. * Convenience function for implementations.
* *
* @param x the result to set * @param x the result to set
* @param fx the result to set * @param fx the result to set
* @param iterationCount the iteration count 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. * 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 upper the upper endpoint
* @param function the function * @param function the function
* @return true if f(lower) * f(upper) < 0 * @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 * 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) final UnivariateRealFunction function)
throws FunctionEvaluationException { throws FunctionEvaluationException {
final double f1 = function.value(lower); final double f1 = function.value(lower);
final double f2 = function.value(upper); final double f2 = function.value(upper);
return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0)); return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0));
} }
/** /**
* Returns true if the arguments form a (strictly) increasing sequence * Returns true if the arguments form a (strictly) increasing sequence
* *
* @param start first number * @param start first number
* @param mid second number * @param mid second number
* @param end third 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) { protected boolean isSequence(final double start, final double mid, final double end) {
return (start < mid) && (mid < end); return (start < mid) && (mid < end);
} }
/** /**
* Verifies that the endpoints specify an interval, * Verifies that the endpoints specify an interval,
* throws IllegalArgumentException if not * throws IllegalArgumentException if not
* *
* @param lower lower endpoint * @param lower lower endpoint
* @param upper upper endpoint * @param upper upper endpoint
* @throws IllegalArgumentException * @throws IllegalArgumentException
@ -209,13 +209,13 @@ public abstract class UnivariateRealSolverImpl
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"endpoints do not specify an interval: [{0}, {1}]", "endpoints do not specify an interval: [{0}, {1}]",
lower, upper); lower, upper);
} }
} }
/** /**
* Verifies that <code>lower < initial < upper</code> * Verifies that <code>lower < initial < upper</code>
* throws IllegalArgumentException if not * throws IllegalArgumentException if not
* *
* @param lower lower endpoint * @param lower lower endpoint
* @param initial initial value * @param initial initial value
* @param upper upper endpoint * @param upper upper endpoint
@ -226,30 +226,30 @@ public abstract class UnivariateRealSolverImpl
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}", "invalid interval, initial value parameters: lower={0}, initial={1}, upper={2}",
lower, initial, upper); lower, initial, upper);
} }
} }
/** /**
* Verifies that the endpoints specify an interval and the function takes * Verifies that the endpoints specify an interval and the function takes
* opposite signs at the enpoints, throws IllegalArgumentException if not * opposite signs at the enpoints, throws IllegalArgumentException if not
* *
* @param lower lower endpoint * @param lower lower endpoint
* @param upper upper endpoint * @param upper upper endpoint
* @param function function * @param function function
* @throws IllegalArgumentException * @throws IllegalArgumentException
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints * 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) final UnivariateRealFunction function)
throws FunctionEvaluationException { throws FunctionEvaluationException {
verifyInterval(lower, upper); verifyInterval(lower, upper);
if (!isBracketing(lower, upper, function)) { if (!isBracketing(lower, upper, function)) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs. " + "function values at endpoints do not have different signs. " +
"Endpoints: [{0}, {1}], Values: [{2}, {3}]", "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. * Utility routines for {@link UnivariateRealSolver} objects.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class UnivariateRealSolverUtils { public class UnivariateRealSolverUtils {
@ -33,11 +33,11 @@ public class UnivariateRealSolverUtils {
private UnivariateRealSolverUtils() { private UnivariateRealSolverUtils() {
super(); super();
} }
/** /**
* Convenience method to find a zero of a univariate real function. A default * Convenience method to find a zero of a univariate real function. A default
* solver is used. * solver is used.
* *
* @param f the function. * @param f the function.
* @param x0 the lower bound for the interval. * @param x0 the lower bound for the interval.
* @param x1 the upper 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 * Convenience method to find a zero of a univariate real function. A default
* solver is used. * solver is used.
* *
* @param f the function * @param f the function
* @param x0 the lower bound for the interval * @param x0 the lower bound for the interval
* @param x1 the upper 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 ConvergenceException if the iteration count is exceeded
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * 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 * specify a valid interval, or the absoluteAccuracy is not valid for the
* default solver * default solver
*/ */
public static double solve(UnivariateRealFunction f, double x0, double x1, public static double solve(UnivariateRealFunction f, double x0, double x1,
double absoluteAccuracy) throws ConvergenceException, double absoluteAccuracy) throws ConvergenceException,
FunctionEvaluationException { FunctionEvaluationException {
setup(f); setup(f);
UnivariateRealSolver solver = LazyHolder.FACTORY.newDefaultSolver(); UnivariateRealSolver solver = LazyHolder.FACTORY.newDefaultSolver();
solver.setAbsoluteAccuracy(absoluteAccuracy); 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> * If f is continuous on <code>[a,b],</code> this means that <code>a</code>
* and <code>b</code> bracket a root of f. * and <code>b</code> bracket a root of f.
* <p> * <p>
* The algorithm starts by setting * The algorithm starts by setting
* <code>a := initial -1; b := initial +1,</code> examines the value of the * <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 * 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> * when one of the following happens: <ul>
* <li> <code> f(a) * f(b) < 0 </code> -- success!</li> * <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> * -- ConvergenceException </li>
* <li> <code> Integer.MAX_VALUE</code> iterations elapse * <li> <code> Integer.MAX_VALUE</code> iterations elapse
* -- ConvergenceException </li> * -- ConvergenceException </li>
* </ul></p> * </ul></p>
* <p> * <p>
* <strong>Note: </strong> this method can take * <strong>Note: </strong> this method can take
* <code>Integer.MAX_VALUE</code> iterations to throw a * <code>Integer.MAX_VALUE</code> iterations to throw a
* <code>ConvergenceException.</code> Unless you are confident that there * <code>ConvergenceException.</code> Unless you are confident that there
* is a root between <code>lowerBound</code> and <code>upperBound</code> * is a root between <code>lowerBound</code> and <code>upperBound</code>
* near <code>initial,</code> it is better to use * near <code>initial,</code> it is better to use
* {@link #bracket(UnivariateRealFunction, double, double, double, int)}, * {@link #bracket(UnivariateRealFunction, double, double, double, int)},
* explicitly specifying the maximum number of iterations.</p> * explicitly specifying the maximum number of iterations.</p>
* *
* @param function the function * @param function the function
@ -121,8 +121,8 @@ public class UnivariateRealSolverUtils {
* @throws IllegalArgumentException if function is null, maximumIterations * @throws IllegalArgumentException if function is null, maximumIterations
* is not positive, or initial is not between lowerBound and upperBound * is not positive, or initial is not between lowerBound and upperBound
*/ */
public static double[] bracket(UnivariateRealFunction function, public static double[] bracket(UnivariateRealFunction function,
double initial, double lowerBound, double upperBound) double initial, double lowerBound, double upperBound)
throws ConvergenceException, FunctionEvaluationException { throws ConvergenceException, FunctionEvaluationException {
return bracket( function, initial, lowerBound, upperBound, return bracket( function, initial, lowerBound, upperBound,
Integer.MAX_VALUE ) ; 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> * If f is continuous on <code>[a,b],</code> this means that <code>a</code>
* and <code>b</code> bracket a root of f. * and <code>b</code> bracket a root of f.
* <p> * <p>
* The algorithm starts by setting * The algorithm starts by setting
* <code>a := initial -1; b := initial +1,</code> examines the value of the * <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 * 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> * when one of the following happens: <ul>
* <li> <code> f(a) * f(b) <= 0 </code> -- success!</li> * <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> * -- ConvergenceException </li>
* <li> <code> maximumIterations</code> iterations elapse * <li> <code> maximumIterations</code> iterations elapse
* -- ConvergenceException </li></ul></p> * -- ConvergenceException </li></ul></p>
* *
* @param function the function * @param function the function
* @param initial initial midpoint of interval being expanded to * @param initial initial midpoint of interval being expanded to
* bracket a root * bracket a root
@ -157,16 +157,16 @@ public class UnivariateRealSolverUtils {
* @return a two element array holding {a, b}. * @return a two element array holding {a, b}.
* @throws ConvergenceException if the algorithm fails to find a and b * @throws ConvergenceException if the algorithm fails to find a and b
* satisfying the desired conditions * satisfying the desired conditions
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function * function
* @throws IllegalArgumentException if function is null, maximumIterations * @throws IllegalArgumentException if function is null, maximumIterations
* is not positive, or initial is not between lowerBound and upperBound * is not positive, or initial is not between lowerBound and upperBound
*/ */
public static double[] bracket(UnivariateRealFunction function, public static double[] bracket(UnivariateRealFunction function,
double initial, double lowerBound, double upperBound, double initial, double lowerBound, double upperBound,
int maximumIterations) throws ConvergenceException, int maximumIterations) throws ConvergenceException,
FunctionEvaluationException { FunctionEvaluationException {
if (function == null) { if (function == null) {
throw MathRuntimeException.createIllegalArgumentException("function is null"); throw MathRuntimeException.createIllegalArgumentException("function is null");
} }
@ -184,17 +184,17 @@ public class UnivariateRealSolverUtils {
double fa; double fa;
double fb; double fb;
int numIterations = 0 ; int numIterations = 0 ;
do { do {
a = Math.max(a - 1.0, lowerBound); a = Math.max(a - 1.0, lowerBound);
b = Math.min(b + 1.0, upperBound); b = Math.min(b + 1.0, upperBound);
fa = function.value(a); fa = function.value(a);
fb = function.value(b); fb = function.value(b);
numIterations++ ; numIterations++ ;
} while ((fa * fb > 0.0) && (numIterations < maximumIterations) && } while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
((a > lowerBound) || (b < upperBound))); ((a > lowerBound) || (b < upperBound)));
if (fa * fb > 0.0 ) { if (fa * fb > 0.0 ) {
throw new ConvergenceException( throw new ConvergenceException(
"number of iterations={0}, maximum iterations={1}, " + "number of iterations={0}, maximum iterations={1}, " +
@ -203,21 +203,21 @@ public class UnivariateRealSolverUtils {
numIterations, maximumIterations, initial, numIterations, maximumIterations, initial,
lowerBound, upperBound, a, b, fa, fb); lowerBound, upperBound, a, b, fa, fb);
} }
return new double[]{a, b}; return new double[]{a, b};
} }
/** /**
* Compute the midpoint of two values. * Compute the midpoint of two values.
* *
* @param a first value. * @param a first value.
* @param b second value. * @param b second value.
* @return the midpoint. * @return the midpoint.
*/ */
public static double midpoint(double a, double b) { public static double midpoint(double a, double b) {
return (a + b) * .5; return (a + b) * .5;
} }
/** /**
* Checks to see if f is null, throwing IllegalArgumentException if so. * Checks to see if f is null, throwing IllegalArgumentException if so.
* @param f input function * @param f input function

View File

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

View File

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

View File

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

View File

@ -20,39 +20,39 @@ package org.apache.commons.math.complex;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathRuntimeException;
/** /**
* Static implementations of common * Static implementations of common
* {@link org.apache.commons.math.complex.Complex} utilities functions. * {@link org.apache.commons.math.complex.Complex} utilities functions.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class ComplexUtils { public class ComplexUtils {
/** /**
* Default constructor. * Default constructor.
*/ */
private ComplexUtils() { private ComplexUtils() {
super(); super();
} }
/** /**
* Creates a complex number from the given polar representation. * Creates a complex number from the given polar representation.
* <p> * <p>
* The value returned is <code>r&middot;e<sup>i&middot;theta</sup></code>, * 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> * computed as <code>r&middot;cos(theta) + r&middot;sin(theta)i</code></p>
* <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> * <code>theta</code> is infinite, {@link Complex#NaN} is returned.</p>
* <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 * infinite or NaN values may be returned in parts of the result, following
* the rules for double arithmetic.<pre> * the rules for double arithmetic.<pre>
* Examples: * Examples:
* <code> * <code>
* polar2Complex(INFINITY, &pi;/4) = INFINITY + INFINITY i * polar2Complex(INFINITY, &pi;/4) = INFINITY + INFINITY i
* polar2Complex(INFINITY, 0) = INFINITY + NaN i * polar2Complex(INFINITY, 0) = INFINITY + NaN i
* polar2Complex(INFINITY, -&pi;/4) = INFINITY - INFINITY i * polar2Complex(INFINITY, -&pi;/4) = INFINITY - INFINITY i
* polar2Complex(INFINITY, 5&pi;/4) = -INFINITY - INFINITY i </code></pre></p> * polar2Complex(INFINITY, 5&pi;/4) = -INFINITY - INFINITY i </code></pre></p>
* *
* @param r the modulus of the complex number to create * @param r the modulus of the complex number to create
* @param theta the argument 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> * @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)); 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 Complex number type and implementations of complex transcendental
functions. functions.
</body> </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 * Base class for continuous distributions. Default implementations are
* provided for some of the methods that do not vary from distribution to * provided for some of the methods that do not vary from distribution to
* distribution. * distribution.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public abstract class AbstractContinuousDistribution public abstract class AbstractContinuousDistribution
@ -38,7 +38,7 @@ public abstract class AbstractContinuousDistribution
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -38038050983108802L; private static final long serialVersionUID = -38038050983108802L;
/** /**
* Default constructor. * 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 lowerBound = getDomainLowerBound(p);
double upperBound = getDomainUpperBound(p); double upperBound = getDomainUpperBound(p);
double[] bracket = null; double[] bracket = null;
@ -86,20 +86,20 @@ public abstract class AbstractContinuousDistribution
rootFindingFunction, getInitialDomain(p), rootFindingFunction, getInitialDomain(p),
lowerBound, upperBound); lowerBound, upperBound);
} catch (ConvergenceException ex) { } catch (ConvergenceException ex) {
/* /*
* Check domain endpoints to see if one gives value that is within * Check domain endpoints to see if one gives value that is within
* the default solver's defaultAbsoluteAccuracy of 0 (will be the * the default solver's defaultAbsoluteAccuracy of 0 (will be the
* case if density has bounded support and p is 0 or 1). * case if density has bounded support and p is 0 or 1).
* *
* TODO: expose the default solver, defaultAbsoluteAccuracy as * TODO: expose the default solver, defaultAbsoluteAccuracy as
* a constant. * a constant.
*/ */
if (Math.abs(rootFindingFunction.value(lowerBound)) < 1E-6) { if (Math.abs(rootFindingFunction.value(lowerBound)) < 1E-6) {
return lowerBound; return lowerBound;
} }
if (Math.abs(rootFindingFunction.value(upperBound)) < 1E-6) { if (Math.abs(rootFindingFunction.value(upperBound)) < 1E-6) {
return upperBound; return upperBound;
} }
// Failed bracket convergence was not because of corner solution // Failed bracket convergence was not because of corner solution
throw new MathException(ex); throw new MathException(ex);
} }
@ -114,7 +114,7 @@ public abstract class AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to * Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return initial domain 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 * Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value lower bound, i.e. * @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); 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 * Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value upper bound, i.e. * @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); protected abstract double getDomainUpperBound(double p);
} }

View File

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

View File

@ -35,22 +35,22 @@ public interface BinomialDistribution extends IntegerDistribution {
* @return the number of trials. * @return the number of trials.
*/ */
int getNumberOfTrials(); int getNumberOfTrials();
/** /**
* Access the probability of success for this distribution. * Access the probability of success for this distribution.
* @return the probability of success. * @return the probability of success.
*/ */
double getProbabilityOfSuccess(); double getProbabilityOfSuccess();
/** /**
* Change the number of trials for this distribution. * Change the number of trials for this distribution.
* @param trials the new number of trials. * @param trials the new number of trials.
*/ */
void setNumberOfTrials(int trials); void setNumberOfTrials(int trials);
/** /**
* Change the probability of success for this distribution. * Change the probability of success for this distribution.
* @param p the new probability of success. * @param p the new probability of success.
*/ */
void setProbabilityOfSuccess(double p); 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 * Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value lower bound, i.e. * @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 @Override
protected int getDomainLowerBound(double p) { 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 * Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value upper bound, i.e. * @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 @Override
protected int getDomainUpperBound(double p) { protected int getDomainUpperBound(double p) {
@ -126,7 +126,7 @@ public class BinomialDistributionImpl
/** /**
* For this distribution, X, this method returns P(X &le; x). * For this distribution, X, this method returns P(X &le; x).
* @param x the value at which the PDF is evaluated. * @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 * @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors. * 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). * For this distribution, X, this method returns P(X = x).
* *
* @param x the value at which the PMF is evaluated. * @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) { public double probability(int x) {
double ret; double ret;
@ -166,7 +166,7 @@ public class BinomialDistributionImpl
} }
return ret; return ret;
} }
/** /**
* For this distribution, X, this method returns the largest x, such * For this distribution, X, this method returns the largest x, such
* that P(X &le; x) &le; <code>p</code>. * that P(X &le; x) &le; <code>p</code>.
@ -185,11 +185,11 @@ public class BinomialDistributionImpl
// handle extreme values explicitly // handle extreme values explicitly
if (p == 0) { if (p == 0) {
return -1; return -1;
}
if (p == 1) {
return Integer.MAX_VALUE;
} }
if (p == 1) {
return Integer.MAX_VALUE;
}
// use default bisection impl // use default bisection impl
return super.inverseCumulativeProbability(p); return super.inverseCumulativeProbability(p);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -24,11 +24,11 @@ import org.apache.commons.math.MathException;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public interface ContinuousDistribution extends Distribution { public interface ContinuousDistribution extends Distribution {
/** /**
* For this distribution, X, this method returns x such that P(X &lt; x) = p. * For this distribution, X, this method returns x such that P(X &lt; x) = p.
* @param p the cumulative probability. * @param p the cumulative probability.
* @return x. * @return x.
* @throws MathException if the inverse cumulative probability can not be * @throws MathException if the inverse cumulative probability can not be
* computed due to convergence or other numerical errors. * 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 * For a random variable X whose values are distributed according
* to this distribution, this method returns P(X = x). In other words, this * to this distribution, this method returns P(X = x). In other words, this
* method represents the probability mass function, or PMF for the distribution. * method represents the probability mass function, or PMF for the distribution.
* *
* @param x the value at which the probability mass function is evaluated. * @param x the value at which the probability mass function is evaluated.
* @return the value of the probability mass function at x * @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, * to this distribution, this method returns P(X &le; x). In other words,
* this method represents the (cumulative) distribution function, or * this method represents the (cumulative) distribution function, or
* CDF, for this distribution. * CDF, for this distribution.
* *
* @param x the value at which the distribution function is evaluated. * @param x the value at which the distribution function is evaluated.
* @return the probability that a random variable with this * @return the probability that a random variable with this
* distribution takes a value less than or equal to <code>x</code> * 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. * computed due to convergence or other numerical errors.
*/ */
double cumulativeProbability(double x) throws MathException; double cumulativeProbability(double x) throws MathException;
/** /**
* For a random variable X whose values are distributed according * For a random variable X whose values are distributed according
* to this distribution, this method returns P(x0 &le; X &le; x1). * to this distribution, this method returns P(x0 &le; X &le; x1).
* *
* @param x0 the (inclusive) lower bound * @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound * @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution * @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 * including the endpoints
* @throws MathException if the cumulative probability can not be * @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors. * 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. * @param mean the new mean.
*/ */
void setMean(double mean); void setMean(double mean);
/** /**
* Access the mean. * Access the mean.
* @return the mean. * @return the mean.
@ -48,4 +48,4 @@ public interface ExponentialDistribution extends ContinuousDistribution, HasDens
* @return The pdf at point x. * @return The pdf at point x.
*/ */
double density(Double x); double density(Double x);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ import org.apache.commons.math.util.MathUtils;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class HypergeometricDistributionImpl extends AbstractIntegerDistribution public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
implements HypergeometricDistribution, Serializable implements HypergeometricDistribution, Serializable
{ {
/** Serializable version identifier */ /** Serializable version identifier */
@ -36,13 +36,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
/** The number of successes in the population. */ /** The number of successes in the population. */
private int numberOfSuccesses; private int numberOfSuccesses;
/** The population size. */ /** The population size. */
private int populationSize; private int populationSize;
/** The sample size. */ /** The sample size. */
private int sampleSize; private int sampleSize;
/** /**
* Construct a new hypergeometric distribution with the given the population * Construct a new hypergeometric distribution with the given the population
* size, the number of successes in the population, and the sample size. * 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). * For this distribution, X, this method returns P(X &le; x).
* @param x the value at which the PDF is evaluated. * @param x the value at which the PDF is evaluated.
* @return PDF for this distribution. * @return PDF for this distribution.
*/ */
@Override @Override
public double cumulativeProbability(int x) { public double cumulativeProbability(int x) {
double ret; double ret;
int n = getPopulationSize(); int n = getPopulationSize();
int m = getNumberOfSuccesses(); int m = getNumberOfSuccesses();
int k = getSampleSize(); int k = getSampleSize();
@ -89,7 +89,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else { } else {
ret = innerCumulativeProbability(domain[0], x, 1, n, m, k); ret = innerCumulativeProbability(domain[0], x, 1, n, m, k);
} }
return ret; return ret;
} }
@ -99,7 +99,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* @param m number of successes in the population. * @param m number of successes in the population.
* @param k the sample size. * @param k the sample size.
* @return a two element array containing the lower and upper bounds of the * @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){ private int[] getDomain(int n, int m, int k){
return new int[]{ return new int[]{
@ -107,28 +107,28 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
getUpperDomain(m, k) getUpperDomain(m, k)
}; };
} }
/** /**
* Access the domain value lower bound, based on <code>p</code>, used to * Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value lower bound, i.e. * @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 @Override
protected int getDomainLowerBound(double p) { protected int getDomainLowerBound(double p) {
return getLowerDomain(getPopulationSize(), getNumberOfSuccesses(), return getLowerDomain(getPopulationSize(), getNumberOfSuccesses(),
getSampleSize()); getSampleSize());
} }
/** /**
* Access the domain value upper bound, based on <code>p</code>, used to * Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value upper bound, i.e. * @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 @Override
protected int getDomainUpperBound(double p) { protected int getDomainUpperBound(double p) {
@ -141,7 +141,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* @param n the population size. * @param n the population size.
* @param m number of successes in the population. * @param m number of successes in the population.
* @param k the sample size. * @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) { private int getLowerDomain(int n, int m, int k) {
return Math.max(0, m - (n - k)); return Math.max(0, m - (n - k));
@ -176,7 +176,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
* parameters. * parameters.
* @param m number of successes in the population. * @param m number of successes in the population.
* @param k the sample size. * @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){ private int getUpperDomain(int m, int k){
return Math.min(k, m); return Math.min(k, m);
@ -184,13 +184,13 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
/** /**
* For this distribution, X, this method returns P(X = x). * For this distribution, X, this method returns P(X = x).
* *
* @param x the value at which the PMF is evaluated. * @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) { public double probability(int x) {
double ret; double ret;
int n = getPopulationSize(); int n = getPopulationSize();
int m = getNumberOfSuccesses(); int m = getNumberOfSuccesses();
int k = getSampleSize(); int k = getSampleSize();
@ -201,19 +201,19 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else { } else {
ret = probability(n, m, k, x); ret = probability(n, m, k, x);
} }
return ret; return ret;
} }
/** /**
* For the distribution, X, defined by the given hypergeometric distribution * For the distribution, X, defined by the given hypergeometric distribution
* parameters, this method returns P(X = x). * parameters, this method returns P(X = x).
* *
* @param n the population size. * @param n the population size.
* @param m number of successes in the population. * @param m number of successes in the population.
* @param k the sample size. * @param k the sample size.
* @param x the value at which the PMF is evaluated. * @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) { private double probability(int n, int m, int k, int x) {
return Math.exp(MathUtils.binomialCoefficientLog(m, x) + return Math.exp(MathUtils.binomialCoefficientLog(m, x) +
@ -248,7 +248,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} }
populationSize = size; populationSize = size;
} }
/** /**
* Modify the sample size. * Modify the sample size.
* @param size the new sample size. * @param size the new sample size.
@ -259,7 +259,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"sample size must be positive ({0})", "sample size must be positive ({0})",
size); size);
} }
sampleSize = size; sampleSize = size;
} }
@ -271,7 +271,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
*/ */
public double upperCumulativeProbability(int x) { public double upperCumulativeProbability(int x) {
double ret; double ret;
int n = getPopulationSize(); int n = getPopulationSize();
int m = getNumberOfSuccesses(); int m = getNumberOfSuccesses();
int k = getSampleSize(); int k = getSampleSize();
@ -284,14 +284,14 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
} else { } else {
ret = innerCumulativeProbability(domain[1], x, -1, n, m, k); ret = innerCumulativeProbability(domain[1], x, -1, n, m, k);
} }
return ret; return ret;
} }
/** /**
* For this distribution, X, this method returns P(x0 &le; X &le; x1). This * 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 * 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 x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound * @param x1 the inclusive, upper bound
* @param dx the direction of summation. 1 indicates summing from x0 to x1. * @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 n the population size.
* @param m number of successes in the population. * @param m number of successes in the population.
* @param k the sample size. * @param k the sample size.
* @return P(x0 &le; X &le; x1). * @return P(x0 &le; X &le; x1).
*/ */
private double innerCumulativeProbability( private double innerCumulativeProbability(
int x0, int x1, int dx, int n, int m, int k) 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 * For a random variable X whose values are distributed according
* to this distribution, this method returns P(X = x). In other words, this * to this distribution, this method returns P(X = x). In other words, this
* method represents the probability mass function for the distribution. * method represents the probability mass function for the distribution.
* *
* @param x the value at which the probability density function is evaluated. * @param x the value at which the probability density function is evaluated.
* @return the value of the probability density function at x * @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, * to this distribution, this method returns P(X &le; x). In other words,
* this method represents the probability distribution function, or PDF * this method represents the probability distribution function, or PDF
* for the distribution. * for the distribution.
* *
* @param x the value at which the PDF is evaluated. * @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 * @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors. * computed due to convergence or other numerical errors.
*/ */
double cumulativeProbability(int x) throws MathException; double cumulativeProbability(int x) throws MathException;
/** /**
* For this distribution, X, this method returns P(x0 &le; X &le; x1). * For this distribution, X, this method returns P(x0 &le; X &le; x1).
* @param x0 the inclusive, lower bound * @param x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound * @param x1 the inclusive, upper bound
* @return the cumulative probability. * @return the cumulative probability.
* @throws MathException if the cumulative probability can not be * @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors. * computed due to convergence or other numerical errors.
* @throws IllegalArgumentException if x0 > x1 * @throws IllegalArgumentException if x0 > x1
*/ */
double cumulativeProbability(int x0, int x1) throws MathException; double cumulativeProbability(int x0, int x1) throws MathException;
/** /**
* For this distribution, X, this method returns the largest x such that * For this distribution, X, this method returns the largest x such that
* P(X &le; x) <= p. * 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 * <li> If there is a minimum value, <code>m</code>, with postive
* probablility under (the density of) X, then <code>m - 1</code> is * probablility under (the density of) X, then <code>m - 1</code> is
* returned by <code>inverseCumulativeProbability(0).</code> If there 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> * returned.</li>
* <li> If there is a maximum value, <code>M</code>, such that * <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> * <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> * returned.</li></ul></p>
* *
* @param p the cumulative probability. * @param p the cumulative probability.
* @return the largest x such that P(X &le; x) <= p * @return the largest x such that P(X &le; x) <= p
* @throws MathException if the inverse cumulative probability can not be * @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$ * @version $Revision$ $Date$
*/ */
public class NormalDistributionImpl extends AbstractContinuousDistribution public class NormalDistributionImpl extends AbstractContinuousDistribution
implements NormalDistribution, Serializable { implements NormalDistribution, Serializable {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = 8589540077390120676L; private static final long serialVersionUID = 8589540077390120676L;
@ -41,7 +41,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
/** The mean of this distribution. */ /** The mean of this distribution. */
private double mean = 0; private double mean = 0;
/** The standard deviation of this distribution. */ /** The standard deviation of this distribution. */
private double standardDeviation = 1; private double standardDeviation = 1;
@ -55,23 +55,23 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
setMean(mean); setMean(mean);
setStandardDeviation(sd); setStandardDeviation(sd);
} }
/** /**
* Creates normal distribution with the mean equal to zero and standard * Creates normal distribution with the mean equal to zero and standard
* deviation equal to one. * deviation equal to one.
*/ */
public NormalDistributionImpl(){ public NormalDistributionImpl(){
this(0.0, 1.0); this(0.0, 1.0);
} }
/** /**
* Access the mean. * Access the mean.
* @return mean for this distribution * @return mean for this distribution
*/ */
public double getMean() { public double getMean() {
return mean; return mean;
} }
/** /**
* Modify the mean. * Modify the mean.
* @param mean for this distribution * @param mean for this distribution
@ -98,7 +98,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"standard deviation must be positive ({0})", "standard deviation must be positive ({0})",
sd); sd);
} }
standardDeviation = 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>). * For this distribution, X, this method returns P(X &lt; <code>x</code>).
* @param x the value at which the CDF is evaluated. * @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 * @throws MathException if the algorithm fails to converge; unless
* x is more than 20 standard deviations from the mean, in which case the * x is more than 20 standard deviations from the mean, in which case the
* convergence exception is caught and 0 or 1 is returned. * 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 * For this distribution, X, this method returns the critical point x, such
* that P(X &lt; x) = <code>p</code>. * that P(X &lt; x) = <code>p</code>.
* <p> * <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> * <code>Double.POSITIVE_INFINITY</code> for p=1.</p>
* *
* @param p the desired probability * @param p the desired probability
@ -151,7 +151,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* probability. * probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) public double inverseCumulativeProbability(final double p)
throws MathException { throws MathException {
if (p == 0) { if (p == 0) {
return Double.NEGATIVE_INFINITY; return Double.NEGATIVE_INFINITY;
@ -161,15 +161,15 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} }
return super.inverseCumulativeProbability(p); return super.inverseCumulativeProbability(p);
} }
/** /**
* Access the domain value lower bound, based on <code>p</code>, used to * Access the domain value lower bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value lower bound, i.e. * @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 @Override
protected double getDomainLowerBound(double p) { protected double getDomainLowerBound(double p) {
@ -180,7 +180,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else { } else {
ret = getMean(); ret = getMean();
} }
return ret; return ret;
} }
@ -188,10 +188,10 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* Access the domain value upper bound, based on <code>p</code>, used to * Access the domain value upper bound, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value upper bound, i.e. * @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 @Override
protected double getDomainUpperBound(double p) { protected double getDomainUpperBound(double p) {
@ -202,7 +202,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else { } else {
ret = Double.MAX_VALUE; ret = Double.MAX_VALUE;
} }
return ret; return ret;
} }
@ -210,7 +210,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* Access the initial domain value, based on <code>p</code>, used to * Access the initial domain value, based on <code>p</code>, used to
* bracket a CDF root. This method is used by * bracket a CDF root. This method is used by
* {@link #inverseCumulativeProbability(double)} to find critical values. * {@link #inverseCumulativeProbability(double)} to find critical values.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return initial domain value * @return initial domain value
*/ */
@ -225,7 +225,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} else { } else {
ret = getMean(); ret = getMean();
} }
return ret; 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 * The Pascal distribution. The Pascal distribution is a special case of the
* Negative Binomial distribution where the number of successes parameter is an * Negative Binomial distribution where the number of successes parameter is an
* integer. * integer.
* *
* There are various ways to express the probability mass and distribution * There are various ways to express the probability mass and distribution
* functions for the Pascal distribution. The convention employed by the * functions for the Pascal distribution. The convention employed by the
* library is to express these functions in terms of the number of failures in * 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 { public interface PascalDistribution extends IntegerDistribution {
/** /**
* Access the number of successes for this distribution. * Access the number of successes for this distribution.
* *
* @return the number of successes * @return the number of successes
*/ */
int getNumberOfSuccesses(); int getNumberOfSuccesses();
/** /**
* Access the probability of success for this distribution. * Access the probability of success for this distribution.
* *
* @return the probability of success * @return the probability of success
*/ */
double getProbabilityOfSuccess(); double getProbabilityOfSuccess();
/** /**
* Change the number of successes for this distribution. * Change the number of successes for this distribution.
* *
* @param successes the new number of successes * @param successes the new number of successes
*/ */
void setNumberOfSuccesses(int successes); void setNumberOfSuccesses(int successes);
/** /**
* Change the probability of success for this distribution. * Change the probability of success for this distribution.
* *
* @param p the new probability of success * @param p the new probability of success
*/ */
void setProbabilityOfSuccess(double p); void setProbabilityOfSuccess(double p);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,10 +23,10 @@ import org.apache.commons.math.MathRuntimeException;
/** /**
* Implementation for the {@link ZipfDistribution}. * Implementation for the {@link ZipfDistribution}.
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class ZipfDistributionImpl extends AbstractIntegerDistribution public class ZipfDistributionImpl extends AbstractIntegerDistribution
implements ZipfDistribution, Serializable { implements ZipfDistribution, Serializable {
/** Serializable version identifier. */ /** Serializable version identifier. */
@ -39,10 +39,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
private double exponent; private double exponent;
/** /**
* Create a new Zipf distribution with the given number of elements and * Create a new Zipf distribution with the given number of elements and
* exponent. Both values must be positive; otherwise an * exponent. Both values must be positive; otherwise an
* <code>IllegalArgumentException</code> is thrown. * <code>IllegalArgumentException</code> is thrown.
* *
* @param numberOfElements the number of elements * @param numberOfElements the number of elements
* @param exponent the exponent * @param exponent the exponent
* @exception IllegalArgumentException if n &le; 0 or s &le; 0.0 * @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. * Get the number of elements (e.g. corpus size) for the distribution.
* *
* @return the number of elements * @return the number of elements
*/ */
public int getNumberOfElements() { public int getNumberOfElements() {
@ -64,9 +64,9 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/** /**
* Set the number of elements (e.g. corpus size) for the distribution. * 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. * <code>IllegalArgumentException</code> is thrown.
* *
* @param n the number of elements * @param n the number of elements
* @exception IllegalArgumentException if n &le; 0 * @exception IllegalArgumentException if n &le; 0
*/ */
@ -79,10 +79,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
} }
this.numberOfElements = n; this.numberOfElements = n;
} }
/** /**
* Get the exponent characterising the distribution. * Get the exponent characterising the distribution.
* *
* @return the exponent * @return the exponent
*/ */
public double getExponent() { public double getExponent() {
@ -91,9 +91,9 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/** /**
* Set the exponent characterising the distribution. * 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. * <code>IllegalArgumentException</code> is thrown.
* *
* @param s the exponent * @param s the exponent
* @exception IllegalArgumentException if s &le; 0.0 * @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. * The probability mass function P(X = x) for a Zipf distribution.
* *
* @param x the value at which the probability density function is evaluated. * @param x the value at which the probability density function is evaluated.
* @return the value of the probability mass function at x * @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); return (1.0 / Math.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
} }
/** /**
* The probability distribution function P(X <= x) for a Zipf distribution. * The probability distribution function P(X <= x) for a Zipf distribution.
* *
* @param x the value at which the PDF is evaluated. * @param x the value at which the PDF is evaluated.
* @return Zipf distribution function evaluated at x * @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 * Access the domain value lower bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value lower bound, i.e. * @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 @Override
protected int getDomainLowerBound(final double p) { 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 * Access the domain value upper bound, based on <code>p</code>, used to
* bracket a PDF root. * bracket a PDF root.
* *
* @param p the desired probability for the critical value * @param p the desired probability for the critical value
* @return domain value upper bound, i.e. * @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 @Override
protected int getDomainUpperBound(final double p) { protected int getDomainUpperBound(final double p) {
@ -168,10 +168,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
/** /**
* Calculates the Nth generalized harmonic number. See * Calculates the Nth generalized harmonic number. See
* <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic * <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic
* Series</a>. * Series</a>.
* *
* @param n the term in the series to calculate (must be &ge; 1) * @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 * @param m the exponent; special case m == 1.0 is the harmonic series
* @return the nth generalized harmonic number * @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. * Set the maximal number of cost evaluations allowed.
* *
* @param maxCostEval maximal number of cost evaluations allowed * @param maxCostEval maximal number of cost evaluations allowed
* @see #estimate * @see #estimate
*/ */
@ -61,23 +61,23 @@ public abstract class AbstractEstimator implements Estimator {
/** /**
* Get the number of cost evaluations. * Get the number of cost evaluations.
* *
* @return number of cost evaluations * @return number of cost evaluations
* */ * */
public final int getCostEvaluations() { public final int getCostEvaluations() {
return costEvaluations; return costEvaluations;
} }
/** /**
* Get the number of jacobian evaluations. * Get the number of jacobian evaluations.
* *
* @return number of jacobian evaluations * @return number of jacobian evaluations
* */ * */
public final int getJacobianEvaluations() { public final int getJacobianEvaluations() {
return jacobianEvaluations; return jacobianEvaluations;
} }
/** /**
* Update the jacobian matrix. * Update the jacobian matrix.
*/ */
protected void updateJacobian() { protected void updateJacobian() {
@ -99,7 +99,7 @@ public abstract class AbstractEstimator implements Estimator {
++jacobianEvaluations; ++jacobianEvaluations;
} }
/** /**
* Update the residuals array and cost function value. * Update the residuals array and cost function value.
* @exception EstimationException if the number of cost evaluations * @exception EstimationException if the number of cost evaluations
* exceeds the maximum allowed * 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.
* Get the Root Mean Square value, i.e. the root of the arithmetic * 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 * mean of the square of all weighted residuals. This is related to the
* criterion that is minimized by the estimator as follows: if * criterion that is minimized by the estimator as follows: if
* <em>c</em> if the criterion, and <em>n</em> is the number of * <em>c</em> if the criterion, and <em>n</em> is the number of
* measurements, then the RMS is <em>sqrt (c/n)</em>. * measurements, then the RMS is <em>sqrt (c/n)</em>.
* *
* @param problem estimation problem * @param problem estimation problem
* @return RMS value * @return RMS value
*/ */
@ -168,7 +168,7 @@ public abstract class AbstractEstimator implements Estimator {
*/ */
public double[][] getCovariances(EstimationProblem problem) public double[][] getCovariances(EstimationProblem problem)
throws EstimationException { throws EstimationException {
// set up the jacobian // set up the jacobian
updateJacobian(); updateJacobian();
@ -253,7 +253,7 @@ public abstract class AbstractEstimator implements Estimator {
} }
/** /**
* Solve an estimation problem. * Solve an estimation problem.
* *
* <p>The method should set the parameters of the problem to several * <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. */ /** Array of parameters. */
protected EstimatedParameter[] parameters; protected EstimatedParameter[] parameters;
/** /**
* Jacobian matrix. * Jacobian matrix.
* <p>This matrix is in canonical form just after the calls to * <p>This matrix is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver * {@link #updateJacobian()}, but may be modified by the solver
@ -311,4 +311,4 @@ public abstract class AbstractEstimator implements Estimator {
/** Number of jacobian evaluations. */ /** Number of jacobian evaluations. */
private int jacobianEvaluations; private int jacobianEvaluations;
} }

View File

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

View File

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

View File

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

View File

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

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