use standard declaration order rules

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@811827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-09-06 15:32:50 +00:00
parent 54c0e73219
commit f8254ebbd3
69 changed files with 1343 additions and 1352 deletions

View File

@ -116,8 +116,10 @@
<module name="RedundantModifier" /> <module name="RedundantModifier" />
<module name="ModifierOrder" /> <module name="ModifierOrder" />
<!-- <!-- Use a consistent way to put declarations -->
<module name="DeclarationOrder" /> <module name="DeclarationOrder" />
<!--
<module name="IllegalCatch" /> <module name="IllegalCatch" />
<module name="StringLiteralEquality" /> <module name="StringLiteralEquality" />
<module name="MultipleStringLiterals" /> <module name="MultipleStringLiterals" />
@ -144,6 +146,11 @@
<property name="onCommentFormat" value="CHECKSTYLE\: resume ConstantName"/> <property name="onCommentFormat" value="CHECKSTYLE\: resume ConstantName"/>
<property name="checkFormat" value="ConstantName"/> <property name="checkFormat" value="ConstantName"/>
</module> </module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE\: stop HideUtilityClassConstructor"/>
<property name="onCommentFormat" value="CHECKSTYLE\: resume HideUtilityClassConstructor"/>
<property name="checkFormat" value="HideUtilityClassConstructor"/>
</module>
</module> </module>

View File

@ -27,12 +27,18 @@ public class DimensionMismatchException extends MathException {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -1316089546353786411L; private static final long serialVersionUID = -1316089546353786411L;
/** First dimension. */
private final int dimension1;
/** Second dimension. */
private final int dimension2;
/** /**
* Construct an exception from the mismatched dimensions * Construct an exception from the mismatched dimensions
* @param dimension1 first dimension * @param dimension1 first dimension
* @param dimension2 second dimension * @param dimension2 second dimension
*/ */
public DimensionMismatchException(int dimension1, int dimension2) { public DimensionMismatchException(final int dimension1, final int dimension2) {
super("dimension mismatch {0} != {1}", dimension1, dimension2); super("dimension mismatch {0} != {1}", dimension1, dimension2);
this.dimension1 = dimension1; this.dimension1 = dimension1;
this.dimension2 = dimension2; this.dimension2 = dimension2;
@ -54,10 +60,4 @@ public class DimensionMismatchException extends MathException {
return dimension2; return dimension2;
} }
/** First dimension. */
private int dimension1;
/** Second dimension. */
private int dimension2;
} }

View File

