tighten checkstyle rules for hidden fields

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@810238 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-09-01 21:02:59 +00:00
parent de33e91191
commit 0283b0c935
36 changed files with 278 additions and 281 deletions

View File

@ -85,11 +85,13 @@
<!-- Constant names should obey the traditional all uppercase naming convention --> <!-- Constant names should obey the traditional all uppercase naming convention -->
<module name="ConstantName" /> <module name="ConstantName" />
<!-- <!-- Method parameters and local variables should not hide fields, except in constructors and setters -->
<module name="HiddenField"> <module name="HiddenField">
<property name="ignoreConstructorParameter" value="true" /> <property name="ignoreConstructorParameter" value="true" />
<property name="ignoreSetter" value="true" /> <property name="ignoreSetter" value="true" />
</module> </module>
<!--
<module name="DeclarationOrder" /> <module name="DeclarationOrder" />
<module name="IllegalCatch" /> <module name="IllegalCatch" />
<module name="RedundantModifier" /> <module name="RedundantModifier" />

View File

@ -115,11 +115,11 @@ public abstract class UnivariateRealIntegratorImpl
/** /**
* Convenience function for implementations. * Convenience function for implementations.
* *
* @param result the result to set * @param newResult the result to set
* @param iterationCount the iteration count to set * @param iterationCount the iteration count to set
*/ */
protected final void setResult(double result, int iterationCount) { protected final void setResult(double newResult, int iterationCount) {
this.result = result; this.result = newResult;
this.iterationCount = iterationCount; this.iterationCount = iterationCount;
this.resultComputed = true; this.resultComputed = true;
} }

View File

@ -134,11 +134,11 @@ public abstract class UnivariateRealSolverImpl
/** /**
* Convenience function for implementations. * Convenience function for implementations.
* *
* @param result the result to set * @param newResult the result to set
* @param iterationCount the iteration count to set * @param iterationCount the iteration count to set
*/ */
protected final void setResult(final double result, final int iterationCount) { protected final void setResult(final double newResult, final int iterationCount) {
this.result = result; this.result = newResult;
this.iterationCount = iterationCount; this.iterationCount = iterationCount;
this.resultComputed = true; this.resultComputed = true;
} }
@ -171,16 +171,16 @@ public abstract class UnivariateRealSolverImpl
* *
* @param lower the lower endpoint * @param lower the lower endpoint
* @param upper the upper endpoint * @param upper the upper endpoint
* @param f the function * @param function the function
* @return true if f(lower) * f(upper) < 0 * @return true if f(lower) * f(upper) < 0
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints * function at the endpoints
*/ */
protected boolean isBracketing(final double lower, final double upper, protected boolean isBracketing(final double lower, final double upper,
final UnivariateRealFunction f) final UnivariateRealFunction function)
throws FunctionEvaluationException { throws FunctionEvaluationException {
final double f1 = f.value(lower); final double f1 = function.value(lower);
final double f2 = f.value(upper); final double f2 = function.value(upper);
return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0)); return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0));
} }
@ -235,21 +235,21 @@ public abstract class UnivariateRealSolverImpl
* *
* @param lower lower endpoint * @param lower lower endpoint
* @param upper upper endpoint * @param upper upper endpoint
* @param f function * @param function function
* @throws IllegalArgumentException * @throws IllegalArgumentException
* @throws FunctionEvaluationException if an error occurs evaluating the * @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints * function at the endpoints
*/ */
protected void verifyBracketing(final double lower, final double upper, protected void verifyBracketing(final double lower, final double upper,
final UnivariateRealFunction f) final UnivariateRealFunction function)
throws FunctionEvaluationException { throws FunctionEvaluationException {
verifyInterval(lower, upper); verifyInterval(lower, upper);
if (!isBracketing(lower, upper, f)) { if (!isBracketing(lower, upper, function)) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"function values at endpoints do not have different signs. " + "function values at endpoints do not have different signs. " +
"Endpoints: [{0}, {1}], Values: [{2}, {3}]", "Endpoints: [{0}, {1}], Values: [{2}, {3}]",
lower, upper, f.value(lower), f.value(upper)); lower, upper, function.value(lower), function.value(upper));
} }
} }
} }

View File

