diff --git a/src/main/java/eva2/tools/math/Mathematics.java b/src/main/java/eva2/tools/math/Mathematics.java
index efbccfbd..380da272 100644
--- a/src/main/java/eva2/tools/math/Mathematics.java
+++ b/src/main/java/eva2/tools/math/Mathematics.java
@@ -4,9 +4,6 @@ import Jama.Matrix;
import eva2.optimization.tools.DoubleArrayComparator;
import eva2.tools.EVAERROR;
import eva2.tools.Pair;
-import eva2.tools.math.interpolation.BasicDataSet;
-import eva2.tools.math.interpolation.InterpolationException;
-import eva2.tools.math.interpolation.SplineInterpolation;
import java.util.Arrays;
import java.util.List;
@@ -1099,29 +1096,6 @@ public final class Mathematics {
}
}
- /**
- * Computes a spline interpolation of the two point (x0,f0) and (x1,f1).
- *
- * @param x
- * @param x0
- * @param x1
- * @param f0
- * @param f1
- * @return If an error with the spline occurs, a linear interpolation will
- * be returned.
- */
- public static double splineInterpolation(double x, double x0, double x1,
- double f0, double f1) {
- try {
- double[] t = {x0, x1}, f = {f0, f1};
- SplineInterpolation spline = new SplineInterpolation(
- new BasicDataSet(t, f, 1));
- return spline.getY(x);
- } catch (InterpolationException e) {
- e.printStackTrace();
- }
- return linearInterpolation(x, x0, x1, f0, f1);
- }
/**
* This computes the submatrix of the given matrix as a result by scraching
diff --git a/src/main/java/eva2/tools/math/interpolation/AbstractDataModifier.java b/src/main/java/eva2/tools/math/interpolation/AbstractDataModifier.java
deleted file mode 100644
index 9f4bc9fb..00000000
--- a/src/main/java/eva2/tools/math/interpolation/AbstractDataModifier.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package eva2.tools.math.interpolation;
-
-/**
- * The minimal set of functions which should implemented in a data modifier for
- * AbstractDataSet
.
- */
-public abstract class AbstractDataModifier {
-
- /**
- * Modifies the X data.
- */
- public abstract void modifyX(double[] setX);
-
- /**
- * Modifies the Y data.
- */
- public abstract void modifyY(double[] setY);
-
- /**
- * Modifies the data.
- */
- public abstract void modify(double[] setX, double[] setY);
-}
\ No newline at end of file
diff --git a/src/main/java/eva2/tools/math/interpolation/AbstractDataSet.java b/src/main/java/eva2/tools/math/interpolation/AbstractDataSet.java
deleted file mode 100644
index b751fc58..00000000
--- a/src/main/java/eva2/tools/math/interpolation/AbstractDataSet.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package eva2.tools.math.interpolation;
-
-public abstract class AbstractDataSet {
- /**
- * double array of X data.
- *
- * @see #yDoubleData
- */
- protected double[] xDoubleData = {-1, 1};
- /**
- * double array of Y data.
- *
- * @see #xDoubleData
- */
- protected double[] yDoubleData = {1, 1};
-
- /**
- * Returns the length of the data set
- *
- * @return the length of the data set
- */
- public int getLength() {
- return xDoubleData.length;
- }
-
- /**
- * Returns an array of the X data
- *
- * @return the array of the X data
- */
- public double[] getXData() {
- return xDoubleData;
- }
-
- /**
- * Returns an array of the Y data
- *
- * @return the array of the Y data
- */
- public double[] getYData() {
- return yDoubleData;
- }
-
- /**
- * Returns the X label of the data set
- *
- * @return the X label of the data set
- */
- public abstract String getXLabel();
-
- /**
- * Returns the Y label of the data set
- *
- * @return the Y label of the data set
- */
- public abstract String getYLabel();
-
- /**
- * Modifies the X data.
- *
- * @param modifier the data modifier
- */
- public void modifyXData(AbstractDataModifier modifier) {
- modifier.modifyX(xDoubleData);
- }
-
- /**
- * Modifies the Y data.
- *
- * @param modifier the data modifier
- */
- public void modifyYData(AbstractDataModifier modifier) {
- modifier.modifyY(yDoubleData);
- }
-
- /**
- * Modifies the data.
- *
- * @param modifier the data modifier
- */
- public void modifyData(AbstractDataModifier modifier) {
- modifier.modify(xDoubleData, yDoubleData);
- }
-}
diff --git a/src/main/java/eva2/tools/math/interpolation/BasicDataSet.java b/src/main/java/eva2/tools/math/interpolation/BasicDataSet.java
deleted file mode 100644
index adee202e..00000000
--- a/src/main/java/eva2/tools/math/interpolation/BasicDataSet.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package eva2.tools.math.interpolation;
-
-/**
- * The minimum wrapper class for an AbstractDataSet
.
- */
-public class BasicDataSet extends AbstractDataSet {
- protected int dataType = -1;
- protected String xLabel = null;
- protected String yLabel = null;
-
- public BasicDataSet() {
- this(null, null, null, null);
- }
-
- public BasicDataSet(
- double[] xDoubleData,
- double[] yDoubleData,
- int dataType) {
- this(xDoubleData, yDoubleData, null, null);
- }
-
- public BasicDataSet(
- double[] xDoubleData,
- double[] yDoubleData,
- String xLabel,
- String yLabel) {
- this.xDoubleData = xDoubleData;
- this.yDoubleData = yDoubleData;
- this.xLabel = xLabel;
- this.yLabel = yLabel;
- }
-
- public int getDataType() {
- return dataType;
- }
-
- @Override
- public String getXLabel() {
- return xLabel;
- }
-
- @Override
- public String getYLabel() {
- return yLabel;
- }
-
- public String getAdditionalInformation(String parm1) {
- return "";
- }
-}
diff --git a/src/main/java/eva2/tools/math/interpolation/InterpolationException.java b/src/main/java/eva2/tools/math/interpolation/InterpolationException.java
deleted file mode 100644
index 7d6363fc..00000000
--- a/src/main/java/eva2/tools/math/interpolation/InterpolationException.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package eva2.tools.math.interpolation;
-/**
- * Exception for interpolation error.
- */
-public class InterpolationException extends Exception {
-
- public InterpolationException() {
- super();
- }
-
- public InterpolationException(String s) {
- super(s);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eva2/tools/math/interpolation/LinearInterpolation.java b/src/main/java/eva2/tools/math/interpolation/LinearInterpolation.java
deleted file mode 100644
index 7280dde9..00000000
--- a/src/main/java/eva2/tools/math/interpolation/LinearInterpolation.java
+++ /dev/null
@@ -1,522 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// Filename: $RCSfile: LinearInterpolation.java,v $
-// Purpose: Some interpolation stuff.
-// Language: Java
-// Compiler: JDK 1.4
-// Authors: Joerg K. Wegner
-// Original author: Charles S. Stanton
-// Version: $Revision: 1.1 $
-// $Date: 2003/07/22 19:25:23 $
-// $Author: wegnerj $
-//
-// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
-//
-///////////////////////////////////////////////////////////////////////////////
-
-package eva2.tools.math.interpolation;
-
-/**
- * Defines the routines for the spline interpolation of data.
- */
-public class LinearInterpolation {
- AbstractDataSet abstractDataSet = null;
- private double[] x, y;
- //vectors of x,y
- private double sumX = 0;
- private double sumY = 0;
- private double sumXY = 0;
- private double sumXsquared = 0;
- private double sumYsquared = 0;
- private double Sxx, Sxy, Syy, n;
- private double a = 0, b = 0;
- //coefficients of regression
- private int dataLength;
- private double[][] residual;
- // residual[0][i] = x[i], residual[1][i]= residual
- private double maxAbsoluteResidual = 0.0;
- private double SSR = 0.0;
- //regression sum of squares
- private double SSE = 0.0;
- //error sum of squares
- private double minX = Double.POSITIVE_INFINITY;
- private double maxX = Double.NEGATIVE_INFINITY;
- private double minY = Double.POSITIVE_INFINITY;
- private double maxY = Double.NEGATIVE_INFINITY;
-
- //MISC
- String xName, yName;
- double aCILower, aCIUpper, bCILower, bCIUpper; //confidence interval
- double t, bSE, aSE;
- double MSE, F;
- static double[] t025 =
- {
- Double.NaN,
- 12.706,
- 4.303,
- 3.182,
- 2.776,
- 2.571,
- 2.447,
- 2.365,
- 2.306,
- 2.262,
- 2.228,
- 2.201,
- 2.179,
- 2.160,
- 2.145,
- 2.131,
- 2.120,
- 2.110,
- 2.101,
- 2.093,
- 2.086,
- 2.080,
- 2.075,
- 2.069,
- 2.064,
- 2.060,
- 2.056,
- 2.052,
- 2.048,
- 2.045,
- 1.960};
-
- /*------------------------------------------------------------------------*
- * constructor
- *------------------------------------------------------------------------*/
-
- /**
- * Initializes this class.
- */
- public LinearInterpolation() throws InterpolationException {
- this.abstractDataSet = null;
- }
-
- /**
- * Constructor for regression calculator.
- *
- * @param x is the array of x data
- * @param y is the array of y data
- */
- public LinearInterpolation(double[] x, double[] y) {
- this.x = x;
- this.y = y;
- if (x.length != y.length) {
- System.out.println("x, y vectors must be of same length");
- } else {
- dataLength = x.length;
- doStatistics();
- }
-
- }
-
- /**
- * Initializes this class and calculates the second derivative of the spline.
- *
- * @param abstractDataSet the AbstractDataSet
- */
- public LinearInterpolation(AbstractDataSet abstractDataSet)
- throws InterpolationException {
- this.setAbstractDataSet(abstractDataSet);
- }
-
- public void setAbstractDataSet(AbstractDataSet abstractDataSet)
- throws InterpolationException {
- this.abstractDataSet = abstractDataSet;
- x = abstractDataSet.getXData();
- y = abstractDataSet.getYData();
- if (x.length != y.length) {
- System.out.println("x, y vectors must be of same length");
- } else {
- dataLength = x.length;
- doStatistics();
- }
- }
-
- /**
- * Find the p value for a given value of F.
- * Requires the COLT high performance library:
- * http://hoschek.home.cern.ch/hoschek/colt/
- *
- * @param fValue the value for the CDF
- * @return The P value
- */
- // public double getP(double fValue) {
- // double answer;
- // double y1;
- // double y2;
- // //nu1 = 1;
- // //x2 =1
- // double nu2 = n - 2;
- // y1 = nu2 / (nu2 + fValue);
- // y2 = 0.0;
- // answer = Gamma.incompleteBeta(nu2 / 2.0, 1 / 2.0, y1)
- // - Gamma.incompleteBeta(nu2 / 2.0, 1 / 2.0, y2);
- // return answer;
- // }
-
- /*
- * Here are the accessor methods
- *
- */
-
- /**
- * Gets the intercept of the regression line.
- *
- * @return The intercept.
- */
- public double getIntercept() {
- return a;
- }
-
- /**
- * Gets the Slope of the regression line.
- *
- * @return The slope.
- */
- public double getSlope() {
- return b;
- }
-
- /**
- * Gets the residuals of the regression.
- *
- * @return The residuals.
- */
- public double[][] getResiduals() {
- return residual;
- }
-
- /**
- * Gets the x data for the regression.
- *
- * @return The array of x values.
- */
- public double[] getDataX() {
- return x;
- }
-
- /**
- * Gets the y data for the regression.
- *
- * @return The array of y values.
- */
- public double[] getDataY() {
- return y;
- }
-
- /**
- * Gets the minimum of the x values.
- *
- * @return The minimum.
- */
- public double getMinX() {
- return minX;
- }
-
- /**
- * Gets the maximum of the x values.
- *
- * @return The maximum.
- */
- public double getMaxX() {
- return maxX;
- }
-
- /**
- * Gets the minimum of the y values.
- *
- * @return The minumum.
- */
- public double getMinY() {
- return minY;
- }
-
- /**
- * Gets the maximum of the y values.
- *
- * @return The maximum.
- */
- public double getMaxY() {
- return maxY;
- }
-
- /**
- * Gets the maximum absolute residual.
- *
- * @return The maximum.
- */
- public double getMaxAbsoluteResidual() {
- return maxAbsoluteResidual;
- }
-
- /**
- * Gets the sum of the square x deviations from mean of x.
- *
- * @return The Sxx value
- */
- public double getSxx() {
- return Sxx;
- }
-
- /**
- * Gets the sum of the square y deviations from mean of y.
- *
- * @return The Syy value
- */
- public double getSyy() {
- return Syy;
- }
-
- /**
- * Gets SSR = Sxy * Sxy / Sxx;
- *
- * @return The SSR value
- */
- public double getSSR() {
- return SSR;
- }
-
- /**
- * Gets SSE = Syy - SSR.
- *
- * @return The SSE value
- */
- public double getSSE() {
- return SSE;
- }
-
- /**
- * Gets the mean square error MSE.
- *
- * @return The MSE value
- */
- public double getMSE() {
- return SSE / (n - 2);
- }
-
- /**
- * Gets the mean XBar of x.
- *
- * @return The XBar value
- */
- public double getXBar() {
- return sumX / n;
- }
-
- /**
- * Gets the mean YBar of y.
- *
- * @return The YBar value
- */
- public double getYBar() {
- return sumY / n;
- }
-
- /**
- * Gets the sample size.
- *
- * @return The sample size.
- */
- public int getDataLength() {
- return x.length;
- }
-
- /**
- * Gets the Pearson R statistic of the regression.
- *
- * @return The PearsonR value
- */
- public double getPearsonR() {
- return Sxy / Math.sqrt(Sxx * Syy);
- }
-
- /**
- * Gets the sum of the x squared values.
- *
- * @return The sum of the x squared values.
- */
- public double getSumXSquared() {
- return sumXsquared;
- }
-
- /**
- * reset data to 0
- */
- public void reset() {
- x = new double[0];
- y = new double[0];
- dataLength = 0;
- n = 0.0;
- residual = new double[0][0];
-
- sumX = 0;
- sumXsquared = 0;
- sumY = 0;
- sumYsquared = 0;
- sumXY = 0;
-
- }
-
- /**
- * Adds a new point to the regression (for interactive use).
- *
- * @param xValue The new x value
- * @param yValue The new y value
- */
- public void addPoint(double xValue, double yValue) {
- dataLength++;
- double[] xNew = new double[dataLength];
- double[] yNew = new double[dataLength];
- System.arraycopy(x, 0, xNew, 0, dataLength - 1);
- System.arraycopy(y, 0, yNew, 0, dataLength - 1);
- xNew[dataLength - 1] = xValue;
- yNew[dataLength - 1] = yValue;
- x = xNew;
- y = yNew;
- updateStatistics(xValue, yValue);
- }
-
- private void doStatistics() {
- //Find sum of squares for x,y and sum of xy
- for (int i = 0; i < dataLength; i++) {
- minX = Math.min(minX, x[i]);
- maxX = Math.max(maxX, x[i]);
- minY = Math.min(minY, y[i]);
- maxY = Math.max(maxY, y[i]);
- sumX += x[i];
- sumY += y[i];
- sumXsquared += x[i] * x[i];
- sumYsquared += y[i] * y[i];
- sumXY += x[i] * y[i];
- }
- //Caculate regression coefficients
- n = (double) dataLength;
- Sxx = sumXsquared - sumX * sumX / n;
- Syy = sumYsquared - sumY * sumY / n;
- Sxy = sumXY - sumX * sumY / n;
- b = Sxy / Sxx;
- a = (sumY - b * sumX) / n;
- SSR = Sxy * Sxy / Sxx;
- SSE = Syy - SSR;
- calculateResiduals();
- }
-
- private void calculateResiduals() {
- residual = new double[2][dataLength];
- maxAbsoluteResidual = 0.0;
- for (int i = 0; i < dataLength; i++) {
- residual[0][i] = x[i];
- residual[1][i] = y[i] - (a + b * x[i]);
- maxAbsoluteResidual =
- Math.max(maxAbsoluteResidual, Math.abs(y[i] - (a + b * x[i])));
- }
- }
-
- //update statistics for a single additional data point
- private void updateStatistics(double xValue, double yValue) {
- //Find sum of squares for x,y and sum of xy
- n++;
- sumX += xValue;
- sumY += yValue;
- sumXsquared += xValue * xValue;
- sumYsquared += yValue * yValue;
- sumXY += xValue * yValue;
- //Caculate regression coefficients
- n = (double) dataLength;
- Sxx = sumXsquared - sumX * sumX / n;
- Syy = sumYsquared - sumY * sumY / n;
- Sxy = sumXY - sumX * sumY / n;
- b = Sxy / Sxx;
- a = (sumY - b * sumX) / n;
- SSR = Sxy * Sxy / Sxx;
- SSE = Syy - SSR;
- calculateResiduals();
- }
-
- /**
- * regression line y = a + bx.
- *
- * @param x
- * @return double
- * @throws InterpolationException
- */
- public double getY(double x) throws InterpolationException {
- return a + b * x;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(1000);
-
- sb.append("Regression Statistics for " + yName + " = a + b*" + xName);
- sb.append("");
- sb.append("Sample Statistics");
- int n = this.getDataLength();
- sb.append("Sample size n = " + n);
- sb.append("Mean of " + yName + " Y bar = " + this.getYBar());
- sb.append("s_Y");
- sb.append("= " + Math.sqrt(this.getSyy() / ((float) (n - 1))));
- sb.append("Pearson correlation R = " + this.getPearsonR());
- sb.append("");
- sb.append("Coefficient Estimates");
- a = this.getIntercept();
- b = this.getSlope();
- sb.append("a = " + a);
- sb.append("b = " + b);
- sb.append("");
-
- sb.append("95% Confidence Intervals");
-
- if (n > 32) {
- t = t025[30];
- } else if (n > 2) {
- t = t025[n - 2];
- } else {
- t = Double.NaN;
- }
- MSE = this.getMSE();
- if (n > 2) {
- bSE = Math.sqrt(MSE / this.getSxx());
- } else {
- bSE = Double.NaN;
- }
- aSE = bSE * Math.sqrt(this.getSumXSquared() / n);
- aCILower = a - t * aSE;
- aCIUpper = a + t * aSE;
- sb.append("a : (" + aCILower + ", " + aCIUpper + ")");
- bCILower = b - t * bSE;
- bCIUpper = b + t * bSE;
- sb.append("b : (" + bCILower + ", " + bCIUpper + ")");
- sb.append("");
- sb.append("Analysis of Variance");
- sb.append("Source Degrees Freedom Sum of Squares");
- sb.append("");
- SSR = this.getSSR();
- //allow one degree of freedom for mean
- sb.append(
- "model 1 "
- + SSR);
- sb.append(
- "error "
- + (n - 2)
- + " "
- + this.getSSE());
- sb.append(
- "total(corrected) "
- + (n - 1)
- + " "
- + this.getSyy());
- sb.append("");
- sb.append("MSE =" + MSE);
- F = SSR / MSE;
- sb.append("F = " + F + " ");
- //sb.append("p = " + this.getP(F));
-
- return sb.toString();
- }
-}
-/****************************************************************************
- * END OF FILE
- ****************************************************************************/
\ No newline at end of file
diff --git a/src/main/java/eva2/tools/math/interpolation/PolynomialInterpolationResult.java b/src/main/java/eva2/tools/math/interpolation/PolynomialInterpolationResult.java
deleted file mode 100644
index 43bc81e2..00000000
--- a/src/main/java/eva2/tools/math/interpolation/PolynomialInterpolationResult.java
+++ /dev/null
@@ -1,53 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// Filename: $RCSfile: PolynomialInterpolationResult.java,v $
-// Purpose: Some interpolation stuff.
-// Language: Java
-// Compiler: JDK 1.4
-// Authors: Joerg K. Wegner
-// Version: $Revision: 1.1 $
-// $Date: 2003/07/22 19:25:36 $
-// $Author: wegnerj $
-//
-// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
-//
-///////////////////////////////////////////////////////////////////////////////
-
-package eva2.tools.math.interpolation;
-
-/*==========================================================================*
- * IMPORTS
- *==========================================================================*/
-
-/*==========================================================================*
- * CLASS DECLARATION
- *==========================================================================*/
-
-/**
- * The result data for a polynomial interpolation.
- */
-public class PolynomialInterpolationResult {
- /*-------------------------------------------------------------------------*
- * public member variables
- *-------------------------------------------------------------------------*/
-
- public double y = Double.NaN;
- public double yError = Double.NaN;
-
- /*------------------------------------------------------------------------*
- * constructor
- *------------------------------------------------------------------------*/
-
- public PolynomialInterpolationResult() {
- y = Double.NaN;
- yError = Double.NaN;
- }
-
- public PolynomialInterpolationResult(double y, double yError) {
- this.y = y;
- this.yError = yError;
- }
-}
-
-/****************************************************************************
- * END OF FILE
- ****************************************************************************/
\ No newline at end of file
diff --git a/src/main/java/eva2/tools/math/interpolation/SplineInterpolation.java b/src/main/java/eva2/tools/math/interpolation/SplineInterpolation.java
deleted file mode 100644
index a4b61694..00000000
--- a/src/main/java/eva2/tools/math/interpolation/SplineInterpolation.java
+++ /dev/null
@@ -1,245 +0,0 @@
-package eva2.tools.math.interpolation;
-
-/**
- * Defines the routines for the spline interpolation of data.
- */
-public class SplineInterpolation {
- AbstractDataSet abstractDataSet = null;
- double[] secondDerivative = null;
- double[] xArray = null;
- double[] yArray = null;
- boolean ascendingData = true;
-
- /**
- * Initializes this class.
- */
- public SplineInterpolation() throws InterpolationException {
- }
-
- /**
- * Initializes this class and calculates the second derivative of the spline.
- *
- * @param abstractDataSet the AbstractDataSet
- */
- public SplineInterpolation(AbstractDataSet abstractDataSet)
- throws InterpolationException {
- this.setAbstractDataSet(abstractDataSet);
- }
-
- /**
- * Sets the new AbstractDataSet
and calculates the second
- * derivative of the spline.
- *
- * @param abstractDataSet the AbstractDataSet
- */
- public void setAbstractDataSet(AbstractDataSet abstractDataSet)
- throws InterpolationException {
- this.abstractDataSet = abstractDataSet;
- double[] x = abstractDataSet.getXData();
- double[] y = abstractDataSet.getYData();
- boolean ascending = false;
- int n = x.length;
-
- xArray = new double[n];
- yArray = new double[n];
- xArray[n - 1] = x[0];
- yArray[n - 1] = y[0];
- for (int i = 0; i < n - 1; i++) {
- xArray[i] = x[n - i - 1];
- yArray[i] = y[n - i - 1];
- if (x[i] < x[i + 1]) {
- //if(descending)throw new InterpolationException("The x values must be"+
- // " in continous ascending/descending order.");
- ascending = true;
- }
- }
- ascendingData = ascending;
-
- if (ascendingData) {
- xArray = abstractDataSet.getXData();
- yArray = abstractDataSet.getYData();
- }
- this.secondDerivative =
- spline(
- xArray,
- yArray,
- (yArray[1] - yArray[0]) / (xArray[1] - xArray[0]),
- (yArray[n - 1] - yArray[n - 2]) / (xArray[1] - xArray[n - 2]));
- }
-
- /**
- * Uses the spline with the calculated second derivative values to calculate
- * the y
value. This algorithm was taken from:
- *
- * William H. Press, Saul A. Teukolosky, William T. Vetterling, Brian P. Flannery,
- * "Numerical Recipes in C - The Art of Scientific Computing", Second Edition,
- * Cambridge University Press,
- * ISBN 0-521-43108-5,
- * chapter 5, pages 173-176.
- */
- public double getY(double x) throws InterpolationException {
- return splineInterpolation(xArray, yArray, secondDerivative, x);
- }
-
- public double getDerivative(double x) throws InterpolationException {
- return splineInterpolatedDerivative(
- xArray,
- yArray,
- secondDerivative,
- x);
- }
-
- /**
- * Calculates the second derivative of the data. It's important that the
- * xi values of the function yi=f(xi) are
- * in ascending order, as x0<x1<x2<... .
- * This algorithm was taken from:
- *
- * William H. Press, Saul A. Teukolosky, William T. Vetterling, Brian P. Flannery,
- * "Numerical Recipes in C - The Art of Scientific Computing", Second Edition,
- * Cambridge University Press,
- * ISBN 0-521-43108-5,
- * chapter 3, pages 113-116.
- */
- public double[] spline(double[] x, double[] y, double yp0, double ypn)
- throws InterpolationException {
- if (x[0] > x[1]) {
- throw new InterpolationException(
- "The x values must be" + " in ascending order.");
- }
- int n = x.length;
- double[] y2 = new double[n];
- double[] u = new double[n - 1];
- int i, k;
- double p, qn, sig, un;
-
- if (yp0 > 0.99e30) {
- y2[0] = u[0] = 0.0;
- } else {
- y2[0] = -0.5;
- u[0] =
- (3.0 / (x[1] - x[0])) * ((y[1] - y[0]) / (x[1] - x[0]) - yp0);
- }
- for (i = 2; i <= n - 1; i++) {
- sig = (x[i - 1] - x[i - 2]) / (x[i] - x[i - 2]);
- p = sig * y2[i - 2] + 2.0;
- y2[i - 1] = (sig - 1.0) / p;
- u[i - 1] =
- (y[i] - y[i - 1]) / (x[i] - x[i - 1])
- - (y[i - 1] - y[i - 2]) / (x[i - 1] - x[i - 2]);
- u[i - 1] =
- (6.0 * u[i - 1] / (x[i] - x[i - 2]) - sig * u[i - 2]) / p;
- }
- if (ypn > 0.99e30) {
- qn = un = 0.0;
- } else {
- qn = 0.5;
- un =
- (3.0 / (x[n - 1] - x[n - 2]))
- * (ypn - (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]));
- }
- y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
- for (k = n - 1; k >= 1; k--) {
- y2[k - 1] = y2[k - 1] * y2[k] + u[k - 1];
- }
-
- return y2;
- }
-
- /**
- * Calculates the second derivative of the data. This algorithm
- * was taken from:
- *
- * William H. Press, Saul A. Teukolosky, William T. Vetterling, Brian P. Flannery,
- * "Numerical Recipes in C - The Art of Scientific Computing", Second Edition,
- * Cambridge University Press,
- * ISBN 0-521-43108-5,
- * chapter 3, pages 113-116.
- */
- public double splineInterpolation(
- double[] xa,
- double[] ya,
- double[] y2a,
- double x)
- throws InterpolationException {
- int n = xa.length;
- if (n != ya.length || n != y2a.length) {
- throw new InterpolationException("Arrays have different lengths.");
- }
- double y;
- int klo, khi, k;
- double h, b, a;
-
- klo = 0;
- khi = n - 1;
- while (khi - klo > 1) {
- k = (khi + klo) >> 1;
- if (xa[k] > x) {
- khi = k;
- } else {
- klo = k;
- }
- }
- h = xa[khi] - xa[klo];
-
- if (h == 0.0) {
- throw new InterpolationException("Two identical x values. The values must be distinct.");
- }
- a = (xa[khi] - x) / h;
- b = (x - xa[klo]) / h;
- y =
- a * ya[klo]
- + b * ya[khi]
- + ((a * a * a - a) * y2a[klo] + (b * b * b - b) * y2a[khi])
- * (h * h)
- / 6.0;
- return y;
- }
-
- /**
- * Calculates the second derivative of the data. This algorithm
- * was taken from:
- *
- * William H. Press, Saul A. Teukolosky, William T. Vetterling, Brian P. Flannery,
- * "Numerical Recipes in C - The Art of Scientific Computing", Second Edition,
- * Cambridge University Press,
- * ISBN 0-521-43108-5,
- * chapter 3, pages 113-116.
- */
- public double splineInterpolatedDerivative(
- double[] xa,
- double[] ya,
- double[] y2a,
- double x)
- throws InterpolationException {
- int n = xa.length;
- if (n != ya.length || n != y2a.length) {
- throw new InterpolationException("Arrays have different lengths.");
- }
- double dydx;
- int klo, khi, k;
- double h, b, a;
-
- klo = 0;
- khi = n - 1;
- while (khi - klo > 1) {
- k = (khi + klo) >> 1;
- if (xa[k] > x) {
- khi = k;
- } else {
- klo = k;
- }
- }
- h = xa[khi] - xa[klo];
- if (h == 0.0) {
- throw new InterpolationException("Two identical x values. The values must be distinct.");
- }
- a = (xa[khi] - x) / h;
- b = (x - xa[klo]) / h;
- dydx =
- (ya[khi] - ya[klo]) / h
- - ((3 * (a * a) - 1) * h * y2a[klo]) / 6.0
- + ((3 * (b * b) - 1) * h * y2a[khi]) / 6.0;
- return dydx;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eva2/tools/math/interpolation/package-info.java b/src/main/java/eva2/tools/math/interpolation/package-info.java
deleted file mode 100644
index afc86898..00000000
--- a/src/main/java/eva2/tools/math/interpolation/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package eva2.tools.math.interpolation;