@ -48,43 +48,6 @@ public class MathException extends Exception {
*/ */
private final Object[] arguments; private final Object[] arguments;
/**
* Translate a string to a given locale.
* @param s string to translate
* @param locale locale into which to translate the string
* @return translated string or original string
* for unsupported locales or unknown strings
*/
private static String translate(String s, Locale locale) {
try {
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
// the locale is not supported or the resource is unknown
// don't translate and fall back to using the string as is
return s;
}
/**
* Builds a message string by from a pattern and its arguments.
* @param locale Locale in which the message should be translated
* @param pattern format specifier
* @param arguments format arguments
* @return a message string
*/
private static String buildMessage(Locale locale, String pattern, Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/** /**
* Constructs a new <code>MathException</code> with no * Constructs a new <code>MathException</code> with no
* detail message. * detail message.
@ -137,6 +100,43 @@ public class MathException extends Exception {
this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
} }
/**
* Translate a string to a given locale.
* @param s string to translate
* @param locale locale into which to translate the string
* @return translated string or original string
* for unsupported locales or unknown strings
*/
private static String translate(String s, Locale locale) {
try {
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
// the locale is not supported or the resource is unknown
// don't translate and fall back to using the string as is
return s;
}
/**
* Builds a message string by from a pattern and its arguments.
* @param locale Locale in which the message should be translated
* @param pattern format specifier
* @param arguments format arguments
* @return a message string
*/
private static String buildMessage(Locale locale, String pattern, Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/** Gets the pattern used to build the message of this throwable. /** Gets the pattern used to build the message of this throwable.
* *
* @return the pattern used to build the message of this throwable * @return the pattern used to build the message of this throwable

View File

@ -49,44 +49,6 @@ public class MathRuntimeException extends RuntimeException {
*/ */
private final Object[] arguments; private final Object[] arguments;
/**
* Translate a string to a given locale.
* @param s string to translate
* @param locale locale into which to translate the string
* @return translated string or original string
* for unsupported locales or unknown strings
*/
private static String translate(final String s, final Locale locale) {
try {
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
// the locale is not supported or the resource is unknown
// don't translate and fall back to using the string as is
return s;
}
/**
* Builds a message string by from a pattern and its arguments.
* @param locale Locale in which the message should be translated
* @param pattern format specifier
* @param arguments format arguments
* @return a message string
*/
private static String buildMessage(final Locale locale, final String pattern,
final Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/** /**
* Constructs a new <code>MathRuntimeException</code> with specified * Constructs a new <code>MathRuntimeException</code> with specified
* formatted detail message. * formatted detail message.
@ -129,6 +91,44 @@ public class MathRuntimeException extends RuntimeException {
this.arguments = (arguments == null) ? new Object[0] : arguments.clone(); this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
} }
/**
* Translate a string to a given locale.
* @param s string to translate
* @param locale locale into which to translate the string
* @return translated string or original string
* for unsupported locales or unknown strings
*/
private static String translate(final String s, final Locale locale) {
try {
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return bundle.getString(s);
}
} catch (MissingResourceException mre) {
// do nothing here
}
// the locale is not supported or the resource is unknown
// don't translate and fall back to using the string as is
return s;
}
/**
* Builds a message string by from a pattern and its arguments.
* @param locale Locale in which the message should be translated
* @param pattern format specifier
* @param arguments format arguments
* @return a message string
*/
private static String buildMessage(final Locale locale, final String pattern,
final Object ... arguments) {
return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}
/** Gets the pattern used to build the message of this throwable. /** Gets the pattern used to build the message of this throwable.
* *
* @return the pattern used to build the message of this throwable * @return the pattern used to build the message of this throwable

View File

@ -27,21 +27,6 @@ import java.util.ListResourceBundle;
public class MessagesResources_fr public class MessagesResources_fr
extends ListResourceBundle { extends ListResourceBundle {
/**
* Simple constructor.
*/
public MessagesResources_fr() {
}
/**
* Get the non-translated/translated messages arrays from this resource bundle.
* @return non-translated/translated messages arrays
*/
@Override
public Object[][] getContents() {
return CONTENTS.clone();
}
/** Non-translated/translated messages arrays. */ /** Non-translated/translated messages arrays. */
private static final Object[][] CONTENTS = { private static final Object[][] CONTENTS = {
@ -854,4 +839,19 @@ public class MessagesResources_fr
}; };
/**
* Simple constructor.
*/
public MessagesResources_fr() {
}
/**
* Get the non-translated/translated messages arrays from this resource bundle.
* @return non-translated/translated messages arrays
*/
@Override
public Object[][] getContents() {
return CONTENTS.clone();
}
} }

View File

@ -41,18 +41,15 @@ import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
public class LoessInterpolator public class LoessInterpolator
implements UnivariateRealInterpolator, Serializable { implements UnivariateRealInterpolator, Serializable {
/** Default value of the bandwidth parameter. */
public static final double DEFAULT_BANDWIDTH = 0.3;
/** Default value of the number of robustness iterations. */
public static final int DEFAULT_ROBUSTNESS_ITERS = 2;
/** serializable version identifier. */ /** serializable version identifier. */
private static final long serialVersionUID = 5204927143605193821L; private static final long serialVersionUID = 5204927143605193821L;
/**
* Default value of the bandwidth parameter.
*/
public static final double DEFAULT_BANDWIDTH = 0.3;
/**
* Default value of the number of robustness iterations.
*/
public static final int DEFAULT_ROBUSTNESS_ITERS = 2;
/** /**
* The bandwidth parameter: when computing the loess fit at * The bandwidth parameter: when computing the loess fit at
* a particular point, this fraction of source points closest * a particular point, this fraction of source points closest

View File

@ -229,19 +229,14 @@ public class UnivariateRealSolverUtils {
} }
} }
// CHECKSTYLE: stop HideUtilityClassConstructor
/** Holder for the factory. /** Holder for the factory.
* <p>We use here the Initialization On Demand Holder Idiom.</p> * <p>We use here the Initialization On Demand Holder Idiom.</p>
*/ */
private static class LazyHolder { private static class LazyHolder {
/** Private constructor. */
private LazyHolder() {
}
/** Cached solver factory */ /** Cached solver factory */
private static final UnivariateRealSolverFactory FACTORY = private static final UnivariateRealSolverFactory FACTORY = UnivariateRealSolverFactory.newInstance();
UnivariateRealSolverFactory.newInstance();
} }
// CHECKSTYLE: resume HideUtilityClassConstructor
} }

View File

@ -45,9 +45,6 @@ import org.apache.commons.math.util.MathUtils;
*/ */
public class Complex implements FieldElement<Complex>, Serializable { public class Complex implements FieldElement<Complex>, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -6195664516687396620L;
/** The square root of -1. A number representing "0.0 + 1.0i" */ /** The square root of -1. A number representing "0.0 + 1.0i" */
public static final Complex I = new Complex(0.0, 1.0); public static final Complex I = new Complex(0.0, 1.0);
@ -65,24 +62,19 @@ public class Complex implements FieldElement<Complex>, Serializable {
/** 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);
/** /** Serializable version identifier */
* The imaginary part private static final long serialVersionUID = -6195664516687396620L;
*/
/** 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;
/** /**

View File

@ -57,19 +57,15 @@ public class ComplexField implements Field<Complex>, Serializable {
return Complex.ZERO; return Complex.ZERO;
} }
// CHECKSTYLE: stop HideUtilityClassConstructor
/** Holder for the instance. /** Holder for the instance.
* <p>We use here the Initialization On Demand Holder Idiom.</p> * <p>We use here the Initialization On Demand Holder Idiom.</p>
*/ */
private static class LazyHolder { private static class LazyHolder {
/** Private constructor. */
private LazyHolder() {
}
/** Cached field instance. */ /** Cached field instance. */
private static final ComplexField INSTANCE = new ComplexField(); private static final ComplexField INSTANCE = new ComplexField();
} }
// CHECKSTYLE: resume HideUtilityClassConstructor
/** Handle deserialization of the singleton. /** Handle deserialization of the singleton.
* @return the singleton instance * @return the singleton instance

View File

@ -40,6 +40,47 @@ public abstract class AbstractEstimator implements Estimator {
/** Default maximal number of cost evaluations allowed. */ /** Default maximal number of cost evaluations allowed. */
public static final int DEFAULT_MAX_COST_EVALUATIONS = 100; public static final int DEFAULT_MAX_COST_EVALUATIONS = 100;
/** Array of measurements. */
protected WeightedMeasurement[] measurements;
/** Array of parameters. */
protected EstimatedParameter[] parameters;
/**
* Jacobian matrix.
* <p>This matrix is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver
* in the derived class (the {@link LevenbergMarquardtEstimator
* Levenberg-Marquardt estimator} does this).</p>
*/
protected double[] jacobian;
/** Number of columns of the jacobian matrix. */
protected int cols;
/** Number of rows of the jacobian matrix. */
protected int rows;
/** Residuals array.
* <p>This array is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver
* in the derived class (the {@link LevenbergMarquardtEstimator
* Levenberg-Marquardt estimator} does this).</p>
*/
protected double[] residuals;
/** Cost value (square root of the sum of the residuals). */
protected double cost;
/** Maximal allowed number of cost evaluations. */
private int maxCostEval;
/** Number of cost evaluations. */
private int costEvaluations;
/** Number of jacobian evaluations. */
private int jacobianEvaluations;
/** /**
* Build an abstract estimator for least squares problems. * Build an abstract estimator for least squares problems.
* <p>The maximal number of cost evaluations allowed is set * <p>The maximal number of cost evaluations allowed is set
@ -270,45 +311,4 @@ public abstract class AbstractEstimator implements Estimator {
public abstract void estimate(EstimationProblem problem) public abstract void estimate(EstimationProblem problem)
throws EstimationException; throws EstimationException;
/** Array of measurements. */
protected WeightedMeasurement[] measurements;
/** Array of parameters. */
protected EstimatedParameter[] parameters;
/**
* Jacobian matrix.
* <p>This matrix is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver
* in the derived class (the {@link LevenbergMarquardtEstimator
* Levenberg-Marquardt estimator} does this).</p>
*/
protected double[] jacobian;
/** Number of columns of the jacobian matrix. */
protected int cols;
/** Number of rows of the jacobian matrix. */
protected int rows;
/** Residuals array.
* <p>This array is in canonical form just after the calls to
* {@link #updateJacobian()}, but may be modified by the solver
* in the derived class (the {@link LevenbergMarquardtEstimator
* Levenberg-Marquardt estimator} does this).</p>
*/
protected double[] residuals;
/** Cost value (square root of the sum of the residuals). */
protected double cost;
/** Maximal allowed number of cost evaluations. */
private int maxCostEval;
/** Number of cost evaluations. */
private int costEvaluations;
/** Number of jacobian evaluations. */
private int jacobianEvaluations;
} }

View File

@ -37,90 +37,90 @@ import java.io.Serializable;
public class EstimatedParameter public class EstimatedParameter
implements Serializable { implements Serializable {
/** Simple constructor. /** Serializable version identifier */
* Build an instance from a first estimate of the parameter, private static final long serialVersionUID = -555440800213416949L;
* initially considered unbound.
* @param name name of the parameter
* @param firstEstimate first estimate of the parameter
*/
public EstimatedParameter(String name, double firstEstimate) {
this.name = name;
estimate = firstEstimate;
bound = false;
}
/** Simple constructor. /** Current value of the parameter */
* Build an instance from a first estimate of the parameter and a protected double estimate;
* bound flag
* @param name name of the parameter
* @param firstEstimate first estimate of the parameter
* @param bound flag, should be true if the parameter is bound
*/
public EstimatedParameter(String name,
double firstEstimate,
boolean bound) {
this.name = name;
estimate = firstEstimate;
this.bound = bound;
}
/** Copy constructor. /** Name of the parameter */
* Build a copy of a parameter private String name;
* @param parameter instance to copy
*/
public EstimatedParameter(EstimatedParameter parameter) {
name = parameter.name;
estimate = parameter.estimate;
bound = parameter.bound;
}
/** Set a new estimated value for the parameter. /** Indicator for bound parameters
* @param estimate new estimate for the parameter * (ie parameters that should not be estimated)
*/ */
public void setEstimate(double estimate) { private boolean bound;
this.estimate = estimate;
}
/** Get the current estimate of the parameter /** Simple constructor.
* @return current estimate * Build an instance from a first estimate of the parameter,
*/ * initially considered unbound.
public double getEstimate() { * @param name name of the parameter
return estimate; * @param firstEstimate first estimate of the parameter
} */
public EstimatedParameter(String name, double firstEstimate) {
this.name = name;
estimate = firstEstimate;
bound = false;
}
/** get the name of the parameter /** Simple constructor.
* @return parameter name * Build an instance from a first estimate of the parameter and a
*/ * bound flag
public String getName() { * @param name name of the parameter
return name; * @param firstEstimate first estimate of the parameter
} * @param bound flag, should be true if the parameter is bound
*/
public EstimatedParameter(String name,
double firstEstimate,
boolean bound) {
this.name = name;
estimate = firstEstimate;
this.bound = bound;
}
/** Set the bound flag of the parameter /** Copy constructor.
* @param bound this flag should be set to true if the parameter is * Build a copy of a parameter
* bound (i.e. if it should not be adjusted by the solver). * @param parameter instance to copy
*/ */
public void setBound(boolean bound) { public EstimatedParameter(EstimatedParameter parameter) {
this.bound = bound; name = parameter.name;
} estimate = parameter.estimate;
bound = parameter.bound;
}
/** Check if the parameter is bound /** Set a new estimated value for the parameter.
* @return true if the parameter is bound */ * @param estimate new estimate for the parameter
public boolean isBound() { */
return bound; public void setEstimate(double estimate) {
} this.estimate = estimate;
}
/** Name of the parameter */ /** Get the current estimate of the parameter
private String name; * @return current estimate
*/
public double getEstimate() {
return estimate;
}
/** Current value of the parameter */ /** get the name of the parameter
protected double estimate; * @return parameter name
*/
public String getName() {
return name;
}
/** Indicator for bound parameters /** Set the bound flag of the parameter
* (ie parameters that should not be estimated) * @param bound this flag should be set to true if the parameter is
*/ * bound (i.e. if it should not be adjusted by the solver).
private boolean bound; */
public void setBound(boolean bound) {
this.bound = bound;
}
/** Serializable version identifier */ /** Check if the parameter is bound
private static final long serialVersionUID = -555440800213416949L; * @return true if the parameter is bound */
public boolean isBound() {
return bound;
}
} }

View File

@ -103,6 +103,46 @@ import java.util.Arrays;
@Deprecated @Deprecated
public class LevenbergMarquardtEstimator extends AbstractEstimator implements Serializable { public class LevenbergMarquardtEstimator extends AbstractEstimator implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -5705952631533171019L;
/** Number of solved variables. */
private int solvedCols;
/** Diagonal elements of the R matrix in the Q.R. decomposition. */
private double[] diagR;
/** Norms of the columns of the jacobian matrix. */
private double[] jacNorm;
/** Coefficients of the Householder transforms vectors. */
private double[] beta;
/** Columns permutation array. */
private int[] permutation;
/** Rank of the jacobian matrix. */
private int rank;
/** Levenberg-Marquardt parameter. */
private double lmPar;
/** Parameters evolution direction associated with lmPar. */
private double[] lmDir;
/** Positive input variable used in determining the initial step bound. */
private double initialStepBoundFactor;
/** Desired relative error in the sum of squares. */
private double costRelativeTolerance;
/** Desired relative error in the approximate solution parameters. */
private double parRelativeTolerance;
/** Desired max cosine on the orthogonality between the function vector
* and the columns of the jacobian. */
private double orthoTolerance;
/** /**
* 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:
@ -834,44 +874,4 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
} }
} }
/** Number of solved variables. */
private int solvedCols;
/** Diagonal elements of the R matrix in the Q.R. decomposition. */
private double[] diagR;
/** Norms of the columns of the jacobian matrix. */
private double[] jacNorm;
/** Coefficients of the Householder transforms vectors. */
private double[] beta;
/** Columns permutation array. */
private int[] permutation;
/** Rank of the jacobian matrix. */
private int rank;
/** Levenberg-Marquardt parameter. */
private double lmPar;
/** Parameters evolution direction associated with lmPar. */
private double[] lmDir;
/** Positive input variable used in determining the initial step bound. */
private double initialStepBoundFactor;
/** Desired relative error in the sum of squares. */
private double costRelativeTolerance;
/** Desired relative error in the approximate solution parameters. */
private double parRelativeTolerance;
/** Desired max cosine on the orthogonality between the function vector
* and the columns of the jacobian. */
private double orthoTolerance;
/** Serializable version identifier */
private static final long serialVersionUID = -5705952631533171019L;
} }

View File

@ -44,6 +44,12 @@ import java.util.List;
@Deprecated @Deprecated
public class SimpleEstimationProblem implements EstimationProblem { public class SimpleEstimationProblem implements EstimationProblem {
/** Estimated parameters. */
private final List<EstimatedParameter> parameters;
/** Measurements. */
private final List<WeightedMeasurement> measurements;
/** /**
* Build an empty instance without parameters nor measurements. * Build an empty instance without parameters nor measurements.
*/ */
@ -102,10 +108,4 @@ public class SimpleEstimationProblem implements EstimationProblem {
measurements.add(m); measurements.add(m);
} }
/** Estimated parameters. */
private final List<EstimatedParameter> parameters;
/** Measurements. */
private final List<WeightedMeasurement> measurements;
} }

View File

@ -56,7 +56,16 @@ public abstract class WeightedMeasurement implements Serializable {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = 4360046376796901941L; private static final long serialVersionUID = 4360046376796901941L;
/** /** Measurement weight. */
private final double weight;
/** Value of the measurements. */
private final double measuredValue;
/** Ignore measurement indicator. */
private boolean ignored;
/**
* Simple constructor. * Simple constructor.
* Build a measurement with the given parameters, and set its ignore * Build a measurement with the given parameters, and set its ignore
* flag to false. * flag to false.
@ -160,13 +169,4 @@ public abstract class WeightedMeasurement implements Serializable {
return ignored; return ignored;
} }
/** Measurement weight. */
private final double weight;
/** Value of the measurements. */
private final double measuredValue;
/** Ignore measurement indicator. */
private boolean ignored;
} }

View File

@ -89,34 +89,6 @@ public class BigFraction
/** The denominator. */ /** The denominator. */
private final BigInteger denominator; private final BigInteger denominator;
/**
* <p>
* Creates a <code>BigFraction</code> instance with the 2 parts of a fraction
* Y/Z.
* </p>
*
* <p>
* Any negative signs are resolved to be on the numerator.
* </p>
*
* @param numerator
* the numerator, for example the three in 'three sevenths'.
* @param denominator
* the denominator, for example the seven in 'three sevenths'.
* @return a new fraction instance, with the numerator and denominator
* reduced.
* @throws ArithmeticException
* if the denominator is <code>zero</code>.
*/
public static BigFraction getReducedFraction(final int numerator,
final int denominator) {
if (numerator == 0) {
return ZERO; // normalize zero.
}
return new BigFraction(numerator, denominator);
}
/** /**
* <p> * <p>
* Create a {@link BigFraction} equivalent to the passed <tt>BigInteger</tt>, ie * Create a {@link BigFraction} equivalent to the passed <tt>BigInteger</tt>, ie
@ -441,6 +413,34 @@ public class BigFraction
this(BigInteger.valueOf(num), BigInteger.valueOf(den)); this(BigInteger.valueOf(num), BigInteger.valueOf(den));
} }
/**
* <p>
* Creates a <code>BigFraction</code> instance with the 2 parts of a fraction
* Y/Z.
* </p>
*
* <p>
* Any negative signs are resolved to be on the numerator.
* </p>
*
* @param numerator
* the numerator, for example the three in 'three sevenths'.
* @param denominator
* the denominator, for example the seven in 'three sevenths'.
* @return a new fraction instance, with the numerator and denominator
* reduced.
* @throws ArithmeticException
* if the denominator is <code>zero</code>.
*/
public static BigFraction getReducedFraction(final int numerator,
final int denominator) {
if (numerator == 0) {
return ZERO; // normalize zero.
}
return new BigFraction(numerator, denominator);
}
/** /**
* <p> * <p>
* Returns the absolute value of this {@link BigFraction}. * Returns the absolute value of this {@link BigFraction}.

View File

@ -57,19 +57,15 @@ public class BigFractionField implements Field<BigFraction>, Serializable {
return BigFraction.ZERO; return BigFraction.ZERO;
} }
// CHECKSTYLE: stop HideUtilityClassConstructor
/** Holder for the instance. /** Holder for the instance.
* <p>We use here the Initialization On Demand Holder Idiom.</p> * <p>We use here the Initialization On Demand Holder Idiom.</p>
*/ */
private static class LazyHolder { private static class LazyHolder {
/** Private constructor. */
private LazyHolder() {
}
/** Cached field instance. */ /** Cached field instance. */
private static final BigFractionField INSTANCE = new BigFractionField(); private static final BigFractionField INSTANCE = new BigFractionField();
} }
// CHECKSTYLE: resume HideUtilityClassConstructor
/** Handle deserialization of the singleton. /** Handle deserialization of the singleton.
* @return the singleton instance * @return the singleton instance

View File

@ -57,19 +57,15 @@ public class FractionField implements Field<Fraction>, Serializable {
return Fraction.ZERO; return Fraction.ZERO;
} }
// CHECKSTYLE: stop HideUtilityClassConstructor
/** Holder for the instance. /** Holder for the instance.
* <p>We use here the Initialization On Demand Holder Idiom.</p> * <p>We use here the Initialization On Demand Holder Idiom.</p>
*/ */
private static class LazyHolder { private static class LazyHolder {
/** Private constructor. */
private LazyHolder() {
}
/** Cached field instance. */ /** Cached field instance. */
private static final FractionField INSTANCE = new FractionField(); private static final FractionField INSTANCE = new FractionField();
} }
// CHECKSTYLE: resume HideUtilityClassConstructor
/** Handle deserialization of the singleton. /** Handle deserialization of the singleton.
* @return the singleton instance * @return the singleton instance

View File

@ -37,24 +37,6 @@ public class GeneticAlgorithm {
//@GuardedBy("this") //@GuardedBy("this")
private static RandomGenerator randomGenerator = new JDKRandomGenerator(); private static RandomGenerator randomGenerator = new JDKRandomGenerator();
/**
* Set the (static) random generator.
*
* @param random random generator
*/
public static synchronized void setRandomGenerator(RandomGenerator random) {
randomGenerator = random;
}
/**
* Returns the (static) random generator.
*
* @return the static random generator shared by GA implementation classes
*/
public static synchronized RandomGenerator getRandomGenerator() {
return randomGenerator;
}
/** the crossover policy used by the algorithm. */ /** the crossover policy used by the algorithm. */
private final CrossoverPolicy crossoverPolicy; private final CrossoverPolicy crossoverPolicy;
@ -94,6 +76,24 @@ public class GeneticAlgorithm {
this.selectionPolicy = selectionPolicy; this.selectionPolicy = selectionPolicy;
} }
/**
* Set the (static) random generator.
*
* @param random random generator
*/
public static synchronized void setRandomGenerator(RandomGenerator random) {
randomGenerator = random;
}
/**
* Returns the (static) random generator.
*
* @return the static random generator shared by GA implementation classes
*/
public static synchronized RandomGenerator getRandomGenerator() {
return randomGenerator;
}
/** /**
* Evolve the given population. Evolution stops when the stopping condition * Evolve the given population. Evolution stops when the stopping condition
* is satisfied. * is satisfied.

View File

@ -28,17 +28,17 @@ import org.apache.commons.math.MathException;
public class CardanEulerSingularityException public class CardanEulerSingularityException
extends MathException { extends MathException {
/** /** Serializable version identifier */
* Simple constructor. private static final long serialVersionUID = -1360952845582206770L;
* build an exception with a default message.
* @param isCardan if true, the rotation is related to Cardan angles,
* if false it is related to EulerAngles
*/
public CardanEulerSingularityException(boolean isCardan) {
super(isCardan ? "Cardan angles singularity" : "Euler angles singularity");
}
/** Serializable version identifier */ /**
private static final long serialVersionUID = -1360952845582206770L; * Simple constructor.
* build an exception with a default message.
* @param isCardan if true, the rotation is related to Cardan angles,
* if false it is related to EulerAngles
*/
public CardanEulerSingularityException(boolean isCardan) {
super(isCardan ? "Cardan angles singularity" : "Euler angles singularity");
}
} }

View File