@ -1001,13 +1001,13 @@ public class Complex implements FieldElement<Complex>, Serializable {
/** /**
* Create a complex number given the real and imaginary parts. * Create a complex number given the real and imaginary parts.
* *
* @param real the real part * @param realPart the real part
* @param imaginary the imaginary part * @param imaginaryPart the imaginary part
* @return a new complex number instance * @return a new complex number instance
* @since 1.2 * @since 1.2
*/ */
protected Complex createComplex(double real, double imaginary) { protected Complex createComplex(double realPart, double imaginaryPart) {
return new Complex(real, imaginary); return new Complex(realPart, imaginaryPart);
} }
/** /**

View File

@ -35,10 +35,10 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
private static final long serialVersionUID = 8589540077390120676L; private static final long serialVersionUID = 8589540077390120676L;
/** The shape parameter. */ /** The shape parameter. */
private double alpha; private double shape;
/** The scale parameter. */ /** The scale parameter. */
private double beta; private double scale;
/** /**
* Creates weibull distribution with the given shape and scale and a * Creates weibull distribution with the given shape and scale and a
@ -72,7 +72,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
* @return the shape parameter. * @return the shape parameter.
*/ */
public double getShape() { public double getShape() {
return alpha; return shape;
} }
/** /**
@ -80,7 +80,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
* @return the scale parameter. * @return the scale parameter.
*/ */
public double getScale() { public double getScale() {
return beta; return scale;
} }
/** /**
@ -121,7 +121,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
"shape must be positive ({0})", "shape must be positive ({0})",
alpha); alpha);
} }
this.alpha = alpha; this.shape = alpha;
} }
/** /**
@ -134,7 +134,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
"scale must be positive ({0})", "scale must be positive ({0})",
beta); beta);
} }
this.beta = beta; this.scale = beta;
} }
/** /**

View File

@ -173,14 +173,14 @@ public abstract class AbstractEstimator implements Estimator {
updateJacobian(); updateJacobian();
// compute transpose(J).J, avoiding building big intermediate matrices // compute transpose(J).J, avoiding building big intermediate matrices
final int rows = problem.getMeasurements().length; final int n = problem.getMeasurements().length;
final int cols = problem.getUnboundParameters().length; final int m = problem.getUnboundParameters().length;
final int max = cols * rows; final int max = m * n;
double[][] jTj = new double[cols][cols]; double[][] jTj = new double[m][m];
for (int i = 0; i < cols; ++i) { for (int i = 0; i < m; ++i) {
for (int j = i; j < cols; ++j) { for (int j = i; j < m; ++j) {
double sum = 0; double sum = 0;
for (int k = 0; k < max; k += cols) { for (int k = 0; k < max; k += m) {
sum += jacobian[k + i] * jacobian[k + j]; sum += jacobian[k + i] * jacobian[k + j];
} }
jTj[i][j] = sum; jTj[i][j] = sum;

View File

@ -57,11 +57,11 @@ public abstract class AbstractListChromosome<T> extends Chromosome {
/** /**
* *
* Asserts that <code>representation</code> can represent a valid chromosome. * Asserts that <code>representation</code> can represent a valid chromosome.
* @param representation representation of the chromosome * @param chromosomeRepresentation representation of the chromosome
* @throws InvalidRepresentationException iff the <code>representation</code> can not represent * @throws InvalidRepresentationException iff the <code>representation</code> can not represent
* a valid chromosome * a valid chromosome
*/ */
protected abstract void checkValidity(List<T> representation) throws InvalidRepresentationException; protected abstract void checkValidity(List<T> chromosomeRepresentation) throws InvalidRepresentationException;
/** /**
* Returns the (immutable) inner representation of the chromosome. * Returns the (immutable) inner representation of the chromosome.
@ -87,12 +87,12 @@ public abstract class AbstractListChromosome<T> extends Chromosome {
* *
* Usually, this method just calls a constructor of the class. * Usually, this method just calls a constructor of the class.
* *
* @param representation * @param chromosomeRepresentation
* the inner array representation of the new chromosome. * the inner array representation of the new chromosome.
* @return new instance extended from FixedLengthChromosome with the given * @return new instance extended from FixedLengthChromosome with the given
* arrayRepresentation * arrayRepresentation
*/ */
public abstract AbstractListChromosome<T> newFixedLengthChromosome(final List<T> representation); public abstract AbstractListChromosome<T> newFixedLengthChromosome(final List<T> chromosomeRepresentation);
/** /**
* {@inheritDoc} * {@inheritDoc}

View File

@ -48,8 +48,8 @@ public abstract class BinaryChromosome extends AbstractListChromosome<Integer> {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected void checkValidity(List<Integer> representation) throws InvalidRepresentationException { protected void checkValidity(List<Integer> chromosomeRepresentation) throws InvalidRepresentationException {
for (int i : representation) { for (int i : chromosomeRepresentation) {
if (i < 0 || i >1) if (i < 0 || i >1)
throw new InvalidRepresentationException("Elements can be only 0 or 1."); throw new InvalidRepresentationException("Elements can be only 0 or 1.");
} }

View File

@ -172,8 +172,8 @@ public abstract class RandomKey<T> extends AbstractListChromosome<Double> implem
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected void checkValidity(java.util.List<Double> representation) throws InvalidRepresentationException { protected void checkValidity(java.util.List<Double> chromosomeRepresentation) throws InvalidRepresentationException {
for (double val : representation) { for (double val : chromosomeRepresentation) {
if (val < 0 || val > 1) { if (val < 0 || val > 1) {
throw new InvalidRepresentationException("Values of representation must be in [0,1] interval"); throw new InvalidRepresentationException("Values of representation must be in [0,1] interval");
} }

View File

@ -851,27 +851,27 @@ public class EigenDecompositionImpl implements EigenDecomposition {
sigmaLow = 0; sigmaLow = 0;
// find start of a new split segment to process // find start of a new split segment to process
double eMin = (i0 == n0) ? 0 : work[4 * n0 - 6]; double offDiagMin = (i0 == n0) ? 0 : work[4 * n0 - 6];
double eMax = 0; double offDiagMax = 0;
double qMax = work[4 * n0 - 4]; double diagMax = work[4 * n0 - 4];
double qMin = qMax; double diagMin = diagMax;
i0 = 0; i0 = 0;
for (int i = 4 * (n0 - 2); i >= 0; i -= 4) { for (int i = 4 * (n0 - 2); i >= 0; i -= 4) {
if (work[i + 2] <= 0) { if (work[i + 2] <= 0) {
i0 = 1 + i / 4; i0 = 1 + i / 4;
break; break;
} }
if (qMin >= 4 * eMax) { if (diagMin >= 4 * offDiagMax) {
qMin = Math.min(qMin, work[i + 4]); diagMin = Math.min(diagMin, work[i + 4]);
eMax = Math.max(eMax, work[i + 2]); offDiagMax = Math.max(offDiagMax, work[i + 2]);
} }
qMax = Math.max(qMax, work[i] + work[i + 2]); diagMax = Math.max(diagMax, work[i] + work[i + 2]);
eMin = Math.min(eMin, work[i + 2]); offDiagMin = Math.min(offDiagMin, work[i + 2]);
} }
work[4 * n0 - 2] = eMin; work[4 * n0 - 2] = offDiagMin;
// lower bound of Gershgorin disk // lower bound of Gershgorin disk
dMin = -Math.max(0, qMin - 2 * Math.sqrt(qMin * eMax)); dMin = -Math.max(0, diagMin - 2 * Math.sqrt(diagMin * offDiagMax));
pingPong = 0; pingPong = 0;
int maxIter = 30 * (n0 - i0); int maxIter = 30 * (n0 - i0);
@ -887,11 +887,11 @@ public class EigenDecompositionImpl implements EigenDecomposition {
// check for new splits after "ping" steps // check for new splits after "ping" steps
// when the last elements of qd array are very small // when the last elements of qd array are very small
if ((pingPong == 0) && (n0 - i0 > 3) && if ((pingPong == 0) && (n0 - i0 > 3) &&
(work[4 * n0 - 1] <= TOLERANCE_2 * qMax) && (work[4 * n0 - 1] <= TOLERANCE_2 * diagMax) &&
(work[4 * n0 - 2] <= TOLERANCE_2 * sigma)) { (work[4 * n0 - 2] <= TOLERANCE_2 * sigma)) {
int split = i0 - 1; int split = i0 - 1;
qMax = work[4 * i0]; diagMax = work[4 * i0];
eMin = work[4 * i0 + 2]; offDiagMin = work[4 * i0 + 2];
double previousEMin = work[4 * i0 + 3]; double previousEMin = work[4 * i0 + 3];
for (int i = 4 * i0; i < 4 * n0 - 11; i += 4) { for (int i = 4 * i0; i < 4 * n0 - 11; i += 4) {
if ((work[i + 3] <= TOLERANCE_2 * work[i]) && if ((work[i + 3] <= TOLERANCE_2 * work[i]) &&
@ -899,16 +899,16 @@ public class EigenDecompositionImpl implements EigenDecomposition {
// insert a split // insert a split
work[i + 2] = -sigma; work[i + 2] = -sigma;
split = i / 4; split = i / 4;
qMax = 0; diagMax = 0;
eMin = work[i + 6]; offDiagMin = work[i + 6];
previousEMin = work[i + 7]; previousEMin = work[i + 7];
} else { } else {
qMax = Math.max(qMax, work[i + 4]); diagMax = Math.max(diagMax, work[i + 4]);
eMin = Math.min(eMin, work[i + 2]); offDiagMin = Math.min(offDiagMin, work[i + 2]);
previousEMin = Math.min(previousEMin, work[i + 3]); previousEMin = Math.min(previousEMin, work[i + 3]);
} }
} }
work[4 * n0 - 2] = eMin; work[4 * n0 - 2] = offDiagMin;
work[4 * n0 - 1] = previousEMin; work[4 * n0 - 1] = previousEMin;
i0 = split + 1; i0 = split + 1;
} }
@ -1662,20 +1662,20 @@ public class EigenDecompositionImpl implements EigenDecomposition {
/** /**
* Update sigma. * Update sigma.
* @param tau shift to apply to sigma * @param shift shift to apply to sigma
*/ */
private void updateSigma(final double tau) { private void updateSigma(final double shift) {
// BEWARE: do NOT attempt to simplify the following statements // BEWARE: do NOT attempt to simplify the following statements
// the expressions below take care to accumulate the part of sigma // the expressions below take care to accumulate the part of sigma
// that does not fit within a double variable into sigmaLow // that does not fit within a double variable into sigmaLow
if (tau < sigma) { if (shift < sigma) {
sigmaLow += tau; sigmaLow += shift;
final double t = sigma + sigmaLow; final double t = sigma + sigmaLow;
sigmaLow -= t - sigma; sigmaLow -= t - sigma;
sigma = t; sigma = t;
} else { } else {
final double t = sigma + tau; final double t = sigma + shift;
sigmaLow += sigma - (t - tau); sigmaLow += sigma - (t - shift);
sigma = t; sigma = t;
} }
} }
@ -1731,8 +1731,7 @@ public class EigenDecompositionImpl implements EigenDecomposition {
int r = m - 1; int r = m - 1;
double minG = Math.abs(work[6 * r] + work[6 * r + 3] + eigenvalue); double minG = Math.abs(work[6 * r] + work[6 * r + 3] + eigenvalue);
for (int i = 0, sixI = 0; i < m - 1; ++i, sixI += 6) { for (int i = 0, sixI = 0; i < m - 1; ++i, sixI += 6) {
final double g = work[sixI] + d[i] * work[sixI + 9] / work[sixI + 10]; final double absG = Math.abs(work[sixI] + d[i] * work[sixI + 9] / work[sixI + 10]);
final double absG = Math.abs(g);
if (absG < minG) { if (absG < minG) {
r = i; r = i;
minG = absG; minG = absG;

View File

@ -33,10 +33,10 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
private static final long serialVersionUID = -5962461716457143437L; private static final long serialVersionUID = -5962461716457143437L;
/** Number of rows of the matrix. */ /** Number of rows of the matrix. */
private final int rowDimension; private final int rows;
/** Number of columns of the matrix. */ /** Number of columns of the matrix. */
private final int columnDimension; private final int columns;
/** Storage for (sparse) matrix elements. */ /** Storage for (sparse) matrix elements. */
private final OpenIntToDoubleHashMap entries; private final OpenIntToDoubleHashMap entries;
@ -48,8 +48,8 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
*/ */
public OpenMapRealMatrix(int rowDimension, int columnDimension) { public OpenMapRealMatrix(int rowDimension, int columnDimension) {
super(rowDimension, columnDimension); super(rowDimension, columnDimension);
this.rowDimension = rowDimension; this.rows = rowDimension;
this.columnDimension = columnDimension; this.columns = columnDimension;
this.entries = new OpenIntToDoubleHashMap(0.0); this.entries = new OpenIntToDoubleHashMap(0.0);
} }
@ -58,8 +58,8 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
* @param matrix matrix to copy * @param matrix matrix to copy
*/ */
public OpenMapRealMatrix(OpenMapRealMatrix matrix) { public OpenMapRealMatrix(OpenMapRealMatrix matrix) {
this.rowDimension = matrix.rowDimension; this.rows = matrix.rows;
this.columnDimension = matrix.columnDimension; this.columns = matrix.columns;
this.entries = new OpenIntToDoubleHashMap(matrix.entries); this.entries = new OpenIntToDoubleHashMap(matrix.entries);
} }
@ -79,7 +79,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getColumnDimension() { public int getColumnDimension() {
return columnDimension; return columns;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -108,8 +108,8 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
final OpenMapRealMatrix out = new OpenMapRealMatrix(this); final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) { for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance(); iterator.advance();
final int row = iterator.key() / columnDimension; final int row = iterator.key() / columns;
final int col = iterator.key() - row * columnDimension; final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) + iterator.value()); out.setEntry(row, col, getEntry(row, col) + iterator.value());
} }
@ -143,8 +143,8 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
final OpenMapRealMatrix out = new OpenMapRealMatrix(this); final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) { for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance(); iterator.advance();
final int row = iterator.key() / columnDimension; final int row = iterator.key() / columns;
final int col = iterator.key() - row * columnDimension; final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) - iterator.value()); out.setEntry(row, col, getEntry(row, col) - iterator.value());
} }
@ -164,13 +164,13 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
MatrixUtils.checkMultiplicationCompatible(this, m); MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension(); final int outCols = m.getColumnDimension();
final BlockRealMatrix out = new BlockRealMatrix(rowDimension, outCols); final BlockRealMatrix out = new BlockRealMatrix(rows, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) { for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance(); iterator.advance();
final double value = iterator.value(); final double value = iterator.value();
final int key = iterator.key(); final int key = iterator.key();
final int i = key / columnDimension; final int i = key / columns;
final int k = key % columnDimension; final int k = key % columns;
for (int j = 0; j < outCols; ++j) { for (int j = 0; j < outCols; ++j) {
out.addToEntry(i, j, value * m.getEntry(k, j)); out.addToEntry(i, j, value * m.getEntry(k, j));
} }
@ -195,13 +195,13 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
MatrixUtils.checkMultiplicationCompatible(this, m); MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension(); final int outCols = m.getColumnDimension();
OpenMapRealMatrix out = new OpenMapRealMatrix(rowDimension, outCols); OpenMapRealMatrix out = new OpenMapRealMatrix(rows, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) { for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance(); iterator.advance();
final double value = iterator.value(); final double value = iterator.value();
final int key = iterator.key(); final int key = iterator.key();
final int i = key / columnDimension; final int i = key / columns;
final int k = key % columnDimension; final int k = key % columns;
for (int j = 0; j < outCols; ++j) { for (int j = 0; j < outCols; ++j) {
final int rightKey = m.computeKey(k, j); final int rightKey = m.computeKey(k, j);
if (m.entries.containsKey(rightKey)) { if (m.entries.containsKey(rightKey)) {
@ -232,7 +232,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getRowDimension() { public int getRowDimension() {
return rowDimension; return rows;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -285,7 +285,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
* @return key within the map to access the matrix element * @return key within the map to access the matrix element
*/ */
private int computeKey(int row, int column) { private int computeKey(int row, int column) {
return row * columnDimension + column; return row * columns + column;
} }

View File

@ -37,11 +37,11 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
/** /**
* row dimension * row dimension
*/ */
private final int rowDimension; private final int rows;
/** /**
* column dimension * column dimension
*/ */
private final int columnDimension; private final int columns;
/** /**
@ -50,8 +50,8 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
*/ */
public SparseFieldMatrix(final Field<T> field) { public SparseFieldMatrix(final Field<T> field) {
super(field); super(field);
rowDimension = 0; rows = 0;
columnDimension= 0; columns= 0;
entries = new OpenIntToFieldHashMap<T>(field); entries = new OpenIntToFieldHashMap<T>(field);
} }
@ -67,8 +67,8 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
final int rowDimension, final int columnDimension) final int rowDimension, final int columnDimension)
throws IllegalArgumentException { throws IllegalArgumentException {
super(field, rowDimension, columnDimension); super(field, rowDimension, columnDimension);
this.rowDimension = rowDimension; this.rows = rowDimension;
this.columnDimension = columnDimension; this.columns = columnDimension;
entries = new OpenIntToFieldHashMap<T>(field); entries = new OpenIntToFieldHashMap<T>(field);
} }
@ -78,8 +78,8 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
*/ */
public SparseFieldMatrix(SparseFieldMatrix<T> other) { public SparseFieldMatrix(SparseFieldMatrix<T> other) {
super(other.getField(), other.getRowDimension(), other.getColumnDimension()); super(other.getField(), other.getRowDimension(), other.getColumnDimension());
rowDimension = other.getRowDimension(); rows = other.getRowDimension();
columnDimension = other.getColumnDimension(); columns = other.getColumnDimension();
entries = new OpenIntToFieldHashMap<T>(other.entries); entries = new OpenIntToFieldHashMap<T>(other.entries);
} }
@ -89,11 +89,11 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
*/ */
public SparseFieldMatrix(FieldMatrix<T> other){ public SparseFieldMatrix(FieldMatrix<T> other){
super(other.getField(), other.getRowDimension(), other.getColumnDimension()); super(other.getField(), other.getRowDimension(), other.getColumnDimension());
rowDimension = other.getRowDimension(); rows = other.getRowDimension();
columnDimension = other.getColumnDimension(); columns = other.getColumnDimension();
entries = new OpenIntToFieldHashMap<T>(getField()); entries = new OpenIntToFieldHashMap<T>(getField());
for (int i = 0; i < rowDimension; i++) { for (int i = 0; i < rows; i++) {
for (int j = 0; j < columnDimension; j++) { for (int j = 0; j < columns; j++) {
setEntry(i, j, other.getEntry(i, j)); setEntry(i, j, other.getEntry(i, j));
} }
} }
@ -131,7 +131,7 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getColumnDimension() { public int getColumnDimension() {
return columnDimension; return columns;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -145,7 +145,7 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getRowDimension() { public int getRowDimension() {
return rowDimension; return rows;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -184,7 +184,7 @@ public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldM
* @return key within the map to access the matrix element * @return key within the map to access the matrix element
*/ */
private int computeKey(int row, int column) { private int computeKey(int row, int column) {
return row * columnDimension + column; return row * columns + column;
} }
} }

View File

@ -184,30 +184,30 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
} }
/** Perform some sanity checks on the integration parameters. /** Perform some sanity checks on the integration parameters.
* @param equations differential equations set * @param ode differential equations set
* @param t0 start time * @param t0 start time
* @param y0 state vector at t0 * @param y0 state vector at t0
* @param t target time for the integration * @param t target time for the integration
* @param y placeholder where to put the state vector * @param y placeholder where to put the state vector
* @exception IntegratorException if some inconsistency is detected * @exception IntegratorException if some inconsistency is detected
*/ */
protected void sanityChecks(final FirstOrderDifferentialEquations equations, protected void sanityChecks(final FirstOrderDifferentialEquations ode,
final double t0, final double[] y0, final double t0, final double[] y0,
final double t, final double[] y) final double t, final double[] y)
throws IntegratorException { throws IntegratorException {
if (equations.getDimension() != y0.length) { if (ode.getDimension() != y0.length) {
throw new IntegratorException( throw new IntegratorException(
"dimensions mismatch: ODE problem has dimension {0}," + "dimensions mismatch: ODE problem has dimension {0}," +
" initial state vector has dimension {1}", " initial state vector has dimension {1}",
equations.getDimension(), y0.length); ode.getDimension(), y0.length);
} }
if (equations.getDimension() != y.length) { if (ode.getDimension() != y.length) {
throw new IntegratorException( throw new IntegratorException(
"dimensions mismatch: ODE problem has dimension {0}," + "dimensions mismatch: ODE problem has dimension {0}," +
" final state vector has dimension {1}", " final state vector has dimension {1}",
equations.getDimension(), y.length); ode.getDimension(), y.length);
} }
if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) { if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {

View File

@ -183,10 +183,10 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator {
* <p>The various step and event handlers for this starter integrator * <p>The various step and event handlers for this starter integrator
* will be managed automatically by the multi-step integrator. Any * will be managed automatically by the multi-step integrator. Any
* user configuration for these elements will be cleared before use.</p> * user configuration for these elements will be cleared before use.</p>
* @param starter starter integrator * @param starterIntegrator starter integrator
*/ */
public void setStarterIntegrator(FirstOrderIntegrator starter) { public void setStarterIntegrator(FirstOrderIntegrator starterIntegrator) {
this.starter = starter; this.starter = starterIntegrator;
} }
/** Start the integration. /** Start the integration.

View File

@ -138,17 +138,17 @@ public class EventState {
} }
/** Reinitialize the beginning of the step. /** Reinitialize the beginning of the step.
* @param t0 value of the independent <i>time</i> variable at the * @param tStart value of the independent <i>time</i> variable at the
* beginning of the step * beginning of the step
* @param y0 array containing the current value of the state vector * @param yStart array containing the current value of the state vector
* at the beginning of the step * at the beginning of the step
* @exception EventException if the event handler * @exception EventException if the event handler
* value cannot be evaluated at the beginning of the step * value cannot be evaluated at the beginning of the step
*/ */
public void reinitializeBegin(final double t0, final double[] y0) public void reinitializeBegin(final double tStart, final double[] yStart)
throws EventException { throws EventException {
this.t0 = t0; t0 = tStart;
g0 = handler.g(t0, y0); g0 = handler.g(tStart, yStart);
g0Positive = (g0 >= 0); g0Positive = (g0 >= 0);
} }

View File

@ -150,29 +150,29 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
* <p>By default, the test is performed, at most during two * <p>By default, the test is performed, at most during two
* iterations at each step, and at most once for each of these * iterations at each step, and at most once for each of these
* iterations. The default stepsize reduction factor is 0.5.</p> * iterations. The default stepsize reduction factor is 0.5.</p>
* @param performTest if true, stability check will be performed, * @param performStabilityCheck if true, stability check will be performed,
if false, the check will be skipped if false, the check will be skipped
* @param maxIter maximal number of iterations for which checks are * @param maxNumIter maximal number of iterations for which checks are
* performed (the number of iterations is reset to default if negative * performed (the number of iterations is reset to default if negative
* or null) * or null)
* @param maxChecks maximal number of checks for each iteration * @param maxNumChecks maximal number of checks for each iteration
* (the number of checks is reset to default if negative or null) * (the number of checks is reset to default if negative or null)
* @param stabilityReduction stepsize reduction factor in case of * @param stepsizeReductionFactor stepsize reduction factor in case of
* failure (the factor is reset to default if lower than 0.0001 or * failure (the factor is reset to default if lower than 0.0001 or
* greater than 0.9999) * greater than 0.9999)
*/ */
public void setStabilityCheck(final boolean performTest, public void setStabilityCheck(final boolean performStabilityCheck,
final int maxIter, final int maxChecks, final int maxNumIter, final int maxNumChecks,
final double stabilityReduction) { final double stepsizeReductionFactor) {
this.performTest = performTest; this.performTest = performStabilityCheck;
this.maxIter = (maxIter <= 0) ? 2 : maxIter; this.maxIter = (maxNumIter <= 0) ? 2 : maxNumIter;
this.maxChecks = (maxChecks <= 0) ? 1 : maxChecks; this.maxChecks = (maxNumChecks <= 0) ? 1 : maxNumChecks;
if ((stabilityReduction < 0.0001) || (stabilityReduction > 0.9999)) { if ((stepsizeReductionFactor < 0.0001) || (stepsizeReductionFactor > 0.9999)) {
this.stabilityReduction = 0.5; this.stabilityReduction = 0.5;
} else { } else {
this.stabilityReduction = stabilityReduction; this.stabilityReduction = stepsizeReductionFactor;
} }
} }
@ -192,40 +192,40 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
* </pre> * </pre>
* The default values are 0.02 for stepControl3 and 4.0 for * The default values are 0.02 for stepControl3 and 4.0 for
* stepControl4.</p> * stepControl4.</p>
* @param stepControl1 first stepsize control factor (the factor is * @param control1 first stepsize control factor (the factor is
* reset to default if lower than 0.0001 or greater than 0.9999) * reset to default if lower than 0.0001 or greater than 0.9999)
* @param stepControl2 second stepsize control factor (the factor * @param control2 second stepsize control factor (the factor
* is reset to default if lower than 0.0001 or greater than 0.9999) * is reset to default if lower than 0.0001 or greater than 0.9999)
* @param stepControl3 third stepsize control factor (the factor is * @param control3 third stepsize control factor (the factor is
* reset to default if lower than 0.0001 or greater than 0.9999) * reset to default if lower than 0.0001 or greater than 0.9999)
* @param stepControl4 fourth stepsize control factor (the factor * @param control4 fourth stepsize control factor (the factor
* is reset to default if lower than 1.0001 or greater than 999.9) * is reset to default if lower than 1.0001 or greater than 999.9)
*/ */
public void setStepsizeControl(final double stepControl1, final double stepControl2, public void setStepsizeControl(final double control1, final double control2,
final double stepControl3, final double stepControl4) { final double control3, final double control4) {
if ((stepControl1 < 0.0001) || (stepControl1 > 0.9999)) { if ((control1 < 0.0001) || (control1 > 0.9999)) {
this.stepControl1 = 0.65; this.stepControl1 = 0.65;
} else { } else {
this.stepControl1 = stepControl1; this.stepControl1 = control1;
} }
if ((stepControl2 < 0.0001) || (stepControl2 > 0.9999)) { if ((control2 < 0.0001) || (control2 > 0.9999)) {
this.stepControl2 = 0.94; this.stepControl2 = 0.94;
} else { } else {
this.stepControl2 = stepControl2; this.stepControl2 = control2;
} }
if ((stepControl3 < 0.0001) || (stepControl3 > 0.9999)) { if ((control3 < 0.0001) || (control3 > 0.9999)) {
this.stepControl3 = 0.02; this.stepControl3 = 0.02;
} else { } else {
this.stepControl3 = stepControl3; this.stepControl3 = control3;
} }
if ((stepControl4 < 1.0001) || (stepControl4 > 999.9)) { if ((control4 < 1.0001) || (control4 > 999.9)) {
this.stepControl4 = 4.0; this.stepControl4 = 4.0;
} else { } else {
this.stepControl4 = stepControl4; this.stepControl4 = control4;
} }
} }
@ -246,30 +246,30 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
* <p>The default maximal order after construction is 18 (i.e. the * <p>The default maximal order after construction is 18 (i.e. the
* maximal number of columns is 9). The default values are 0.8 for * maximal number of columns is 9). The default values are 0.8 for
* orderControl1 and 0.9 for orderControl2.</p> * orderControl1 and 0.9 for orderControl2.</p>
* @param maxOrder maximal order in the extrapolation table (the * @param maximalOrder maximal order in the extrapolation table (the
* maximal order is reset to default if order <= 6 or odd) * maximal order is reset to default if order <= 6 or odd)
* @param orderControl1 first order control factor (the factor is * @param control1 first order control factor (the factor is
* reset to default if lower than 0.0001 or greater than 0.9999) * reset to default if lower than 0.0001 or greater than 0.9999)
* @param orderControl2 second order control factor (the factor * @param control2 second order control factor (the factor
* is reset to default if lower than 0.0001 or greater than 0.9999) * is reset to default if lower than 0.0001 or greater than 0.9999)
*/ */
public void setOrderControl(final int maxOrder, public void setOrderControl(final int maximalOrder,
final double orderControl1, final double orderControl2) { final double control1, final double control2) {
if ((maxOrder <= 6) || (maxOrder % 2 != 0)) { if ((maximalOrder <= 6) || (maximalOrder % 2 != 0)) {
this.maxOrder = 18; this.maxOrder = 18;
} }
if ((orderControl1 < 0.0001) || (orderControl1 > 0.9999)) { if ((control1 < 0.0001) || (control1 > 0.9999)) {
this.orderControl1 = 0.8; this.orderControl1 = 0.8;
} else { } else {
this.orderControl1 = orderControl1; this.orderControl1 = control1;
} }
if ((orderControl2 < 0.0001) || (orderControl2 > 0.9999)) { if ((control2 < 0.0001) || (control2 > 0.9999)) {
this.orderControl2 = 0.9; this.orderControl2 = 0.9;
} else { } else {
this.orderControl2 = orderControl2; this.orderControl2 = control2;
} }
// reinitialize the arrays // reinitialize the arrays
@ -352,20 +352,20 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
* default value for mudif is 4 and the interpolation error is used * default value for mudif is 4 and the interpolation error is used
* in stepsize control by default. * in stepsize control by default.
* @param useInterpolationError if true, interpolation error is used * @param useInterpolationErrorForControl if true, interpolation error is used
* for stepsize control * for stepsize control
* @param mudif interpolation order control parameter (the parameter * @param mudifControlParameter interpolation order control parameter (the parameter
* is reset to default if <= 0 or >= 7) * is reset to default if <= 0 or >= 7)
*/ */
public void setInterpolationControl(final boolean useInterpolationError, public void setInterpolationControl(final boolean useInterpolationErrorForControl,
final int mudif) { final int mudifControlParameter) {
this.useInterpolationError = useInterpolationError; this.useInterpolationError = useInterpolationErrorForControl;
if ((mudif <= 0) || (mudif >= 7)) { if ((mudifControlParameter <= 0) || (mudifControlParameter >= 7)) {
this.mudif = 4; this.mudif = 4;
} else { } else {
this.mudif = mudif; this.mudif = mudifControlParameter;
} }
} }

View File

@ -108,18 +108,18 @@ abstract class RungeKuttaStepInterpolator
* {@link AbstractStepInterpolator#getInterpolatedState * {@link AbstractStepInterpolator#getInterpolatedState
* getInterpolatedState} method (for an interpolator which needs a * getInterpolatedState} method (for an interpolator which needs a
* finalization) or if it clones the step interpolator.</p> * finalization) or if it clones the step interpolator.</p>
* @param integrator integrator being used * @param rkIntegrator integrator being used
* @param y reference to the integrator array holding the state at * @param y reference to the integrator array holding the state at
* the end of the step * the end of the step
* @param yDotK reference to the integrator array holding all the * @param yDotArray reference to the integrator array holding all the
* intermediate slopes * intermediate slopes
* @param forward integration direction indicator * @param forward integration direction indicator
*/ */
public void reinitialize(final AbstractIntegrator integrator, public void reinitialize(final AbstractIntegrator rkIntegrator,
final double[] y, final double[][] yDotK, final boolean forward) { final double[] y, final double[][] yDotArray, final boolean forward) {
reinitialize(y, forward); reinitialize(y, forward);
this.yDotK = yDotK; this.yDotK = yDotArray;
this.integrator = integrator; this.integrator = rkIntegrator;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */

View File

@ -164,9 +164,9 @@ public abstract class AbstractStepInterpolator
/** Reinitialize the instance /** Reinitialize the instance
* @param y reference to the integrator array holding the state at * @param y reference to the integrator array holding the state at
* the end of the step * the end of the step
* @param forward integration direction indicator * @param isForward integration direction indicator
*/ */
protected void reinitialize(final double[] y, final boolean forward) { protected void reinitialize(final double[] y, final boolean isForward) {
previousTime = Double.NaN; previousTime = Double.NaN;
currentTime = Double.NaN; currentTime = Double.NaN;
@ -178,7 +178,7 @@ public abstract class AbstractStepInterpolator
interpolatedDerivatives = new double[y.length]; interpolatedDerivatives = new double[y.length];
finalized = false; finalized = false;
this.forward = forward; this.forward = isForward;
this.dirtyState = true; this.dirtyState = true;
} }

View File

@ -114,19 +114,20 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
/** Reinitialize the instance. /** Reinitialize the instance.
* <p>Beware that all arrays <em>must</em> be references to integrator * <p>Beware that all arrays <em>must</em> be references to integrator
* arrays, in order to ensure proper update without copy.</p> * arrays, in order to ensure proper update without copy.</p>
* @param referenceTime time at which all arrays are defined * @param time time at which all arrays are defined
* @param scalingH step size used in the scaled and nordsieck arrays * @param stepSize step size used in the scaled and nordsieck arrays
* @param scaled reference to the integrator array holding the first * @param scaledDerivative reference to the integrator array holding the first
* scaled derivative * scaled derivative
* @param nordsieck reference to the integrator matrix holding the * @param nordsieckVector reference to the integrator matrix holding the
* nordsieck vector * nordsieck vector
*/ */
public void reinitialize(final double referenceTime, final double scalingH, public void reinitialize(final double time, final double stepSize,
final double[] scaled, final Array2DRowRealMatrix nordsieck) { final double[] scaledDerivative,
this.referenceTime = referenceTime; final Array2DRowRealMatrix nordsieckVector) {
this.scalingH = scalingH; this.referenceTime = time;
this.scaled = scaled; this.scalingH = stepSize;
this.nordsieck = nordsieck; this.scaled = scaledDerivative;
this.nordsieck = nordsieckVector;
// make sure the state and derivatives will depend on the new arrays // make sure the state and derivatives will depend on the new arrays
setInterpolatedTime(getInterpolatedTime()); setInterpolatedTime(getInterpolatedTime());
@ -136,11 +137,11 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
/** Rescale the instance. /** Rescale the instance.
* <p>Since the scaled and Nordiseck arrays are shared with the caller, * <p>Since the scaled and Nordiseck arrays are shared with the caller,
* this method has the side effect of rescaling this arrays in the caller too.</p> * this method has the side effect of rescaling this arrays in the caller too.</p>
* @param scalingH new step size to use in the scaled and nordsieck arrays * @param stepSize new step size to use in the scaled and nordsieck arrays
*/ */
public void rescale(final double scalingH) { public void rescale(final double stepSize) {
final double ratio = scalingH / this.scalingH; final double ratio = stepSize / scalingH;
for (int i = 0; i < scaled.length; ++i) { for (int i = 0; i < scaled.length; ++i) {
scaled[i] *= ratio; scaled[i] *= ratio;
} }
@ -155,7 +156,7 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
} }
} }
this.scalingH = scalingH; scalingH = stepSize;
} }

View File

@ -246,8 +246,8 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void setConvergenceChecker(RealConvergenceChecker checker) { public void setConvergenceChecker(RealConvergenceChecker convergenceChecker) {
this.checker = checker; this.checker = convergenceChecker;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -256,9 +256,9 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public RealPointValuePair optimize(final MultivariateRealFunction f, public RealPointValuePair optimize(final MultivariateRealFunction function,
final GoalType goalType, final GoalType goalType,
final double[] startPoint) final double[] startPoint)
throws FunctionEvaluationException, OptimizationException, throws FunctionEvaluationException, OptimizationException,
IllegalArgumentException { IllegalArgumentException {
@ -270,7 +270,7 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
setStartConfiguration(unit); setStartConfiguration(unit);
} }
this.f = f; this.f = function;
final Comparator<RealPointValuePair> comparator = final Comparator<RealPointValuePair> comparator =
new Comparator<RealPointValuePair>() { new Comparator<RealPointValuePair>() {
public int compare(final RealPointValuePair o1, public int compare(final RealPointValuePair o1,

View File

@ -79,16 +79,16 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
protected int rows; protected int rows;
/** Objective function. */ /** Objective function. */
private DifferentiableMultivariateVectorialFunction f; private DifferentiableMultivariateVectorialFunction function;
/** Objective function derivatives. */ /** Objective function derivatives. */
private MultivariateMatrixFunction jF; private MultivariateMatrixFunction jF;
/** Target value for the objective functions at optimum. */ /** Target value for the objective functions at optimum. */
protected double[] target; protected double[] targetValues;
/** Weight for the least squares cost computation. */ /** Weight for the least squares cost computation. */
protected double[] weights; protected double[] residualsWeights;
/** Current point. */ /** Current point. */
protected double[] point; protected double[] point;
@ -148,8 +148,8 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void setConvergenceChecker(VectorialConvergenceChecker checker) { public void setConvergenceChecker(VectorialConvergenceChecker convergenceChecker) {
this.checker = checker; this.checker = convergenceChecker;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -182,7 +182,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
} }
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
final double[] ji = jacobian[i]; final double[] ji = jacobian[i];
final double factor = -Math.sqrt(weights[i]); final double factor = -Math.sqrt(residualsWeights[i]);
for (int j = 0; j < cols; ++j) { for (int j = 0; j < cols; ++j) {
ji[j] *= factor; ji[j] *= factor;
} }
@ -202,16 +202,16 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations), throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations),
point); point);
} }
objective = f.value(point); objective = function.value(point);
if (objective.length != rows) { if (objective.length != rows) {
throw new FunctionEvaluationException(point, "dimension mismatch {0} != {1}", throw new FunctionEvaluationException(point, "dimension mismatch {0} != {1}",
objective.length, rows); objective.length, rows);
} }
cost = 0; cost = 0;
for (int i = 0, index = 0; i < rows; i++, index += cols) { for (int i = 0, index = 0; i < rows; i++, index += cols) {
final double residual = target[i] - objective[i]; final double residual = targetValues[i] - objective[i];
residuals[i] = residual; residuals[i] = residual;
cost += weights[i] * residual * residual; cost += residualsWeights[i] * residual * residual;
} }
cost = Math.sqrt(cost); cost = Math.sqrt(cost);
@ -231,7 +231,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
double criterion = 0; double criterion = 0;
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
final double residual = residuals[i]; final double residual = residuals[i];
criterion += weights[i] * residual * residual; criterion += residualsWeights[i] * residual * residual;
} }
return Math.sqrt(criterion / rows); return Math.sqrt(criterion / rows);
} }
@ -244,7 +244,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
double chiSquare = 0; double chiSquare = 0;
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
final double residual = residuals[i]; final double residual = residuals[i];
chiSquare += residual * residual / weights[i]; chiSquare += residual * residual / residualsWeights[i];
} }
return chiSquare; return chiSquare;
} }
@ -329,12 +329,12 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
jacobianEvaluations = 0; jacobianEvaluations = 0;
// store least squares problem characteristics // store least squares problem characteristics
this.f = f; function = f;
jF = f.jacobian(); jF = f.jacobian();
this.target = target.clone(); targetValues = target.clone();
this.weights = weights.clone(); residualsWeights = weights.clone();
this.point = startPoint.clone(); this.point = startPoint.clone();
this.residuals = new double[target.length]; this.residuals = new double[target.length];
// arrays shared with the other private methods // arrays shared with the other private methods
rows = target.length; rows = target.length;

View File

@ -61,13 +61,13 @@ public abstract class AbstractScalarDifferentiableOptimizer
protected RealConvergenceChecker checker; protected RealConvergenceChecker checker;
/** Objective function. */ /** Objective function. */
private DifferentiableMultivariateRealFunction f; private DifferentiableMultivariateRealFunction function;
/** Objective function gradient. */ /** Objective function gradient. */
private MultivariateVectorialFunction gradient; private MultivariateVectorialFunction gradient;
/** Type of optimization. */ /** Type of optimization. */
protected GoalType goalType; protected GoalType goal;
/** Current point set. */ /** Current point set. */
protected double[] point; protected double[] point;
@ -118,8 +118,8 @@ public abstract class AbstractScalarDifferentiableOptimizer
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void setConvergenceChecker(RealConvergenceChecker checker) { public void setConvergenceChecker(RealConvergenceChecker convergenceChecker) {
this.checker = checker; this.checker = convergenceChecker;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -140,31 +140,31 @@ public abstract class AbstractScalarDifferentiableOptimizer
/** /**
* Compute the gradient vector. * Compute the gradient vector.
* @param point point at which the gradient must be evaluated * @param evaluationPoint point at which the gradient must be evaluated
* @return gradient at the specified point * @return gradient at the specified point
* @exception FunctionEvaluationException if the function gradient * @exception FunctionEvaluationException if the function gradient
*/ */
protected double[] computeObjectiveGradient(final double[] point) protected double[] computeObjectiveGradient(final double[] evaluationPoint)
throws FunctionEvaluationException { throws FunctionEvaluationException {
++gradientEvaluations; ++gradientEvaluations;
return gradient.value(point); return gradient.value(evaluationPoint);
} }
/** /**
* Compute the objective function value. * Compute the objective function value.
* @param point point at which the objective function must be evaluated * @param evaluationPoint point at which the objective function must be evaluated
* @return objective function value at specified point * @return objective function value at specified point
* @exception FunctionEvaluationException if the function cannot be evaluated * @exception FunctionEvaluationException if the function cannot be evaluated
* or its dimension doesn't match problem dimension or the maximal number * or its dimension doesn't match problem dimension or the maximal number
* of iterations is exceeded * of iterations is exceeded
*/ */
protected double computeObjectiveValue(final double[] point) protected double computeObjectiveValue(final double[] evaluationPoint)
throws FunctionEvaluationException { throws FunctionEvaluationException {
if (++evaluations > maxEvaluations) { if (++evaluations > maxEvaluations) {
throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations), throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations),
point); evaluationPoint);
} }
return f.value(point); return function.value(evaluationPoint);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -179,10 +179,10 @@ public abstract class AbstractScalarDifferentiableOptimizer
gradientEvaluations = 0; gradientEvaluations = 0;
// store optimization problem characteristics // store optimization problem characteristics
this.f = f; function = f;
gradient = f.gradient(); gradient = f.gradient();
this.goalType = goalType; goal = goalType;
point = startPoint.clone(); point = startPoint.clone();
return doOptimize(); return doOptimize();

View File

@ -81,8 +81,8 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
final double[] grad = jacobian[i]; final double[] grad = jacobian[i];
final double weight = weights[i]; final double weight = residualsWeights[i];
final double residual = objective[i] - target[i]; final double residual = objective[i] - targetValues[i];
// compute the normal equation // compute the normal equation
final double wr = weight * residual; final double wr = weight * residual;

View File

@ -83,12 +83,12 @@ public class NonLinearConjugateGradientOptimizer
/** /**
* Set the solver to use during line search. * Set the solver to use during line search.
* @param solver solver to use during line search, may be null * @param lineSearchSolver solver to use during line search, may be null
* to remove an already registered solver and fall back to the * to remove an already registered solver and fall back to the
* default {@link BrentSolver Brent solver}. * default {@link BrentSolver Brent solver}.
*/ */
public void setLineSearchSolver(final UnivariateRealSolver solver) { public void setLineSearchSolver(final UnivariateRealSolver lineSearchSolver) {
this.solver = solver; this.solver = lineSearchSolver;
} }
/** /**
@ -124,7 +124,7 @@ public class NonLinearConjugateGradientOptimizer
} }
final int n = point.length; final int n = point.length;
double[] r = computeObjectiveGradient(point); double[] r = computeObjectiveGradient(point);
if (goalType == GoalType.MINIMIZE) { if (goal == GoalType.MINIMIZE) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
r[i] = -r[i]; r[i] = -r[i];
} }
@ -168,7 +168,7 @@ public class NonLinearConjugateGradientOptimizer
point[i] += step * searchDirection[i]; point[i] += step * searchDirection[i];
} }
r = computeObjectiveGradient(point); r = computeObjectiveGradient(point);
if (goalType == GoalType.MINIMIZE) { if (goal == GoalType.MINIMIZE) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
r[i] = -r[i]; r[i] = -r[i];
} }

View File

@ -44,16 +44,16 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
private int iterations; private int iterations;
/** Linear objective function. */ /** Linear objective function. */
protected LinearObjectiveFunction f; protected LinearObjectiveFunction function;
/** Linear constraints. */ /** Linear constraints. */
protected Collection<LinearConstraint> constraints; protected Collection<LinearConstraint> linearConstraints;
/** Type of optimization goal: either {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}. */ /** Type of optimization goal: either {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}. */
protected GoalType goalType; protected GoalType goal;
/** Whether to restrict the variables to non-negative values. */ /** Whether to restrict the variables to non-negative values. */
protected boolean restrictToNonNegative; protected boolean nonNegative;
/** 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>
@ -95,10 +95,10 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
throws OptimizationException { throws OptimizationException {
// store linear problem characteristics // store linear problem characteristics
this.f = f; this.function = f;
this.constraints = constraints; this.linearConstraints = constraints;
this.goalType = goalType; this.goal = goalType;
this.restrictToNonNegative = restrictToNonNegative; this.nonNegative = restrictToNonNegative;
iterations = 0; iterations = 0;

View File

@ -184,7 +184,7 @@ public class SimplexSolver extends AbstractLinearOptimizer {
public RealPointValuePair doOptimize() public RealPointValuePair doOptimize()
throws OptimizationException { throws OptimizationException {
final SimplexTableau tableau = final SimplexTableau tableau =
new SimplexTableau(f, constraints, goalType, restrictToNonNegative, epsilon); new SimplexTableau(function, linearConstraints, goal, nonNegative, epsilon);
solvePhase1(tableau); solvePhase1(tableau);
tableau.discardArtificialVariables(); tableau.discardArtificialVariables();
while (!isOptimal(tableau)) { while (!isOptimal(tableau)) {

View File

@ -192,12 +192,12 @@ class SimplexTableau implements Serializable {
/** /**
* Get new versions of the constraints which have positive right hand sides. * Get new versions of the constraints which have positive right hand sides.
* @param constraints original (not normalized) constraints * @param originalConstraints original (not normalized) constraints
* @return new versions of the constraints * @return new versions of the constraints
*/ */
public List<LinearConstraint> normalizeConstraints(Collection<LinearConstraint> constraints) { public List<LinearConstraint> normalizeConstraints(Collection<LinearConstraint> originalConstraints) {
List<LinearConstraint> normalized = new ArrayList<LinearConstraint>(); List<LinearConstraint> normalized = new ArrayList<LinearConstraint>();
for (LinearConstraint constraint : constraints) { for (LinearConstraint constraint : originalConstraints) {
normalized.add(normalize(constraint)); normalized.add(normalize(constraint));
} }
return normalized; return normalized;

View File

@ -183,8 +183,7 @@ public class RandomDataImpl implements RandomData, Serializable {
"upper bound ({0}) must be greater than lower bound ({1})", "upper bound ({0}) must be greater than lower bound ({1})",
upper, lower); upper, lower);
} }
RandomGenerator rand = getRan(); double r = getRan().nextDouble();
double r = rand.nextDouble();
return (int) ((r * upper) + ((1.0 - r) * lower) + r); return (int) ((r * upper) + ((1.0 - r) * lower) + r);
} }
@ -204,8 +203,7 @@ public class RandomDataImpl implements RandomData, Serializable {
"upper bound ({0}) must be greater than lower bound ({1})", "upper bound ({0}) must be greater than lower bound ({1})",
upper, lower); upper, lower);
} }
RandomGenerator rand = getRan(); double r = getRan().nextDouble();
double r = rand.nextDouble();
return (long) ((r * upper) + ((1.0 - r) * lower) + r); return (long) ((r * upper) + ((1.0 - r) * lower) + r);
} }
@ -356,7 +354,7 @@ public class RandomDataImpl implements RandomData, Serializable {
"the Poisson mean must be positive ({0})", mean); "the Poisson mean must be positive ({0})", mean);
} }
RandomGenerator rand = getRan(); final RandomGenerator generator = getRan();
double pivot = 6.0; double pivot = 6.0;
if (mean < pivot) { if (mean < pivot) {
@ -366,7 +364,7 @@ public class RandomDataImpl implements RandomData, Serializable {
double rnd = 1.0d; double rnd = 1.0d;
while (n < 1000 * mean) { while (n < 1000 * mean) {
rnd = rand.nextDouble(); rnd = generator.nextDouble();
r = r * rnd; r = r * rnd;
if (r >= p) { if (r >= p) {
n++; n++;
@ -458,8 +456,7 @@ public class RandomDataImpl implements RandomData, Serializable {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"standard deviation must be positive ({0})", sigma); "standard deviation must be positive ({0})", sigma);
} }
RandomGenerator rand = getRan(); return sigma * getRan().nextGaussian() + mu;
return sigma * rand.nextGaussian() + mu;
} }
/** /**
@ -481,10 +478,10 @@ public class RandomDataImpl implements RandomData, Serializable {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"mean must be positive ({0})", mean); "mean must be positive ({0})", mean);
} }
RandomGenerator rand = getRan(); final RandomGenerator generator = getRan();
double unif = rand.nextDouble(); double unif = generator.nextDouble();
while (unif == 0.0d) { while (unif == 0.0d) {
unif = rand.nextDouble(); unif = generator.nextDouble();
} }
return -mean * Math.log(unif); return -mean * Math.log(unif);
} }
@ -511,12 +508,12 @@ public class RandomDataImpl implements RandomData, Serializable {
"upper bound ({0}) must be greater than lower bound ({1})", "upper bound ({0}) must be greater than lower bound ({1})",
upper, lower); upper, lower);
} }
RandomGenerator rand = getRan(); final RandomGenerator generator = getRan();
// ensure nextDouble() isn't 0.0 // ensure nextDouble() isn't 0.0
double u = rand.nextDouble(); double u = generator.nextDouble();
while (u <= 0.0) { while (u <= 0.0) {
u = rand.nextDouble(); u = generator.nextDouble();
} }
return lower + u * (upper - lower); return lower + u * (upper - lower);

View File

@ -124,11 +124,11 @@ public class SpearmansCorrelation {
* input rectangular array. The columns of the array represent values * input rectangular array. The columns of the array represent values
* of variables to be correlated. * of variables to be correlated.
* *
* @param data matrix with columns representing variables to correlate * @param matrix matrix with columns representing variables to correlate
* @return correlation matrix * @return correlation matrix
*/ */
public RealMatrix computeCorrelationMatrix(double[][] data) { public RealMatrix computeCorrelationMatrix(double[][] matrix) {
return computeCorrelationMatrix(new BlockRealMatrix(data)); return computeCorrelationMatrix(new BlockRealMatrix(matrix));
} }
/** /**

View File

@ -481,10 +481,10 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
} }
/** /**
* @param isBiasCorrected The isBiasCorrected to set. * @param biasCorrected The isBiasCorrected to set.
*/ */
public void setBiasCorrected(boolean isBiasCorrected) { public void setBiasCorrected(boolean biasCorrected) {
this.isBiasCorrected = isBiasCorrected; this.isBiasCorrected = biasCorrected;
} }
/** /**

View File

@ -53,11 +53,11 @@ public class TestUtils {
/** /**
* Set the (singleton) TTest instance. * Set the (singleton) TTest instance.
* *
* @param tTest the new instance to use * @param chiSquareTest the new instance to use
* @since 1.2 * @since 1.2
*/ */
public static void setChiSquareTest(TTest tTest) { public static void setChiSquareTest(TTest chiSquareTest) {
TestUtils.tTest = tTest; TestUtils.tTest = chiSquareTest;
} }
/** /**

View File

@ -337,35 +337,33 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
* IllegalArgumentException if the contractionCriteria is less than the * IllegalArgumentException if the contractionCriteria is less than the
* expansionCriteria * expansionCriteria
* *
* @param expansionFactor factor to be checked * @param expansion factor to be checked
* @param contractionCriteria criteria to be checked * @param contraction criteria to be checked
* @throws IllegalArgumentException if the contractionCriteria is less than * @throws IllegalArgumentException if the contractionCriteria is less than
* the expansionCriteria. * the expansionCriteria.
*/ */
protected void checkContractExpand( protected void checkContractExpand(float contraction, float expansion) {
float contractionCriteria,
float expansionFactor) {
if (contractionCriteria < expansionFactor) { if (contraction < expansion) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"contraction criteria ({0}) smaller than the expansion factor ({1}). This would " + "contraction criteria ({0}) smaller than the expansion factor ({1}). This would " +
"lead to a never ending loop of expansion and contraction as a newly expanded " + "lead to a never ending loop of expansion and contraction as a newly expanded " +
"internal storage array would immediately satisfy the criteria for contraction", "internal storage array would immediately satisfy the criteria for contraction",
contractionCriteria, expansionFactor); contraction, expansion);
} }
if (contractionCriteria <= 1.0) { if (contraction <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"contraction criteria smaller than one ({0}). This would lead to a never ending " + "contraction criteria smaller than one ({0}). This would lead to a never ending " +
"loop of expansion and contraction as an internal storage array length equal " + "loop of expansion and contraction as an internal storage array length equal " +
"to the number of elements would satisfy the contraction criteria.", "to the number of elements would satisfy the contraction criteria.",
contractionCriteria); contraction);
} }
if (expansionFactor <= 1.0) { if (expansion <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"expansion factor smaller than one ({0})", "expansion factor smaller than one ({0})",
expansionFactor); expansion);
} }
} }