@ -30,17 +30,17 @@ import org.apache.commons.math.MathException;
public class NotARotationMatrixException public class NotARotationMatrixException
extends MathException { extends MathException {
/** /** Serializable version identifier */
* Simple constructor. private static final long serialVersionUID = 5647178478658937642L;
* Build an exception by translating and formating a message
* @param specifier format specifier (to be translated)
* @param parts to insert in the format (no translation)
*/
public NotARotationMatrixException(String specifier, Object ... parts) {
super(specifier, parts);
}
/** Serializable version identifier */ /**
private static final long serialVersionUID = 5647178478658937642L; * Simple constructor.
* Build an exception by translating and formating a message
* @param specifier format specifier (to be translated)
* @param parts to insert in the format (no translation)
*/
public NotARotationMatrixException(String specifier, Object ... parts) {
super(specifier, parts);
}
} }

View File

@ -31,145 +31,145 @@ package org.apache.commons.math.geometry;
*/ */
public final class RotationOrder { public final class RotationOrder {
/** Private constructor. /** Set of Cardan angles.
* This is a utility class that cannot be instantiated by the user, * this ordered set of rotations is around X, then around Y, then
* so its only constructor is private. * around Z
* @param name name of the rotation order */
* @param a1 axis of the first rotation public static final RotationOrder XYZ =
* @param a2 axis of the second rotation new RotationOrder("XYZ", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_K);
* @param a3 axis of the third rotation
*/
private RotationOrder(String name,
Vector3D a1, Vector3D a2, Vector3D a3) {
this.name = name;
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
}
/** Get a string representation of the instance. /** Set of Cardan angles.
* @return a string representation of the instance (in fact, its name) * this ordered set of rotations is around X, then around Z, then
*/ * around Y
@Override */
public String toString() { public static final RotationOrder XZY =
return name; new RotationOrder("XZY", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_J);
}
/** Get the axis of the first rotation. /** Set of Cardan angles.
* @return axis of the first rotation * this ordered set of rotations is around Y, then around X, then
*/ * around Z
public Vector3D getA1() { */
return a1; public static final RotationOrder YXZ =
} new RotationOrder("YXZ", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K);
/** Get the axis of the second rotation. /** Set of Cardan angles.
* @return axis of the second rotation * this ordered set of rotations is around Y, then around Z, then
*/ * around X
public Vector3D getA2() { */
return a2; public static final RotationOrder YZX =
} new RotationOrder("YZX", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I);
/** Get the axis of the second rotation. /** Set of Cardan angles.
* @return axis of the second rotation * this ordered set of rotations is around Z, then around X, then
*/ * around Y
public Vector3D getA3() { */
return a3; public static final RotationOrder ZXY =
} new RotationOrder("ZXY", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J);
/** Set of Cardan angles. /** Set of Cardan angles.
* this ordered set of rotations is around X, then around Y, then * this ordered set of rotations is around Z, then around Y, then
* around Z * around X
*/ */
public static final RotationOrder XYZ = public static final RotationOrder ZYX =
new RotationOrder("XYZ", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_K); new RotationOrder("ZYX", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_I);
/** Set of Cardan angles. /** Set of Euler angles.
* this ordered set of rotations is around X, then around Z, then * this ordered set of rotations is around X, then around Y, then
* around Y * around X
*/ */
public static final RotationOrder XZY = public static final RotationOrder XYX =
new RotationOrder("XZY", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_J); new RotationOrder("XYX", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_I);
/** Set of Cardan angles. /** Set of Euler angles.
* this ordered set of rotations is around Y, then around X, then * this ordered set of rotations is around X, then around Z, then
* around Z * around X
*/ */
public static final RotationOrder YXZ = public static final RotationOrder XZX =
new RotationOrder("YXZ", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K); new RotationOrder("XZX", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_I);
/** Set of Cardan angles. /** Set of Euler angles.
* this ordered set of rotations is around Y, then around Z, then * this ordered set of rotations is around Y, then around X, then
* around X * around Y
*/ */
public static final RotationOrder YZX = public static final RotationOrder YXY =
new RotationOrder("YZX", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I); new RotationOrder("YXY", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_J);
/** Set of Cardan angles. /** Set of Euler angles.
* this ordered set of rotations is around Z, then around X, then * this ordered set of rotations is around Y, then around Z, then
* around Y * around Y
*/ */
public static final RotationOrder ZXY = public static final RotationOrder YZY =
new RotationOrder("ZXY", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J); new RotationOrder("YZY", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_J);
/** Set of Cardan angles. /** Set of Euler angles.
* this ordered set of rotations is around Z, then around Y, then * this ordered set of rotations is around Z, then around X, then
* around X * around Z
*/ */
public static final RotationOrder ZYX = public static final RotationOrder ZXZ =
new RotationOrder("ZYX", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_I); new RotationOrder("ZXZ", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K);
/** Set of Euler angles. /** Set of Euler angles.
* this ordered set of rotations is around X, then around Y, then * this ordered set of rotations is around Z, then around Y, then
* around X * around Z
*/ */
public static final RotationOrder XYX = public static final RotationOrder ZYZ =
new RotationOrder("XYX", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_I); new RotationOrder("ZYZ", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_K);
/** Set of Euler angles. /** Name of the rotations order. */
* this ordered set of rotations is around X, then around Z, then private final String name;
* around X
*/
public static final RotationOrder XZX =
new RotationOrder("XZX", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_I);
/** Set of Euler angles. /** Axis of the first rotation. */
* this ordered set of rotations is around Y, then around X, then private final Vector3D a1;
* around Y
*/
public static final RotationOrder YXY =
new RotationOrder("YXY", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_J);
/** Set of Euler angles. /** Axis of the second rotation. */
* this ordered set of rotations is around Y, then around Z, then private final Vector3D a2;
* around Y
*/
public static final RotationOrder YZY =
new RotationOrder("YZY", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_J);
/** Set of Euler angles. /** Axis of the third rotation. */
* this ordered set of rotations is around Z, then around X, then private final Vector3D a3;
* around Z
*/
public static final RotationOrder ZXZ =
new RotationOrder("ZXZ", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K);
/** Set of Euler angles. /** Private constructor.
* this ordered set of rotations is around Z, then around Y, then * This is a utility class that cannot be instantiated by the user,
* around Z * so its only constructor is private.
*/ * @param name name of the rotation order
public static final RotationOrder ZYZ = * @param a1 axis of the first rotation
new RotationOrder("ZYZ", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_K); * @param a2 axis of the second rotation
* @param a3 axis of the third rotation
*/
private RotationOrder(final String name,
final Vector3D a1, final Vector3D a2, final Vector3D a3) {
this.name = name;
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
}
/** Name of the rotations order. */ /** Get a string representation of the instance.
private final String name; * @return a string representation of the instance (in fact, its name)
*/
@Override
public String toString() {
return name;
}
/** Axis of the first rotation. */ /** Get the axis of the first rotation.
private final Vector3D a1; * @return axis of the first rotation
*/
public Vector3D getA1() {
return a1;
}
/** Axis of the second rotation. */ /** Get the axis of the second rotation.
private final Vector3D a2; * @return axis of the second rotation
*/
public Vector3D getA2() {
return a2;
}
/** Axis of the third rotation. */ /** Get the axis of the second rotation.
private final Vector3D a3; * @return axis of the second rotation
*/
public Vector3D getA3() {
return a3;
}
} }

View File

@ -38,6 +38,45 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
/** Field to which the elements belong. */ /** Field to which the elements belong. */
private final Field<T> field; private final Field<T> field;
/**
* Constructor for use with Serializable
*/
protected AbstractFieldMatrix() {
field = null;
}
/**
* Creates a matrix with no data
* @param field field to which the elements belong
*/
protected AbstractFieldMatrix(final Field<T> field) {
this.field = field;
}
/**
* Create a new FieldMatrix<T> with the supplied row and column dimensions.
*
* @param field field to which the elements belong
* @param rowDimension the number of rows in the new matrix
* @param columnDimension the number of columns in the new matrix
* @throws IllegalArgumentException if row or column dimension is not positive
*/
protected AbstractFieldMatrix(final Field<T> field,
final int rowDimension, final int columnDimension)
throws IllegalArgumentException {
if (rowDimension <= 0 ) {
throw MathRuntimeException.createIllegalArgumentException(
"invalid row dimension {0} (must be positive)",
rowDimension);
}
if (columnDimension <= 0) {
throw MathRuntimeException.createIllegalArgumentException(
"invalid column dimension {0} (must be positive)",
columnDimension);
}
this.field = field;
}
/** /**
* Get the elements type from an array. * Get the elements type from an array.
* @param <T> the type of the field elements * @param <T> the type of the field elements
@ -115,45 +154,6 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>> implements
return array; return array;
} }
/**
* Constructor for use with Serializable
*/
protected AbstractFieldMatrix() {
field = null;
}
/**
* Creates a matrix with no data
* @param field field to which the elements belong
*/
protected AbstractFieldMatrix(final Field<T> field) {
this.field = field;
}
/**
* Create a new FieldMatrix<T> with the supplied row and column dimensions.
*
* @param field field to which the elements belong
* @param rowDimension the number of rows in the new matrix
* @param columnDimension the number of columns in the new matrix
* @throws IllegalArgumentException if row or column dimension is not positive
*/
protected AbstractFieldMatrix(final Field<T> field,
final int rowDimension, final int columnDimension)
throws IllegalArgumentException {
if (rowDimension <= 0 ) {
throw MathRuntimeException.createIllegalArgumentException(
"invalid row dimension {0} (must be positive)",
rowDimension);
}
if (columnDimension <= 0) {
throw MathRuntimeException.createIllegalArgumentException(
"invalid column dimension {0} (must be positive)",
columnDimension);
}
this.field = field;
}
/** {@inheritDoc} */ /** {@inheritDoc} */
public Field<T> getField() { public Field<T> getField() {
return field; return field;

View File

@ -35,20 +35,11 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = 7648186910365927050L; private static final long serialVersionUID = 7648186910365927050L;
/** Field to which the elements belong. */
private final Field<T> field;
/** Entries of the vector. */ /** Entries of the vector. */
protected T[] data; protected T[] data;
/** Build an array of elements. /** Field to which the elements belong. */
* @param length size of the array to build private final Field<T> field;
* @return a new array
*/
@SuppressWarnings("unchecked")
private T[] buildArray(final int length) {
return (T[]) Array.newInstance(field.getZero().getClass(), length);
}
/** /**
* Build a 0-length vector. * Build a 0-length vector.
@ -228,6 +219,15 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
} }
} }
/** Build an array of elements.
* @param length size of the array to build
* @return a new array
*/
@SuppressWarnings("unchecked")
private T[] buildArray(final int length) {
return (T[]) Array.newInstance(field.getZero().getClass(), length);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
public Field<T> getField() { public Field<T> getField() {
return field; return field;

View File

@ -54,6 +54,15 @@ import org.apache.commons.math.MathRuntimeException;
@Deprecated @Deprecated
public class BigMatrixImpl implements BigMatrix, Serializable { public class BigMatrixImpl implements BigMatrix, Serializable {
/** BigDecimal 0 */
static final BigDecimal ZERO = new BigDecimal(0);
/** BigDecimal 1 */
static final BigDecimal ONE = new BigDecimal(1);
/** Bound to determine effective singularity in LU decomposition */
private static final BigDecimal TOO_SMALL = new BigDecimal(10E-12);
/** Serialization id */ /** Serialization id */
private static final long serialVersionUID = -1011428905656140431L; private static final long serialVersionUID = -1011428905656140431L;
@ -77,14 +86,6 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
/*** BigDecimal scale ***/ /*** BigDecimal scale ***/
private int scale = 64; private int scale = 64;
/** Bound to determine effective singularity in LU decomposition */
private static final BigDecimal TOO_SMALL = new BigDecimal(10E-12);
/** BigDecimal 0 */
static final BigDecimal ZERO = new BigDecimal(0);
/** BigDecimal 1 */
static final BigDecimal ONE = new BigDecimal(1);
/** /**
* Creates a matrix with no data * Creates a matrix with no data
*/ */

View File

@ -65,12 +65,12 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T> implements Serializable { public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T> implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -4602336630143123183L;
/** Block size. */ /** Block size. */
public static final int BLOCK_SIZE = 36; public static final int BLOCK_SIZE = 36;
/** Serializable version identifier */
private static final long serialVersionUID = -4602336630143123183L;
/** Blocks of matrix entries. */ /** Blocks of matrix entries. */
private final T blocks[][]; private final T blocks[][];

View File

@ -63,12 +63,12 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class BlockRealMatrix extends AbstractRealMatrix implements Serializable { public class BlockRealMatrix extends AbstractRealMatrix implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = 4991895511313664478L;
/** Block size. */ /** Block size. */
public static final int BLOCK_SIZE = 52; public static final int BLOCK_SIZE = 52;
/** Serializable version identifier */
private static final long serialVersionUID = 4991895511313664478L;
/** Blocks of matrix entries. */ /** Blocks of matrix entries. */
private final double blocks[][]; private final double blocks[][];

View File

@ -33,6 +33,9 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class LUDecompositionImpl implements LUDecomposition { public class LUDecompositionImpl implements LUDecomposition {
/** Default bound to determine effective singularity in LU decomposition */
private static final double DEFAULT_TOO_SMALL = 10E-12;
/** Entries of LU decomposition. */ /** Entries of LU decomposition. */
private double lu[][]; private double lu[][];
@ -54,9 +57,6 @@ public class LUDecompositionImpl implements LUDecomposition {
/** Cached value of P. */ /** Cached value of P. */
private RealMatrix cachedP; private RealMatrix cachedP;
/** Default bound to determine effective singularity in LU decomposition */
private static final double DEFAULT_TOO_SMALL = 10E-12;
/** /**
* Calculates the LU-decomposition of the given matrix. * Calculates the LU-decomposition of the given matrix.
* @param matrix The matrix to decompose. * @param matrix The matrix to decompose.

View File

@ -29,12 +29,12 @@ import org.apache.commons.math.util.OpenIntToDoubleHashMap.Iterator;
*/ */
public class OpenMapRealVector implements SparseRealVector, Serializable { public class OpenMapRealVector implements SparseRealVector, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 8772222695580707260L;
/** Default Tolerance for having a value considered zero. */ /** Default Tolerance for having a value considered zero. */
public static final double DEFAULT_ZERO_TOLERANCE = 1.0e-12; public static final double DEFAULT_ZERO_TOLERANCE = 1.0e-12;
/** Serializable version identifier. */
private static final long serialVersionUID = 8772222695580707260L;
/** Entries of the vector. */ /** Entries of the vector. */
private final OpenIntToDoubleHashMap entries; private final OpenIntToDoubleHashMap entries;

View File

@ -34,6 +34,17 @@ import org.apache.commons.math.ode.sampling.StepHandler;
*/ */
public abstract class AbstractIntegrator implements FirstOrderIntegrator { public abstract class AbstractIntegrator implements FirstOrderIntegrator {
/** Step handler. */
protected Collection<StepHandler> stepHandlers;
/** Current step start time. */
protected double stepStart;
/** Current stepsize. */
protected double stepSize;
/** Events handlers manager. */
protected CombinedEventsManager eventsHandlersManager;
/** Name of the method. */ /** Name of the method. */
private final String name; private final String name;
@ -47,18 +58,6 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
/** Differential equations to integrate. */ /** Differential equations to integrate. */
private transient FirstOrderDifferentialEquations equations; private transient FirstOrderDifferentialEquations equations;
/** Step handler. */
protected Collection<StepHandler> stepHandlers;
/** Current step start time. */
protected double stepStart;
/** Current stepsize. */
protected double stepSize;
/** Events handlers manager. */
protected CombinedEventsManager eventsHandlersManager;
/** Build an instance. /** Build an instance.
* @param name name of the method * @param name name of the method
*/ */

View File

@ -86,6 +86,24 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
public class ContinuousOutputModel public class ContinuousOutputModel
implements StepHandler, Serializable { implements StepHandler, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -1417964919405031606L;
/** Initial integration time. */
private double initialTime;
/** Final integration time. */
private double finalTime;
/** Integration direction indicator. */
private boolean forward;
/** Current interpolator index. */
private int index;
/** Steps table. */
private List<StepInterpolator> steps;
/** Simple constructor. /** Simple constructor.
* Build an empty continuous output model. * Build an empty continuous output model.
*/ */
@ -355,22 +373,4 @@ public class ContinuousOutputModel
} }
} }
/** Initial integration time. */
private double initialTime;
/** Final integration time. */
private double finalTime;
/** Integration direction indicator. */
private boolean forward;
/** Current interpolator index. */
private int index;
/** Steps table. */
private List<StepInterpolator> steps;
/** Serializable version identifier */
private static final long serialVersionUID = -1417964919405031606L;
} }

View File

@ -55,6 +55,21 @@ package org.apache.commons.math.ode;
public class FirstOrderConverter implements FirstOrderDifferentialEquations { public class FirstOrderConverter implements FirstOrderDifferentialEquations {
/** Underlying second order equations set. */
private final SecondOrderDifferentialEquations equations;
/** second order problem dimension. */
private final int dimension;
/** state vector. */
private final double[] z;
/** first time derivative of the state vector. */
private final double[] zDot;
/** second time derivative of the state vector. */
private final double[] zDDot;
/** Simple constructor. /** Simple constructor.
* Build a converter around a second order equations set. * Build a converter around a second order equations set.
* @param equations second order equations set to convert * @param equations second order equations set to convert
@ -99,19 +114,4 @@ public class FirstOrderConverter implements FirstOrderDifferentialEquations {
} }
/** Underlying second order equations set. */
private SecondOrderDifferentialEquations equations;
/** second order problem dimension. */
private int dimension;
/** state vector. */
private double[] z;
/** first time derivative of the state vector. */
private double[] zDot;
/** second time derivative of the state vector. */
private double[] zDDot;
} }

View File

@ -58,12 +58,6 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
*/ */
public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator {
/** Starter integrator. */
private FirstOrderIntegrator starter;
/** Number of steps of the multistep method (excluding the one being computed). */
private final int nSteps;
/** First scaled derivative (h y'). */ /** First scaled derivative (h y'). */
protected double[] scaled; protected double[] scaled;
@ -72,6 +66,12 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator {
*/ */
protected Array2DRowRealMatrix nordsieck; protected Array2DRowRealMatrix nordsieck;
/** Starter integrator. */
private FirstOrderIntegrator starter;
/** Number of steps of the multistep method (excluding the one being computed). */
private final int nSteps;
/** Stepsize control exponent. */ /** Stepsize control exponent. */
private double exp; private double exp;

View File

@ -54,6 +54,26 @@ import org.apache.commons.math.ode.IntegratorException;
public abstract class AdaptiveStepsizeIntegrator public abstract class AdaptiveStepsizeIntegrator
extends AbstractIntegrator { extends AbstractIntegrator {
/** Allowed absolute scalar error. */
protected final double scalAbsoluteTolerance;
/** Allowed relative scalar error. */
protected final double scalRelativeTolerance;
/** Allowed absolute vectorial error. */
protected final double[] vecAbsoluteTolerance;
/** Allowed relative vectorial error. */
protected final double[] vecRelativeTolerance;
/** User supplied initial step. */
private double initialStep;
/** Minimal step. */
private final double minStep;
/** Maximal step. */
private final double maxStep;
/** Build an integrator with the given stepsize bounds. /** Build an integrator with the given stepsize bounds.
* The default step handler does nothing. * The default step handler does nothing.
@ -310,25 +330,4 @@ public abstract class AdaptiveStepsizeIntegrator
return maxStep; return maxStep;
} }
/** Minimal step. */
private double minStep;
/** Maximal step. */
private double maxStep;
/** User supplied initial step. */
private double initialStep;
/** Allowed absolute scalar error. */
protected double scalAbsoluteTolerance;
/** Allowed relative scalar error. */
protected double scalRelativeTolerance;
/** Allowed absolute vectorial error. */
protected double[] vecAbsoluteTolerance;
/** Allowed relative vectorial error. */
protected double[] vecRelativeTolerance;
} }

View File

@ -34,6 +34,61 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class DormandPrince54StepInterpolator class DormandPrince54StepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** Last row of the Butcher-array internal weights, element 0. */
private static final double A70 = 35.0 / 384.0;
// element 1 is zero, so it is neither stored nor used
/** Last row of the Butcher-array internal weights, element 2. */
private static final double A72 = 500.0 / 1113.0;
/** Last row of the Butcher-array internal weights, element 3. */
private static final double A73 = 125.0 / 192.0;
/** Last row of the Butcher-array internal weights, element 4. */
private static final double A74 = -2187.0 / 6784.0;
/** Last row of the Butcher-array internal weights, element 5. */
private static final double A75 = 11.0 / 84.0;
/** Shampine (1986) Dense output, element 0. */
private static final double D0 = -12715105075.0 / 11282082432.0;
// element 1 is zero, so it is neither stored nor used
/** Shampine (1986) Dense output, element 2. */
private static final double D2 = 87487479700.0 / 32700410799.0;
/** Shampine (1986) Dense output, element 3. */
private static final double D3 = -10690763975.0 / 1880347072.0;
/** Shampine (1986) Dense output, element 4. */
private static final double D4 = 701980252875.0 / 199316789632.0;
/** Shampine (1986) Dense output, element 5. */
private static final double D5 = -1453857185.0 / 822651844.0;
/** Shampine (1986) Dense output, element 6. */
private static final double D6 = 69997945.0 / 29380423.0;
/** Serializable version identifier */
private static final long serialVersionUID = 4104157279605906956L;
/** First vector for interpolation. */
private double[] v1;
/** Second vector for interpolation. */
private double[] v2;
/** Third vector for interpolation. */
private double[] v3;
/** Fourth vector for interpolation. */
private double[] v4;
/** Initialization indicator for the interpolation vectors. */
private boolean vectorsInitialized;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link #reinitialize} method should be called before using the * {@link #reinitialize} method should be called before using the
@ -156,59 +211,4 @@ class DormandPrince54StepInterpolator
} }
/** First vector for interpolation. */
private double[] v1;
/** Second vector for interpolation. */
private double[] v2;
/** Third vector for interpolation. */
private double[] v3;
/** Fourth vector for interpolation. */
private double[] v4;
/** Initialization indicator for the interpolation vectors. */
private boolean vectorsInitialized;
/** Last row of the Butcher-array internal weights, element 0. */
private static final double A70 = 35.0 / 384.0;
// element 1 is zero, so it is neither stored nor used
/** Last row of the Butcher-array internal weights, element 2. */
private static final double A72 = 500.0 / 1113.0;
/** Last row of the Butcher-array internal weights, element 3. */
private static final double A73 = 125.0 / 192.0;
/** Last row of the Butcher-array internal weights, element 4. */
private static final double A74 = -2187.0 / 6784.0;
/** Last row of the Butcher-array internal weights, element 5. */
private static final double A75 = 11.0 / 84.0;
/** Shampine (1986) Dense output, element 0. */
private static final double D0 = -12715105075.0 / 11282082432.0;
// element 1 is zero, so it is neither stored nor used
/** Shampine (1986) Dense output, element 2. */
private static final double D2 = 87487479700.0 / 32700410799.0;
/** Shampine (1986) Dense output, element 3. */
private static final double D3 = -10690763975.0 / 1880347072.0;
/** Shampine (1986) Dense output, element 4. */
private static final double D4 = 701980252875.0 / 199316789632.0;
/** Shampine (1986) Dense output, element 5. */
private static final double D5 = -1453857185.0 / 822651844.0;
/** Shampine (1986) Dense output, element 6. */
private static final double D6 = 69997945.0 / 29380423.0;
/** Serializable version identifier */
private static final long serialVersionUID = 4104157279605906956L;
} }

View File

@ -39,6 +39,186 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class DormandPrince853StepInterpolator class DormandPrince853StepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = 7152276390558450974L;
/** Propagation weights, element 1. */
private static final double B_01 = 104257.0 / 1920240.0;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Propagation weights, element 6. */
private static final double B_06 = 3399327.0 / 763840.0;
/** Propagation weights, element 7. */
private static final double B_07 = 66578432.0 / 35198415.0;
/** Propagation weights, element 8. */
private static final double B_08 = -1674902723.0 / 288716400.0;
/** Propagation weights, element 9. */
private static final double B_09 = 54980371265625.0 / 176692375811392.0;
/** Propagation weights, element 10. */
private static final double B_10 = -734375.0 / 4826304.0;
/** Propagation weights, element 11. */
private static final double B_11 = 171414593.0 / 851261400.0;
/** Propagation weights, element 12. */
private static final double B_12 = 137909.0 / 3084480.0;
/** Time step for stage 14 (interpolation only). */
private static final double C14 = 1.0 / 10.0;
/** Internal weights for stage 14, element 1. */
private static final double K14_01 = 13481885573.0 / 240030000000.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 14, element 6. */
private static final double K14_06 = 0.0 - B_06;
/** Internal weights for stage 14, element 7. */
private static final double K14_07 = 139418837528.0 / 549975234375.0 - B_07;
/** Internal weights for stage 14, element 8. */
private static final double K14_08 = -11108320068443.0 / 45111937500000.0 - B_08;
/** Internal weights for stage 14, element 9. */
private static final double K14_09 = -1769651421925959.0 / 14249385146080000.0 - B_09;
/** Internal weights for stage 14, element 10. */
private static final double K14_10 = 57799439.0 / 377055000.0 - B_10;
/** Internal weights for stage 14, element 11. */
private static final double K14_11 = 793322643029.0 / 96734250000000.0 - B_11;
/** Internal weights for stage 14, element 12. */
private static final double K14_12 = 1458939311.0 / 192780000000.0 - B_12;
/** Internal weights for stage 14, element 13. */
private static final double K14_13 = -4149.0 / 500000.0;
/** Time step for stage 15 (interpolation only). */
private static final double C15 = 1.0 / 5.0;
/** Internal weights for stage 15, element 1. */
private static final double K15_01 = 1595561272731.0 / 50120273500000.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 15, element 6. */
private static final double K15_06 = 975183916491.0 / 34457688031250.0 - B_06;
/** Internal weights for stage 15, element 7. */
private static final double K15_07 = 38492013932672.0 / 718912673015625.0 - B_07;
/** Internal weights for stage 15, element 8. */
private static final double K15_08 = -1114881286517557.0 / 20298710767500000.0 - B_08;
/** Internal weights for stage 15, element 9. */
private static final double K15_09 = 0.0 - B_09;
/** Internal weights for stage 15, element 10. */
private static final double K15_10 = 0.0 - B_10;
/** Internal weights for stage 15, element 11. */
private static final double K15_11 = -2538710946863.0 / 23431227861250000.0 - B_11;
/** Internal weights for stage 15, element 12. */
private static final double K15_12 = 8824659001.0 / 23066716781250.0 - B_12;
/** Internal weights for stage 15, element 13. */
private static final double K15_13 = -11518334563.0 / 33831184612500.0;
/** Internal weights for stage 15, element 14. */
private static final double K15_14 = 1912306948.0 / 13532473845.0;
/** Time step for stage 16 (interpolation only). */
private static final double C16 = 7.0 / 9.0;
/** Internal weights for stage 16, element 1. */
private static final double K16_01 = -13613986967.0 / 31741908048.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 16, element 6. */
private static final double K16_06 = -4755612631.0 / 1012344804.0 - B_06;
/** Internal weights for stage 16, element 7. */
private static final double K16_07 = 42939257944576.0 / 5588559685701.0 - B_07;
/** Internal weights for stage 16, element 8. */
private static final double K16_08 = 77881972900277.0 / 19140370552944.0 - B_08;
/** Internal weights for stage 16, element 9. */
private static final double K16_09 = 22719829234375.0 / 63689648654052.0 - B_09;
/** Internal weights for stage 16, element 10. */
private static final double K16_10 = 0.0 - B_10;
/** Internal weights for stage 16, element 11. */
private static final double K16_11 = 0.0 - B_11;
/** Internal weights for stage 16, element 12. */
private static final double K16_12 = 0.0 - B_12;
/** Internal weights for stage 16, element 13. */
private static final double K16_13 = -1199007803.0 / 857031517296.0;
/** Internal weights for stage 16, element 14. */
private static final double K16_14 = 157882067000.0 / 53564469831.0;
/** Internal weights for stage 16, element 15. */
private static final double K16_15 = -290468882375.0 / 31741908048.0;
/** Interpolation weights.
* (beware that only the non-null values are in the table)
*/
private static final double[][] D = {
{ -17751989329.0 / 2106076560.0, 4272954039.0 / 7539864640.0,
-118476319744.0 / 38604839385.0, 755123450731.0 / 316657731600.0,
3692384461234828125.0 / 1744130441634250432.0, -4612609375.0 / 5293382976.0,
2091772278379.0 / 933644586600.0, 2136624137.0 / 3382989120.0,
-126493.0 / 1421424.0, 98350000.0 / 5419179.0,
-18878125.0 / 2053168.0, -1944542619.0 / 438351368.0},
{ 32941697297.0 / 3159114840.0, 456696183123.0 / 1884966160.0,
19132610714624.0 / 115814518155.0, -177904688592943.0 / 474986597400.0,
-4821139941836765625.0 / 218016305204281304.0, 30702015625.0 / 3970037232.0,
-85916079474274.0 / 2800933759800.0, -5919468007.0 / 634310460.0,
2479159.0 / 157936.0, -18750000.0 / 602131.0,
-19203125.0 / 2053168.0, 15700361463.0 / 438351368.0},
{ 12627015655.0 / 631822968.0, -72955222965.0 / 188496616.0,
-13145744952320.0 / 69488710893.0, 30084216194513.0 / 56998391688.0,
-296858761006640625.0 / 25648977082856624.0, 569140625.0 / 82709109.0,
-18684190637.0 / 18672891732.0, 69644045.0 / 89549712.0,
-11847025.0 / 4264272.0, -978650000.0 / 16257537.0,
519371875.0 / 6159504.0, 5256837225.0 / 438351368.0},
{ -450944925.0 / 17550638.0, -14532122925.0 / 94248308.0,
-595876966400.0 / 2573655959.0, 188748653015.0 / 527762886.0,
2545485458115234375.0 / 27252038150535163.0, -1376953125.0 / 36759604.0,
53995596795.0 / 518691437.0, 210311225.0 / 7047894.0,
-1718875.0 / 39484.0, 58000000.0 / 602131.0,
-1546875.0 / 39484.0, -1262172375.0 / 8429834.0}
};
/** Last evaluations. */
private double[][] yDotKLast;
/** Vectors for interpolation. */
private double[][] v;
/** Initialization indicator for the interpolation vectors. */
private boolean vectorsInitialized;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link #reinitialize} method should be called before using the * {@link #reinitialize} method should be called before using the
@ -295,184 +475,4 @@ class DormandPrince853StepInterpolator
} }
/** Last evaluations. */
private double[][] yDotKLast;
/** Vectors for interpolation. */
private double[][] v;
/** Initialization indicator for the interpolation vectors. */
private boolean vectorsInitialized;
/** Propagation weights, element 1. */
private static final double B_01 = 104257.0 / 1920240.0;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Propagation weights, element 6. */
private static final double B_06 = 3399327.0 / 763840.0;
/** Propagation weights, element 7. */
private static final double B_07 = 66578432.0 / 35198415.0;
/** Propagation weights, element 8. */
private static final double B_08 = -1674902723.0 / 288716400.0;
/** Propagation weights, element 9. */
private static final double B_09 = 54980371265625.0 / 176692375811392.0;
/** Propagation weights, element 10. */
private static final double B_10 = -734375.0 / 4826304.0;
/** Propagation weights, element 11. */
private static final double B_11 = 171414593.0 / 851261400.0;
/** Propagation weights, element 12. */
private static final double B_12 = 137909.0 / 3084480.0;
/** Time step for stage 14 (interpolation only). */
private static final double C14 = 1.0 / 10.0;
/** Internal weights for stage 14, element 1. */
private static final double K14_01 = 13481885573.0 / 240030000000.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 14, element 6. */
private static final double K14_06 = 0.0 - B_06;
/** Internal weights for stage 14, element 7. */
private static final double K14_07 = 139418837528.0 / 549975234375.0 - B_07;
/** Internal weights for stage 14, element 8. */
private static final double K14_08 = -11108320068443.0 / 45111937500000.0 - B_08;
/** Internal weights for stage 14, element 9. */
private static final double K14_09 = -1769651421925959.0 / 14249385146080000.0 - B_09;
/** Internal weights for stage 14, element 10. */
private static final double K14_10 = 57799439.0 / 377055000.0 - B_10;
/** Internal weights for stage 14, element 11. */
private static final double K14_11 = 793322643029.0 / 96734250000000.0 - B_11;
/** Internal weights for stage 14, element 12. */
private static final double K14_12 = 1458939311.0 / 192780000000.0 - B_12;
/** Internal weights for stage 14, element 13. */
private static final double K14_13 = -4149.0 / 500000.0;
/** Time step for stage 15 (interpolation only). */
private static final double C15 = 1.0 / 5.0;
/** Internal weights for stage 15, element 1. */
private static final double K15_01 = 1595561272731.0 / 50120273500000.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 15, element 6. */
private static final double K15_06 = 975183916491.0 / 34457688031250.0 - B_06;
/** Internal weights for stage 15, element 7. */
private static final double K15_07 = 38492013932672.0 / 718912673015625.0 - B_07;
/** Internal weights for stage 15, element 8. */
private static final double K15_08 = -1114881286517557.0 / 20298710767500000.0 - B_08;
/** Internal weights for stage 15, element 9. */
private static final double K15_09 = 0.0 - B_09;
/** Internal weights for stage 15, element 10. */
private static final double K15_10 = 0.0 - B_10;
/** Internal weights for stage 15, element 11. */
private static final double K15_11 = -2538710946863.0 / 23431227861250000.0 - B_11;
/** Internal weights for stage 15, element 12. */
private static final double K15_12 = 8824659001.0 / 23066716781250.0 - B_12;
/** Internal weights for stage 15, element 13. */
private static final double K15_13 = -11518334563.0 / 33831184612500.0;
/** Internal weights for stage 15, element 14. */
private static final double K15_14 = 1912306948.0 / 13532473845.0;
/** Time step for stage 16 (interpolation only). */
private static final double C16 = 7.0 / 9.0;
/** Internal weights for stage 16, element 1. */
private static final double K16_01 = -13613986967.0 / 31741908048.0 - B_01;
// elements 2 to 5 are zero, so they are neither stored nor used
/** Internal weights for stage 16, element 6. */
private static final double K16_06 = -4755612631.0 / 1012344804.0 - B_06;
/** Internal weights for stage 16, element 7. */
private static final double K16_07 = 42939257944576.0 / 5588559685701.0 - B_07;
/** Internal weights for stage 16, element 8. */
private static final double K16_08 = 77881972900277.0 / 19140370552944.0 - B_08;
/** Internal weights for stage 16, element 9. */
private static final double K16_09 = 22719829234375.0 / 63689648654052.0 - B_09;
/** Internal weights for stage 16, element 10. */
private static final double K16_10 = 0.0 - B_10;
/** Internal weights for stage 16, element 11. */
private static final double K16_11 = 0.0 - B_11;
/** Internal weights for stage 16, element 12. */
private static final double K16_12 = 0.0 - B_12;
/** Internal weights for stage 16, element 13. */
private static final double K16_13 = -1199007803.0 / 857031517296.0;
/** Internal weights for stage 16, element 14. */
private static final double K16_14 = 157882067000.0 / 53564469831.0;
/** Internal weights for stage 16, element 15. */
private static final double K16_15 = -290468882375.0 / 31741908048.0;
/** Interpolation weights.
* (beware that only the non-null values are in the table)
*/
private static final double[][] D = {
{ -17751989329.0 / 2106076560.0, 4272954039.0 / 7539864640.0,
-118476319744.0 / 38604839385.0, 755123450731.0 / 316657731600.0,
3692384461234828125.0 / 1744130441634250432.0, -4612609375.0 / 5293382976.0,
2091772278379.0 / 933644586600.0, 2136624137.0 / 3382989120.0,
-126493.0 / 1421424.0, 98350000.0 / 5419179.0,
-18878125.0 / 2053168.0, -1944542619.0 / 438351368.0},
{ 32941697297.0 / 3159114840.0, 456696183123.0 / 1884966160.0,
19132610714624.0 / 115814518155.0, -177904688592943.0 / 474986597400.0,
-4821139941836765625.0 / 218016305204281304.0, 30702015625.0 / 3970037232.0,
-85916079474274.0 / 2800933759800.0, -5919468007.0 / 634310460.0,
2479159.0 / 157936.0, -18750000.0 / 602131.0,
-19203125.0 / 2053168.0, 15700361463.0 / 438351368.0},
{ 12627015655.0 / 631822968.0, -72955222965.0 / 188496616.0,
-13145744952320.0 / 69488710893.0, 30084216194513.0 / 56998391688.0,
-296858761006640625.0 / 25648977082856624.0, 569140625.0 / 82709109.0,
-18684190637.0 / 18672891732.0, 69644045.0 / 89549712.0,
-11847025.0 / 4264272.0, -978650000.0 / 16257537.0,
519371875.0 / 6159504.0, 5256837225.0 / 438351368.0},
{ -450944925.0 / 17550638.0, -14532122925.0 / 94248308.0,
-595876966400.0 / 2573655959.0, 188748653015.0 / 527762886.0,
2545485458115234375.0 / 27252038150535163.0, -1376953125.0 / 36759604.0,
53995596795.0 / 518691437.0, 210311225.0 / 7047894.0,
-1718875.0 / 39484.0, 58000000.0 / 602131.0,
-1546875.0 / 39484.0, -1262172375.0 / 8429834.0}
};
/** Serializable version identifier */
private static final long serialVersionUID = 7152276390558450974L;
} }

View File

@ -67,6 +67,33 @@ import org.apache.commons.math.ode.sampling.StepHandler;
public abstract class EmbeddedRungeKuttaIntegrator public abstract class EmbeddedRungeKuttaIntegrator
extends AdaptiveStepsizeIntegrator { extends AdaptiveStepsizeIntegrator {
/** Indicator for <i>fsal</i> methods. */
private final boolean fsal;
/** Time steps from Butcher array (without the first zero). */
private final double[] c;
/** Internal weights from Butcher array (without the first empty row). */
private final double[][] a;
/** External weights for the high order method from Butcher array. */
private final double[] b;
/** Prototype of the step interpolator. */
private final RungeKuttaStepInterpolator prototype;
/** Stepsize control exponent. */
private final double exp;
/** Safety factor for stepsize control. */
private double safety;
/** Minimal reduction factor for stepsize control. */
private double minReduction;
/** Maximal growth factor for stepsize control. */
private double maxGrowth;
/** Build a Runge-Kutta integrator with the given Butcher array. /** Build a Runge-Kutta integrator with the given Butcher array.
* @param name name of the method * @param name name of the method
* @param fsal indicate that the method is an <i>fsal</i> * @param fsal indicate that the method is an <i>fsal</i>
@ -372,31 +399,4 @@ public abstract class EmbeddedRungeKuttaIntegrator
double[] y0, double[] y1, double[] y0, double[] y1,
double h); double h);
/** Indicator for <i>fsal</i> methods. */
private boolean fsal;
/** Time steps from Butcher array (without the first zero). */
private double[] c;
/** Internal weights from Butcher array (without the first empty row). */
private double[][] a;
/** External weights for the high order method from Butcher array. */
private double[] b;
/** Prototype of the step interpolator. */
private RungeKuttaStepInterpolator prototype;
/** Stepsize control exponent. */
private double exp;
/** Safety factor for stepsize control. */
private double safety;
/** Minimal reduction factor for stepsize control. */
private double minReduction;
/** Maximal growth factor for stepsize control. */
private double maxGrowth;
} }

View File

@ -47,6 +47,15 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class GillStepInterpolator class GillStepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** First Gill coefficient. */
private static final double TWO_MINUS_SQRT_2 = 2 - Math.sqrt(2.0);
/** Second Gill coefficient. */
private static final double TWO_PLUS_SQRT_2 = 2 + Math.sqrt(2.0);
/** Serializable version identifier */
private static final long serialVersionUID = -107804074496313322L;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link * {@link
@ -112,13 +121,4 @@ class GillStepInterpolator
} }
/** First Gill coefficient. */
private static final double TWO_MINUS_SQRT_2 = 2 - Math.sqrt(2.0);
/** Second Gill coefficient. */
private static final double TWO_PLUS_SQRT_2 = 2 + Math.sqrt(2.0);
/** Serializable version identifier */
private static final long serialVersionUID = -107804074496313322L;
} }

View File

@ -93,8 +93,65 @@ import org.apache.commons.math.ode.sampling.StepHandler;
public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
/** Integrator method name. */ /** Integrator method name. */
private static final String METHOD_NAME = "Gragg-Bulirsch-Stoer"; private static final String METHOD_NAME = "Gragg-Bulirsch-Stoer";
/** maximal order. */
private int maxOrder;
/** step size sequence. */
private int[] sequence;
/** overall cost of applying step reduction up to iteration k+1, in number of calls. */
private int[] costPerStep;
/** cost per unit step. */
private double[] costPerTimeUnit;
/** optimal steps for each order. */
private double[] optimalStep;
/** extrapolation coefficients. */
private double[][] coeff;
/** stability check enabling parameter. */
private boolean performTest;
/** maximal number of checks for each iteration. */
private int maxChecks;
/** maximal number of iterations for which checks are performed. */
private int maxIter;
/** stepsize reduction factor in case of stability check failure. */
private double stabilityReduction;
/** first stepsize control factor. */
private double stepControl1;
/** second stepsize control factor. */
private double stepControl2;
/** third stepsize control factor. */
private double stepControl3;
/** fourth stepsize control factor. */
private double stepControl4;
/** first order control factor. */
private double orderControl1;
/** second order control factor. */
private double orderControl2;
/** dense outpute required. */
private boolean denseOutput;
/** use interpolation error in stepsize control. */
private boolean useInterpolationError;
/** interpolation order control parameter. */
private int mudif;
/** Simple constructor. /** Simple constructor.
* Build a Gragg-Bulirsch-Stoer integrator with the given step * Build a Gragg-Bulirsch-Stoer integrator with the given step
@ -941,63 +998,4 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
} }
/** maximal order. */
private int maxOrder;
/** step size sequence. */
private int[] sequence;
/** overall cost of applying step reduction up to iteration k+1,
* in number of calls.
*/
private int[] costPerStep;
/** cost per unit step. */
private double[] costPerTimeUnit;
/** optimal steps for each order. */
private double[] optimalStep;
/** extrapolation coefficients. */
private double[][] coeff;
/** stability check enabling parameter. */
private boolean performTest;
/** maximal number of checks for each iteration. */
private int maxChecks;
/** maximal number of iterations for which checks are performed. */
private int maxIter;
/** stepsize reduction factor in case of stability check failure. */
private double stabilityReduction;
/** first stepsize control factor. */
private double stepControl1;
/** second stepsize control factor. */
private double stepControl2;
/** third stepsize control factor. */
private double stepControl3;
/** fourth stepsize control factor. */
private double stepControl4;
/** first order control factor. */
private double orderControl1;
/** second order control factor. */
private double orderControl2;
/** dense outpute required. */
private boolean denseOutput;
/** use interpolation error in stepsize control. */
private boolean useInterpolationError;
/** interpolation order control parameter. */
private int mudif;
} }