View File

@ -32,8 +32,8 @@ public class DummyBinaryChromosome extends BinaryChromosome {
} }
@Override @Override
public AbstractListChromosome<Integer> newFixedLengthChromosome(List<Integer> representation) { public AbstractListChromosome<Integer> newFixedLengthChromosome(List<Integer> chromosomeRepresentation) {
return new DummyBinaryChromosome(representation); return new DummyBinaryChromosome(chromosomeRepresentation);
} }
public double fitness() { public double fitness() {

View File

@ -32,8 +32,8 @@ public class DummyRandomKey extends RandomKey<String> {
} }
@Override @Override
public AbstractListChromosome<Double> newFixedLengthChromosome(List<Double> representation) { public AbstractListChromosome<Double> newFixedLengthChromosome(List<Double> chromosomeRepresentation) {
return new DummyRandomKey(representation); return new DummyRandomKey(chromosomeRepresentation);
} }
public double fitness() { public double fitness() {

View File

@ -113,8 +113,8 @@ public class GeneticAlgorithmTestBinary {
} }
@Override @Override
public AbstractListChromosome<Integer> newFixedLengthChromosome(List<Integer> representation) { public AbstractListChromosome<Integer> newFixedLengthChromosome(List<Integer> chromosomeRepresentation) {
return new FindOnes(representation); return new FindOnes(chromosomeRepresentation);
} }
} }

View File

@ -124,8 +124,8 @@ public class GeneticAlgorithmTestPermutations {
} }
@Override @Override
public AbstractListChromosome<Double> newFixedLengthChromosome(List<Double> representation) { public AbstractListChromosome<Double> newFixedLengthChromosome(List<Double> chromosomeRepresentation) {
return new MinPermutations(representation); return new MinPermutations(chromosomeRepresentation);
} }
} }
} }