View File

@ -77,75 +77,31 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class GraggBulirschStoerStepInterpolator class GraggBulirschStoerStepInterpolator
extends AbstractStepInterpolator { extends AbstractStepInterpolator {
/** Slope at the beginning of the step. */ /** Serializable version identifier. */
private double[] y0Dot; private static final long serialVersionUID = 7320613236731409847L;
/** State at the end of the step. */ /** Slope at the beginning of the step. */
private double[] y1; private double[] y0Dot;
/** Slope at the end of the step. */ /** State at the end of the step. */
private double[] y1Dot; private double[] y1;
/** Derivatives at the middle of the step. /** Slope at the end of the step. */
* element 0 is state at midpoint, element 1 is first derivative ... private double[] y1Dot;
*/
private double[][] yMidDots;
/** Interpolation polynoms. */ /** Derivatives at the middle of the step.
private double[][] polynoms; * element 0 is state at midpoint, element 1 is first derivative ...
*/
private double[][] yMidDots;
/** Error coefficients for the interpolation. */ /** Interpolation polynoms. */
private double[] errfac; private double[][] polynoms;
/** Degree of the interpolation polynoms. */ /** Error coefficients for the interpolation. */
private int currentDegree; private double[] errfac;
/** Reallocate the internal tables. /** Degree of the interpolation polynoms. */
* Reallocate the internal tables in order to be able to handle private int currentDegree;
* interpolation polynoms up to the given degree
* @param maxDegree maximal degree to handle
*/
private void resetTables(final int maxDegree) {
if (maxDegree < 0) {
polynoms = null;
errfac = null;
currentDegree = -1;
} else {
final double[][] newPols = new double[maxDegree + 1][];
if (polynoms != null) {
System.arraycopy(polynoms, 0, newPols, 0, polynoms.length);
for (int i = polynoms.length; i < newPols.length; ++i) {
newPols[i] = new double[currentState.length];
}
} else {
for (int i = 0; i < newPols.length; ++i) {
newPols[i] = new double[currentState.length];
}
}
polynoms = newPols;
// initialize the error factors array for interpolation
if (maxDegree <= 4) {
errfac = null;
} else {
errfac = new double[maxDegree - 4];
for (int i = 0; i < errfac.length; ++i) {
final int ip5 = i + 5;
errfac[i] = 1.0 / (ip5 * ip5);
final double e = 0.5 * Math.sqrt (((double) (i + 1)) / ip5);
for (int j = 0; j <= i; ++j) {
errfac[i] *= e / (j + 1);
}
}
}
currentDegree = 0;
}
}
/** Simple constructor. /** Simple constructor.
* This constructor should not be used directly, it is only intended * This constructor should not be used directly, it is only intended
@ -221,6 +177,53 @@ class GraggBulirschStoerStepInterpolator
} }
/** Reallocate the internal tables.
* Reallocate the internal tables in order to be able to handle
* interpolation polynoms up to the given degree
* @param maxDegree maximal degree to handle
*/
private void resetTables(final int maxDegree) {
if (maxDegree < 0) {
polynoms = null;
errfac = null;
currentDegree = -1;
} else {
final double[][] newPols = new double[maxDegree + 1][];
if (polynoms != null) {
System.arraycopy(polynoms, 0, newPols, 0, polynoms.length);
for (int i = polynoms.length; i < newPols.length; ++i) {
newPols[i] = new double[currentState.length];
}
} else {
for (int i = 0; i < newPols.length; ++i) {
newPols[i] = new double[currentState.length];
}
}
polynoms = newPols;
// initialize the error factors array for interpolation
if (maxDegree <= 4) {
errfac = null;
} else {
errfac = new double[maxDegree - 4];
for (int i = 0; i < errfac.length; ++i) {
final int ip5 = i + 5;
errfac[i] = 1.0 / (ip5 * ip5);
final double e = 0.5 * Math.sqrt (((double) (i + 1)) / ip5);
for (int j = 0; j <= i; ++j) {
errfac[i] *= e / (j + 1);
}
}
}
currentDegree = 0;
}
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected StepInterpolator doCopy() { protected StepInterpolator doCopy() {
@ -396,7 +399,4 @@ class GraggBulirschStoerStepInterpolator
} }
/** Serializable version identifier */
private static final long serialVersionUID = 7320613236731409847L;
} }

View File

@ -33,6 +33,9 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class HighamHall54StepInterpolator class HighamHall54StepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = -3583240427587318654L;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link * {@link
@ -97,7 +100,4 @@ class HighamHall54StepInterpolator
} }
/** Serializable version identifier */
private static final long serialVersionUID = -3583240427587318654L;
} }

View File

@ -44,6 +44,9 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class MidpointStepInterpolator class MidpointStepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = -865524111506042509L;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link * {@link
@ -94,7 +97,4 @@ class MidpointStepInterpolator
} }
/** Serializable version identifier */
private static final long serialVersionUID = -865524111506042509L;
} }

View File

@ -54,6 +54,21 @@ import org.apache.commons.math.ode.sampling.StepHandler;
public abstract class RungeKuttaIntegrator extends AbstractIntegrator { public abstract class RungeKuttaIntegrator extends AbstractIntegrator {
/** Time steps from Butcher array (without the first zero). */
private final double[] c;
/** Internal weights from Butcher array (without the first empty row). */
private final double[][] a;
/** External weights for the high order method from Butcher array. */
private final double[] b;
/** Prototype of the step interpolator. */
private final RungeKuttaStepInterpolator prototype;
/** Integration step. */
private final double step;
/** Simple constructor. /** Simple constructor.
* Build a Runge-Kutta integrator with the given * Build a Runge-Kutta integrator with the given
* step. The default step handler does nothing. * step. The default step handler does nothing.
@ -200,19 +215,4 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator {
} }
/** Time steps from Butcher array (without the first zero). */
private double[] c;
/** Internal weights from Butcher array (without the first empty row). */
private double[][] a;
/** External weights for the high order method from Butcher array. */
private double[] b;
/** Prototype of the step interpolator. */
private RungeKuttaStepInterpolator prototype;
/** Integration step. */
private double step;
} }

View File

@ -37,6 +37,12 @@ import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
abstract class RungeKuttaStepInterpolator abstract class RungeKuttaStepInterpolator
extends AbstractStepInterpolator { extends AbstractStepInterpolator {
/** Slopes at the intermediate points */
protected double[][] yDotK;
/** Reference to the integrator. */
protected AbstractIntegrator integrator;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link #reinitialize} method should be called before using the * {@link #reinitialize} method should be called before using the
@ -174,10 +180,4 @@ abstract class RungeKuttaStepInterpolator
} }
/** Slopes at the intermediate points */
protected double[][] yDotK;
/** Reference to the integrator. */
protected AbstractIntegrator integrator;
} }

View File

@ -49,6 +49,9 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
class ThreeEighthesStepInterpolator class ThreeEighthesStepInterpolator
extends RungeKuttaStepInterpolator { extends RungeKuttaStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = -3345024435978721931L;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link * {@link
@ -110,7 +113,4 @@ class ThreeEighthesStepInterpolator
} }
/** Serializable version identifier */
private static final long serialVersionUID = -3345024435978721931L;
} }

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.sampling; package org.apache.commons.math.ode.sampling;
/** /**
* This class is a step handler that does nothing. * This class is a step handler that does nothing.
@ -37,51 +36,66 @@ package org.apache.commons.math.ode.sampling;
public class DummyStepHandler implements StepHandler { public class DummyStepHandler implements StepHandler {
/** Private constructor. /** Private constructor.
* The constructor is private to prevent users from creating * The constructor is private to prevent users from creating
* instances (Singleton design-pattern). * instances (Singleton design-pattern).
*/ */
private DummyStepHandler() { private DummyStepHandler() {
} }
/** Get the only instance. /** Get the only instance.
* @return the only instance * @return the only instance
*/ */
public static DummyStepHandler getInstance() { public static DummyStepHandler getInstance() {
return INSTANCE; return LazyHolder.INSTANCE;
} }
/** Determines whether this handler needs dense output. /** Determines whether this handler needs dense output.
* Since this handler does nothing, it does not require dense output. * Since this handler does nothing, it does not require dense output.
* @return always false * @return always false
*/ */
public boolean requiresDenseOutput() { public boolean requiresDenseOutput() {
return false; return false;
} }
/** Reset the step handler. /** Reset the step handler.
* Initialize the internal data as required before the first step is * Initialize the internal data as required before the first step is
* handled. * handled.
*/ */
public void reset() { public void reset() {
} }
/** /**
* Handle the last accepted step. * Handle the last accepted step.
* This method does nothing in this class. * This method does nothing in this class.
* @param interpolator interpolator for the last accepted step. For * @param interpolator interpolator for the last accepted step. For
* efficiency purposes, the various integrators reuse the same * efficiency purposes, the various integrators reuse the same
* object on each call, so if the instance wants to keep it across * object on each call, so if the instance wants to keep it across
* all calls (for example to provide at the end of the integration a * all calls (for example to provide at the end of the integration a
* continuous model valid throughout the integration range), it * continuous model valid throughout the integration range), it
* should build a local copy using the clone method and store this * should build a local copy using the clone method and store this
* copy. * copy.
* @param isLast true if the step is the last one * @param isLast true if the step is the last one
*/ */
public void handleStep(final StepInterpolator interpolator, final boolean isLast) { public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
} }
/** The only instance. */ // CHECKSTYLE: stop HideUtilityClassConstructor
private static final DummyStepHandler INSTANCE = new DummyStepHandler(); /** Holder for the instance.
* <p>We use here the Initialization On Demand Holder Idiom.</p>
*/
private static class LazyHolder {
/** Cached field instance. */
private static final DummyStepHandler INSTANCE = new DummyStepHandler();
}
// CHECKSTYLE: resume HideUtilityClassConstructor
/** Handle deserialization of the singleton.
* @return the singleton instance
*/
private Object readResolve() {
// return the singleton instance
return LazyHolder.INSTANCE;
}
} }

View File

@ -40,6 +40,9 @@ import org.apache.commons.math.ode.DerivativeException;
public class DummyStepInterpolator public class DummyStepInterpolator
extends AbstractStepInterpolator { extends AbstractStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = 1708010296707839488L;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* <code>AbstractStepInterpolator.reinitialize</code> protected method * <code>AbstractStepInterpolator.reinitialize</code> protected method
@ -123,7 +126,4 @@ public class DummyStepInterpolator
} }
/** Serializable version identifier */
private static final long serialVersionUID = 1708010296707839488L;
} }

View File

@ -42,6 +42,9 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -7179861704951334960L; private static final long serialVersionUID = -7179861704951334960L;
/** State variation. */
protected double[] stateVariation;
/** Step size used in the first scaled derivative and Nordsieck vector. */ /** Step size used in the first scaled derivative and Nordsieck vector. */
private double scalingH; private double scalingH;
@ -59,9 +62,6 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
/** Nordsieck vector. */ /** Nordsieck vector. */
private Array2DRowRealMatrix nordsieck; private Array2DRowRealMatrix nordsieck;
/** State variation. */
protected double[] stateVariation;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
* {@link AbstractStepInterpolator#reinitialize} method should be called * {@link AbstractStepInterpolator#reinitialize} method should be called

View File

@ -45,21 +45,6 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
/** Default maximal number of iterations allowed. */ /** Default maximal number of iterations allowed. */
public static final int DEFAULT_MAX_ITERATIONS = 100; public static final int DEFAULT_MAX_ITERATIONS = 100;
/** Maximal number of iterations allowed. */
private int maxIterations;
/** Number of iterations already performed. */
private int iterations;
/** Maximal number of evaluations allowed. */
private int maxEvaluations;
/** Number of evaluations already performed. */
private int objectiveEvaluations;
/** Number of jacobian evaluations. */
private int jacobianEvaluations;
/** Convergence checker. */ /** Convergence checker. */
protected VectorialConvergenceChecker checker; protected VectorialConvergenceChecker checker;
@ -78,12 +63,6 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
/** Number of rows of the jacobian matrix. */ /** Number of rows of the jacobian matrix. */
protected int rows; protected int rows;
/** Objective function. */
private DifferentiableMultivariateVectorialFunction function;
/** Objective function derivatives. */
private MultivariateMatrixFunction jF;
/** Target value for the objective functions at optimum. */ /** Target value for the objective functions at optimum. */
protected double[] targetValues; protected double[] targetValues;
@ -102,6 +81,27 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
/** Cost value (square root of the sum of the residuals). */ /** Cost value (square root of the sum of the residuals). */
protected double cost; protected double cost;
/** Maximal number of iterations allowed. */
private int maxIterations;
/** Number of iterations already performed. */
private int iterations;
/** Maximal number of evaluations allowed. */
private int maxEvaluations;
/** Number of evaluations already performed. */
private int objectiveEvaluations;
/** Number of jacobian evaluations. */
private int jacobianEvaluations;
/** Objective function. */
private DifferentiableMultivariateVectorialFunction function;
/** Objective function derivatives. */
private MultivariateMatrixFunction jF;
/** Simple constructor with default settings. /** Simple constructor with default settings.
* <p>The convergence check is set to a {@link SimpleVectorialValueChecker} * <p>The convergence check is set to a {@link SimpleVectorialValueChecker}
* and the maximal number of evaluation is set to its default value.</p> * and the maximal number of evaluation is set to its default value.</p>

View File

@ -42,6 +42,15 @@ public abstract class AbstractScalarDifferentiableOptimizer
/** Default maximal number of iterations allowed. */ /** Default maximal number of iterations allowed. */
public static final int DEFAULT_MAX_ITERATIONS = 100; public static final int DEFAULT_MAX_ITERATIONS = 100;
/** Convergence checker. */
protected RealConvergenceChecker checker;
/** Type of optimization. */
protected GoalType goal;
/** Current point set. */
protected double[] point;
/** Maximal number of iterations allowed. */ /** Maximal number of iterations allowed. */
private int maxIterations; private int maxIterations;
@ -57,21 +66,12 @@ public abstract class AbstractScalarDifferentiableOptimizer
/** Number of gradient evaluations. */ /** Number of gradient evaluations. */
private int gradientEvaluations; private int gradientEvaluations;
/** Convergence checker. */
protected RealConvergenceChecker checker;
/** Objective function. */ /** Objective function. */
private DifferentiableMultivariateRealFunction function; private DifferentiableMultivariateRealFunction function;
/** Objective function gradient. */ /** Objective function gradient. */
private MultivariateVectorialFunction gradient; private MultivariateVectorialFunction gradient;
/** Type of optimization. */
protected GoalType goal;
/** Current point set. */
protected double[] point;
/** Simple constructor with default settings. /** Simple constructor with default settings.
* <p>The convergence check is set to a {@link SimpleScalarValueChecker} * <p>The convergence check is set to a {@link SimpleScalarValueChecker}
* and the maximal number of evaluation is set to its default value.</p> * and the maximal number of evaluation is set to its default value.</p>

View File

@ -37,12 +37,6 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
/** Default maximal number of iterations allowed. */ /** Default maximal number of iterations allowed. */
public static final int DEFAULT_MAX_ITERATIONS = 100; public static final int DEFAULT_MAX_ITERATIONS = 100;
/** Maximal number of iterations allowed. */
private int maxIterations;
/** Number of iterations already performed. */
private int iterations;
/** Linear objective function. */ /** Linear objective function. */
protected LinearObjectiveFunction function; protected LinearObjectiveFunction function;
@ -55,6 +49,12 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
/** Whether to restrict the variables to non-negative values. */ /** Whether to restrict the variables to non-negative values. */
protected boolean nonNegative; protected boolean nonNegative;
/** Maximal number of iterations allowed. */
private int maxIterations;
/** Number of iterations already performed. */
private int iterations;
/** Simple constructor with default settings. /** Simple constructor with default settings.
* <p>The maximal number of evaluation is set to its default value.</p> * <p>The maximal number of evaluation is set to its default value.</p>
*/ */

View File

@ -75,19 +75,19 @@ class SimplexTableau implements Serializable {
private final boolean restrictToNonNegative; private final boolean restrictToNonNegative;
/** Simple tableau. */ /** Simple tableau. */
protected transient RealMatrix tableau; private transient RealMatrix tableau;
/** Number of decision variables. */ /** Number of decision variables. */
protected final int numDecisionVariables; private final int numDecisionVariables;
/** Number of slack variables. */ /** Number of slack variables. */
protected final int numSlackVariables; private final int numSlackVariables;
/** Number of artificial variables. */ /** Number of artificial variables. */
protected int numArtificialVariables; private int numArtificialVariables;
/** Amount of error to accept in floating point comparisons. */ /** Amount of error to accept in floating point comparisons. */
protected final double epsilon; private final double epsilon;
/** /**
* Build a tableau for a linear problem. * Build a tableau for a linear problem.

View File

@ -62,6 +62,21 @@ import org.apache.commons.math.linear.RealMatrix;
public class CorrelatedRandomVectorGenerator public class CorrelatedRandomVectorGenerator
implements RandomVectorGenerator { implements RandomVectorGenerator {
/** Mean vector. */
private final double[] mean;
/** Underlying generator. */
private final NormalizedRandomGenerator generator;
/** Storage for the normalized vector. */
private final double[] normalized;
/** Permutated Cholesky root of the covariance matrix. */
private RealMatrix root;
/** Rank of the covariance matrix. */
private int rank;
/** Simple constructor. /** Simple constructor.
* <p>Build a correlated random vector generator from its mean * <p>Build a correlated random vector generator from its mean
* vector and covariance matrix.</p> * vector and covariance matrix.</p>
@ -285,19 +300,4 @@ public class CorrelatedRandomVectorGenerator
} }
/** Mean vector. */
private double[] mean;
/** Permutated Cholesky root of the covariance matrix. */
private RealMatrix root;
/** Rank of the covariance matrix. */
private int rank;
/** Underlying generator. */
private NormalizedRandomGenerator generator;
/** Storage for the normalized vector. */
private double[] normalized;
} }

View File

@ -27,10 +27,13 @@ package org.apache.commons.math.random;
public class GaussianRandomGenerator implements NormalizedRandomGenerator { public class GaussianRandomGenerator implements NormalizedRandomGenerator {
/** Underlying generator. */
private final RandomGenerator generator;
/** Create a new generator. /** Create a new generator.
* @param generator underlying random generator to use * @param generator underlying random generator to use
*/ */
public GaussianRandomGenerator(RandomGenerator generator) { public GaussianRandomGenerator(final RandomGenerator generator) {
this.generator = generator; this.generator = generator;
} }
@ -41,7 +44,4 @@ public class GaussianRandomGenerator implements NormalizedRandomGenerator {
return generator.nextGaussian(); return generator.nextGaussian();
} }
/** Underlying generator. */
private RandomGenerator generator;
} }

View File

@ -33,6 +33,15 @@ import org.apache.commons.math.MathRuntimeException;
public class UncorrelatedRandomVectorGenerator public class UncorrelatedRandomVectorGenerator
implements RandomVectorGenerator { implements RandomVectorGenerator {
/** Underlying scalar generator. */
private final NormalizedRandomGenerator generator;
/** Mean vector. */
private final double[] mean;
/** Standard deviation vector. */
private final double[] standardDeviation;
/** Simple constructor. /** Simple constructor.
* <p>Build an uncorrelated random vector generator from * <p>Build an uncorrelated random vector generator from
* its mean and standard deviation vectors.</p> * its mean and standard deviation vectors.</p>
@ -83,13 +92,4 @@ public class UncorrelatedRandomVectorGenerator
} }
/** Mean vector. */
private double[] mean;
/** Standard deviation vector. */
private double[] standardDeviation;
/** Underlying scalar generator. */
private NormalizedRandomGenerator generator;
} }

View File

@ -34,6 +34,12 @@ public class UniformRandomGenerator implements NormalizedRandomGenerator {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = 1569292426375546027L; private static final long serialVersionUID = 1569292426375546027L;
/** Square root of three. */
private static final double SQRT3 = Math.sqrt(3.0);
/** Underlying generator. */
private final RandomGenerator generator;
/** Create a new generator. /** Create a new generator.
* @param generator underlying random generator to use * @param generator underlying random generator to use
*/ */
@ -50,10 +56,4 @@ public class UniformRandomGenerator implements NormalizedRandomGenerator {
return SQRT3 * (2 * generator.nextDouble() - 1.0); return SQRT3 * (2 * generator.nextDouble() - 1.0);
} }
/** Underlying generator. */
private RandomGenerator generator;
/** Square root of three. */
private static final double SQRT3 = Math.sqrt(3.0);
} }

View File

@ -46,51 +46,63 @@ import org.apache.commons.math.MathRuntimeException;
* *
*/ */
public class ValueServer { public class ValueServer {
/** mode determines how values are generated */
private int mode = 5;
/** URI to raw data values */ /** Use empirical distribution. */
private URL valuesFileURL = null;
/** Mean for use with non-data-driven modes */
private double mu = 0.0;
/** Standard deviation for use with GAUSSIAN_MODE */
private double sigma = 0.0;
/** Empirical probability distribution for use with DIGEST_MODE */
private EmpiricalDistribution empiricalDistribution = null;
/** file pointer for REPLAY_MODE */
private BufferedReader filePointer = null;
/** RandomDataImpl to use for random data generation */
private RandomData randomData = new RandomDataImpl();
// Data generation modes ======================================
/** Use empirical distribution */
public static final int DIGEST_MODE = 0; public static final int DIGEST_MODE = 0;
/** Replay data from valuesFilePath */ /** Replay data from valuesFilePath. */
public static final int REPLAY_MODE = 1; public static final int REPLAY_MODE = 1;
/** Uniform random deviates with mean = mu */ /** Uniform random deviates with mean = &mu;. */
public static final int UNIFORM_MODE = 2; public static final int UNIFORM_MODE = 2;
/** Exponential random deviates with mean = mu */ /** Exponential random deviates with mean = &mu;. */
public static final int EXPONENTIAL_MODE = 3; public static final int EXPONENTIAL_MODE = 3;
/** Gaussian random deviates with mean = mu, std dev = sigma */ /** Gaussian random deviates with mean = &mu;, std dev = &sigma;. */
public static final int GAUSSIAN_MODE = 4; public static final int GAUSSIAN_MODE = 4;
/** Always return mu */ /** Always return mu */
public static final int CONSTANT_MODE = 5; public static final int CONSTANT_MODE = 5;
/** mode determines how values are generated. */
private int mode = 5;
/** URI to raw data values. */
private URL valuesFileURL = null;
/** Mean for use with non-data-driven modes. */
private double mu = 0.0;
/** Standard deviation for use with GAUSSIAN_MODE. */
private double sigma = 0.0;
/** Empirical probability distribution for use with DIGEST_MODE. */
private EmpiricalDistribution empiricalDistribution = null;
/** File pointer for REPLAY_MODE. */
private BufferedReader filePointer = null;
/** RandomDataImpl to use for random data generation. */
private RandomData randomData = new RandomDataImpl();
// Data generation modes ======================================
/** Creates new ValueServer */ /** Creates new ValueServer */
public ValueServer() { public ValueServer() {
} }
/**
* Construct a ValueServer instance using a RandomData as its source
* of random data.
*
* @param randomData the RandomData instance used to source random data
* @since 1.1
*/
public ValueServer(RandomData randomData) {
this.randomData = randomData;
}
/** /**
* Returns the next generated value, generated according * Returns the next generated value, generated according
* to the mode value (see MODE constants). * to the mode value (see MODE constants).
@ -369,15 +381,4 @@ public class ValueServer {
return randomData.nextGaussian(mu, sigma); return randomData.nextGaussian(mu, sigma);
} }
/**
* Construct a ValueServer instance using a RandomData as its source
* of random data.
*
* @param randomData the RandomData instance used to source random data
* @since 1.1
*/
public ValueServer(RandomData randomData) {
super();
this.randomData = randomData;
}
} }

View File

@ -60,6 +60,12 @@ public class Gamma {
/** Avoid repeated computation of log of 2 PI in logGamma */ /** Avoid repeated computation of log of 2 PI in logGamma */
private static final double HALF_LOG_2_PI = 0.5 * Math.log(2.0 * Math.PI); private static final double HALF_LOG_2_PI = 0.5 * Math.log(2.0 * Math.PI);
// limits for switching algorithm in digamma
/** C limit. */
private static final double C_LIMIT = 49;
/** S limit. */
private static final double S_LIMIT = 1e-5;
/** /**
* Default constructor. Prohibit instantiation. * Default constructor. Prohibit instantiation.
@ -262,12 +268,6 @@ public class Gamma {
} }
// limits for switching algorithm in digamma
/** C limit */
private static final double C_LIMIT = 49;
/** S limit */
private static final double S_LIMIT = 1e-5;
/** /**
* <p>Computes the digamma function of x.</p> * <p>Computes the digamma function of x.</p>
* *

View File

@ -55,6 +55,13 @@ import org.apache.commons.math.util.ResizableDoubleArray;
*/ */
public class DescriptiveStatistics implements StatisticalSummary, Serializable { public class DescriptiveStatistics implements StatisticalSummary, Serializable {
/**
* Represents an infinite window size. When the {@link #getWindowSize()}
* returns this value, there is no limit to the number of data values
* that can be stored in the dataset.
*/
public static final int INFINITE_WINDOW = -1;
/** Serialization UID */ /** Serialization UID */
private static final long serialVersionUID = 4133067267405273064L; private static final long serialVersionUID = 4133067267405273064L;
@ -121,13 +128,6 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
copy(original, this); copy(original, this);
} }
/**
* Represents an infinite window size. When the {@link #getWindowSize()}
* returns this value, there is no limit to the number of data values
* that can be stored in the dataset.
*/
public static final int INFINITE_WINDOW = -1;
/** /**
* Adds the value to the dataset. If the dataset is at the maximum size * Adds the value to the dataset. If the dataset is at the maximum size
* (i.e., the number of stored elements equals the currently configured * (i.e., the number of stored elements equals the currently configured

View File

@ -71,6 +71,36 @@ public class MultivariateSummaryStatistics
/** Serialization UID */ /** Serialization UID */
private static final long serialVersionUID = 2271900808994826718L; private static final long serialVersionUID = 2271900808994826718L;
/** Dimension of the data. */
private int k;
/** Count of values that have been added */
private long n = 0;
/** Sum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumImpl;
/** Sum of squares statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumSqImpl;
/** Minimum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] minImpl;
/** Maximum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] maxImpl;
/** Sum of log statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumLogImpl;
/** Geometric mean statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] geoMeanImpl;
/** Mean statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] meanImpl;
/** Covariance statistic implementation - cannot be reset. */
private VectorialCovariance covarianceImpl;
/** /**
* Construct a MultivariateSummaryStatistics instance * Construct a MultivariateSummaryStatistics instance
* @param k dimension of the data * @param k dimension of the data
@ -104,36 +134,6 @@ public class MultivariateSummaryStatistics
} }
/** Dimension of the data. */
private int k;
/** Count of values that have been added */
private long n = 0;
/** Sum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumImpl;
/** Sum of squares statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumSqImpl;
/** Minimum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] minImpl;
/** Maximum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] maxImpl;
/** Sum of log statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] sumLogImpl;
/** Geometric mean statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] geoMeanImpl;
/** Mean statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic[] meanImpl;
/** Covariance statistic implementation - cannot be reset. */
private VectorialCovariance covarianceImpl;
/** /**
* Add an n-tuple to the data * Add an n-tuple to the data
* *

View File

@ -59,21 +59,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** Serialization UID */ /** Serialization UID */
private static final long serialVersionUID = -2021321786743555871L; private static final long serialVersionUID = -2021321786743555871L;
/**
* Construct a SummaryStatistics instance
*/
public SummaryStatistics() {
}
/**
* A copy constructor. Creates a deep-copy of the {@code original}.
*
* @param original the {@code SummaryStatistics} instance to copy
*/
public SummaryStatistics(SummaryStatistics original) {
copy(original, this);
}
/** count of values that have been added */ /** count of values that have been added */
protected long n = 0; protected long n = 0;
@ -128,6 +113,21 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** Variance statistic implementation - can be reset by setter. */ /** Variance statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic varianceImpl = variance; private StorelessUnivariateStatistic varianceImpl = variance;
/**
* Construct a SummaryStatistics instance
*/
public SummaryStatistics() {
}
/**
* A copy constructor. Creates a deep-copy of the {@code original}.
*
* @param original the {@code SummaryStatistics} instance to copy
*/
public SummaryStatistics(SummaryStatistics original) {
copy(original, this);
}
/** /**
* Return a {@link StatisticalSummaryValues} instance reporting current * Return a {@link StatisticalSummaryValues} instance reporting current
* statistics. * statistics.

View File

@ -73,6 +73,14 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
copy(original, this); copy(original, this);
} }
/**
* Create a GeometricMean instance using the given SumOfLogs instance
* @param sumOfLogs sum of logs instance to use for computation
*/
public GeometricMean(SumOfLogs sumOfLogs) {
this.sumOfLogs = sumOfLogs;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -83,14 +91,6 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
return result; return result;
} }
/**
* Create a GeometricMean instance using the given SumOfLogs instance
* @param sumOfLogs sum of logs instance to use for computation
*/
public GeometricMean(SumOfLogs sumOfLogs) {
this.sumOfLogs = sumOfLogs;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -28,12 +28,6 @@ import org.apache.commons.math.stat.descriptive.StatisticalSummary;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class TestUtils { public class TestUtils {
/**
* Prevent instantiation.
*/
protected TestUtils() {
super();
}
/** Singleton TTest instance using default implementation. */ /** Singleton TTest instance using default implementation. */
private static TTest tTest = new TTestImpl(); private static TTest tTest = new TTestImpl();
@ -50,6 +44,13 @@ public class TestUtils {
private static OneWayAnova oneWayAnova = private static OneWayAnova oneWayAnova =
new OneWayAnovaImpl(); new OneWayAnovaImpl();
/**
* Prevent instantiation.
*/
protected TestUtils() {
super();
}
/** /**
* Set the (singleton) TTest instance. * Set the (singleton) TTest instance.
* *

View File

@ -69,6 +69,12 @@ import org.apache.commons.math.random.RandomGenerator;
*/ */
public class NaturalRanking implements RankingAlgorithm { public class NaturalRanking implements RankingAlgorithm {
/** default NaN strategy */
public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.MAXIMAL;
/** default ties strategy */
public static final TiesStrategy DEFAULT_TIES_STRATEGY = TiesStrategy.AVERAGE;
/** NaN strategy - defaults to NaNs maximal */ /** NaN strategy - defaults to NaNs maximal */
private final NaNStrategy nanStrategy; private final NaNStrategy nanStrategy;
@ -78,12 +84,6 @@ public class NaturalRanking implements RankingAlgorithm {
/** Source of random data - used only when ties strategy is RANDOM */ /** Source of random data - used only when ties strategy is RANDOM */
private final RandomData randomData; private final RandomData randomData;
/** default NaN strategy */
public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.MAXIMAL;
/** default ties strategy */
public static final TiesStrategy DEFAULT_TIES_STRATEGY = TiesStrategy.AVERAGE;
/** /**
* Create a NaturalRanking with default strategies for handling ties and NaNs. * Create a NaturalRanking with default strategies for handling ties and NaNs.
*/ */

View File

@ -36,15 +36,15 @@ import org.apache.commons.math.FieldElement;
*/ */
public class BigReal implements FieldElement<BigReal>, Comparable<BigReal>, Serializable { public class BigReal implements FieldElement<BigReal>, Comparable<BigReal>, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 7887631840434052850L;
/** A big real representing 0. */ /** A big real representing 0. */
public static final BigReal ZERO = new BigReal(BigDecimal.ZERO); public static final BigReal ZERO = new BigReal(BigDecimal.ZERO);
/** A big real representing 1. */ /** A big real representing 1. */
public static final BigReal ONE = new BigReal(BigDecimal.ONE); public static final BigReal ONE = new BigReal(BigDecimal.ONE);
/** Serializable version identifier. */
private static final long serialVersionUID = 7887631840434052850L;
/** Underlying BigDecimal. */ /** Underlying BigDecimal. */
private final BigDecimal d; private final BigDecimal d;

View File

@ -57,19 +57,15 @@ public class BigRealField implements Field<BigReal>, Serializable {
return BigReal.ZERO; return BigReal.ZERO;
} }
// CHECKSTYLE: stop HideUtilityClassConstructor
/** Holder for the instance. /** Holder for the instance.
* <p>We use here the Initialization On Demand Holder Idiom.</p> * <p>We use here the Initialization On Demand Holder Idiom.</p>
*/ */
private static class LazyHolder { private static class LazyHolder {
/** Private constructor. */
private LazyHolder() {
}
/** Cached field instance. */ /** Cached field instance. */
private static final BigRealField INSTANCE = new BigRealField(); private static final BigRealField INSTANCE = new BigRealField();
} }
// CHECKSTYLE: resume HideUtilityClassConstructor
/** Handle deserialization of the singleton. /** Handle deserialization of the singleton.
* @return the singleton instance * @return the singleton instance

View File

@ -65,6 +65,16 @@ public final class MathUtils {
/** Offset to order signed double numbers lexicographically. */ /** Offset to order signed double numbers lexicographically. */
private static final long SGN_MASK = 0x8000000000000000L; private static final long SGN_MASK = 0x8000000000000000L;
/** All long-representable factorials */
private static final long[] FACTORIALS = new long[] {
1l, 1l, 2l,
6l, 24l, 120l,
720l, 5040l, 40320l,
362880l, 3628800l, 39916800l,
479001600l, 6227020800l, 87178291200l,
1307674368000l, 20922789888000l, 355687428096000l,
6402373705728000l, 121645100408832000l, 2432902008176640000l };
/** /**
* Private Constructor * Private Constructor
*/ */
@ -469,13 +479,6 @@ public final class MathUtils {
return true; return true;
} }
/** All long-representable factorials */
private static final long[] FACTORIALS = new long[]
{1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800,
479001600, 6227020800l, 87178291200l, 1307674368000l, 20922789888000l,
355687428096000l, 6402373705728000l, 121645100408832000l,
2432902008176640000l};
/** /**
* Returns n!. Shorthand for <code>n</code> <a * Returns n!. Shorthand for <code>n</code> <a
* href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the

View File

@ -38,6 +38,15 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class OpenIntToDoubleHashMap implements Serializable { public class OpenIntToDoubleHashMap implements Serializable {
/** Status indicator for free table entries. */
protected static final byte FREE = 0;
/** Status indicator for full table entries. */
protected static final byte FULL = 1;
/** Status indicator for removed table entries. */
protected static final byte REMOVED = 2;
/** Serializable version identifier */ /** Serializable version identifier */
private static final long serialVersionUID = -3646337053166149105L; private static final long serialVersionUID = -3646337053166149105L;
@ -57,15 +66,6 @@ public class OpenIntToDoubleHashMap implements Serializable {
/** Number of bits to perturb the index when probing for collision resolution. */ /** Number of bits to perturb the index when probing for collision resolution. */
private static final int PERTURB_SHIFT = 5; private static final int PERTURB_SHIFT = 5;
/** Status indicator for free table entries. */
protected static final byte FREE = 0;
/** Status indicator for full table entries. */
protected static final byte FULL = 1;
/** Status indicator for removed table entries. */
protected static final byte REMOVED = 2;
/** Keys table. */ /** Keys table. */
private int[] keys; private int[] keys;

View File

@ -41,6 +41,15 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Serializable { public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Serializable {
/** Status indicator for free table entries. */
protected static final byte FREE = 0;
/** Status indicator for full table entries. */
protected static final byte FULL = 1;
/** Status indicator for removed table entries. */
protected static final byte REMOVED = 2;
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = -9179080286849120720L; private static final long serialVersionUID = -9179080286849120720L;
@ -60,15 +69,6 @@ public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Seriali
/** Number of bits to perturb the index when probing for collision resolution. */ /** Number of bits to perturb the index when probing for collision resolution. */
private static final int PERTURB_SHIFT = 5; private static final int PERTURB_SHIFT = 5;
/** Status indicator for free table entries. */
protected static final byte FREE = 0;
/** Status indicator for full table entries. */
protected static final byte FULL = 1;
/** Status indicator for removed table entries. */
protected static final byte REMOVED = 2;
/** Field to which the elements belong. */ /** Field to which the elements belong. */
private final Field<T> field; private final Field<T> field;

View File

@ -73,15 +73,15 @@ import org.apache.commons.math.MathRuntimeException;
*/ */
public class ResizableDoubleArray implements DoubleArray, Serializable { public class ResizableDoubleArray implements DoubleArray, Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -3485529955529426875L;
/** additive expansion mode */ /** additive expansion mode */
public static final int ADDITIVE_MODE = 1; public static final int ADDITIVE_MODE = 1;
/** multiplicative expansion mode */ /** multiplicative expansion mode */
public static final int MULTIPLICATIVE_MODE = 0; public static final int MULTIPLICATIVE_MODE = 0;
/** Serializable version identifier */
private static final long serialVersionUID = -3485529955529426875L;
/** /**
* The contraction criteria determines when the internal array will be * The contraction criteria determines when the internal array will be
* contracted to fit the number of elements contained in the element * contracted to fit the number of elements contained in the element