Obtained from:
Submitted by:	Brent Worden 
Reviewed by:	Mark Diggory


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-09-27 04:13:34 +00:00
parent 609917a77c
commit d8931052e4
28 changed files with 1381 additions and 292 deletions

View File

@ -2,7 +2,7 @@
<!--
build.xml generated by maven from project.xml version 0.1-dev
on date September 17 2003, time 1526
on date September 27 2003, time 0007
-->
<project default="jar" name="commons-math" basedir=".">
@ -149,14 +149,16 @@
</javadoc>
</target>
<target name="get-deps" unless="noget" depends="init">
<get dest="${libdir}/commons-beanutils-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-SNAPSHOT.jar">
<get dest="${libdir}/commons-beanutils-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-1.5.jar">
</get>
<get dest="${libdir}/commons-collections-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-collections/jars/commons-collections-SNAPSHOT.jar">
</get>
<get dest="${libdir}/commons-discovery-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-discovery/jars/commons-discovery-SNAPSHOT.jar">
<get dest="${libdir}/commons-lang-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-lang/jars/commons-lang-SNAPSHOT.jar">
</get>
<get dest="${libdir}/commons-logging-1.0.3.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.3.jar">
</get>
<get dest="${libdir}/commons-discovery-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-discovery/jars/commons-discovery-SNAPSHOT.jar">
</get>
<get dest="${libdir}/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar">
</get>
<get dest="${libdir}/ant-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar">

View File

@ -1,134 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1.25 $ $Date: 2003/09/26 19:30:32 $ -->
<!-- $Revision: 1.26 $ $Date: 2003/09/27 04:13:34 $ -->
<project>
<extend>../../jakarta-commons/project.xml</extend>
<name>Math</name>
<id>commons-math</id>
<currentVersion>0.1-dev</currentVersion>
<inceptionYear>2003</inceptionYear>
<logo/>
<shortDescription>A library of lightweight, self-contained mathematics and
statistics components.</shortDescription>
<description>The Math project is a library of lightweight, self-contained
mathematics and statistics components addressing the most common practical
problems not immediately available in the Java programming language or
commons-lang.</description>
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/math/</siteDirectory>
<versions>
<version>
<id>0.1-dev</id>
<name>0.1-dev</name>
</version>
</versions>
<developers>
<developer>
<name>Robert Burrell Donkin</name>
<id>rdonkin</id>
<email>rdonkin@apache.org</email>
</developer>
<developer>
<name>Tim OBrien</name>
<id>tobrien</id>
<email>tobrien@apache.org</email>
</developer>
<developer>
<name>Mark R. Diggory</name>
<id>mdiggory</id>
<email>mdiggory@apache.org</email>
</developer>
<developer>
<name>J.Pietschmann</name>
<id>pietsch</id>
<email>pietsch@apache.org</email>
<email>j3322ptm@yahoo.de</email>
</developer>
</developers>
<contributors>
<contributor>
<name>Phil Steitz</name>
<email>phil@steitz.com</email>
<roles>
<role>proposal author</role>
<role>initial contributor</role>
</roles>
</contributor>
<contributor>
<name>Brent Worden</name>
<email>brent@worden.org</email>
</contributor>
<contributor>
<name>Albert Davidson Chou</name>
<email>hotfusionman@yahoo.com</email>
</contributor>
</contributors>
<dependencies>
<dependency>
<id>commons-beanutils</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-collections</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-discovery</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-logging</id>
<version>1.0.3</version>
</dependency>
</dependencies>
<issueTrackingUrl>http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&amp;
bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;email1=&amp;
emailtype1=substring&amp;emailassigned_to1=1&amp;email2=&amp;
emailtype2=substring&amp;emailreporter2=1&amp;bugidtype=include&amp;bug_id=&amp;
changedin=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp;
product=Commons&amp;component=Sandbox&amp;short_desc=&amp;
short_desc_type=allwordssubstr&amp;long_desc=&amp;
long_desc_type=allwordssubstr&amp;bug_file_loc=&amp;
bug_file_loc_type=allwordssubstr&amp;keywords=&amp;keywords_type=anywords&amp;
field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=&amp;cmdtype=doit&amp;
order=%27Importance%27</issueTrackingUrl>
<repository>
<connection>
scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons-sandbox/${pom.artifactId.substring(8)}</connection>
<url>
http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/${pom.artifactId.substring(8)}/</url>
</repository>
<build>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*AbstractTest.java</exclude>
</excludes>
<resources>
<resource>
<directory>${pom.build.unitTestSourceDirectory}</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.txt</include>
</includes>
</resource>
</resources>
</unitTest>
</build>
<reports>
<report>maven-changelog-plugin</report>
<report>maven-changes-plugin</report>
<report>maven-checkstyle-plugin</report>
<!-- <report>maven-clover-plugin</report> -->
<report>maven-developer-activity-plugin</report>
<report>maven-file-activity-plugin</report>
<report>maven-javadoc-plugin</report>
<report>maven-jdepend-plugin</report>
<report>maven-junit-report-plugin</report>
<report>maven-jxr-plugin</report>
<report>maven-license-plugin</report>
<!-- <report>maven-linkcheck-plugin</report> -->
<report>maven-statcvs-plugin</report>
<report>maven-tasklist-plugin</report>
</reports>
<extend>../../jakarta-commons/project.xml</extend>
<name>Math</name>
<id>commons-math</id>
<currentVersion>0.1-dev</currentVersion>
<inceptionYear>2003</inceptionYear>
<logo/>
<shortDescription>
A library of lightweight, self-contained mathematics and statistics components.
</shortDescription>
<description>
The Math project is a library of lightweight, self-contained mathematics and statistics components addressing the most common practical problems not immediately available in the Java programming language or commons-lang.
</description>
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/math/</siteDirectory>
<versions>
<version>
<id>0.1-dev</id>
<name>0.1-dev</name>
</version>
</versions>
<developers>
<developer>
<name>Robert Burrell Donkin</name>
<id>rdonkin</id>
<email>rdonkin@apache.org</email>
</developer>
<developer>
<name>Tim OBrien</name>
<id>tobrien</id>
<email>tobrien@apache.org</email>
</developer>
<developer>
<name>Mark R. Diggory</name>
<id>mdiggory</id>
<email>mdiggory@apache.org</email>
</developer>
</developers>
<contributors>
<contributor>
<name>Phil Steitz</name>
<email>phil@steitz.com</email>
<roles>
<role>proposal author</role>
<role>initial contributor</role>
</roles>
</contributor>
<contributor>
<name>Brent Worden</name>
<email>brent@worden.org</email>
</contributor>
<contributor>
<name>Albert Davidson Chou</name>
<email>hotfusionman@yahoo.com</email>
</contributor>
<contributor>
<name>J.Pietschmann</name>
<email>j3322ptm@yahoo.de</email>
</contributor>
</contributors>
<dependencies>
<dependency>
<id>commons-beanutils</id>
<version>1.5</version>
</dependency>
<dependency>
<id>commons-collections</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-lang</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-logging</id>
<version>1.0.3</version>
</dependency>
<dependency>
<id>commons-discovery</id>
<version>SNAPSHOT</version>
</dependency>
</dependencies>
<issueTrackingUrl>http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;email1=&amp;emailtype1=substring&amp;emailassigned_to1=1&amp;email2=&amp;emailtype2=substring&amp;emailreporter2=1&amp;bugidtype=include&amp;bug_id=&amp;changedin=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp;product=Commons&amp;component=Sandbox&amp;short_desc=&amp;short_desc_type=allwordssubstr&amp;long_desc=&amp;long_desc_type=allwordssubstr&amp;bug_file_loc=&amp;bug_file_loc_type=allwordssubstr&amp;keywords=&amp;keywords_type=anywords&amp;field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=&amp;cmdtype=doit&amp;order=%27Importance%27</issueTrackingUrl>
<repository>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons-sandbox/${pom.artifactId.substring(8)}</connection>
<url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/${pom.artifactId.substring(8)}/</url>
</repository>
<build>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*AbstractTest.java</exclude>
</excludes>
<resources>
<resource>
<directory>${pom.build.unitTestSourceDirectory}</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.txt</include>
</includes>
</resource>
</resources>
</unitTest>
</build>
<reports>
<report>maven-changelog-plugin</report>
<report>maven-changes-plugin</report>
<report>maven-checkstyle-plugin</report>
<report>maven-developer-activity-plugin</report>
<report>maven-file-activity-plugin</report>
<report>maven-javadoc-plugin</report>
<report>maven-jdepend-plugin</report>
<report>maven-junit-report-plugin</report>
<report>maven-jxr-plugin</report>
<report>maven-license-plugin</report>
<report>maven-statcvs-plugin</report>
<report>maven-tasklist-plugin</report>
<!--
<report>maven-clover-plugin</report>
<report>maven-linkcheck-plugin</report>
-->
</reports>
</project>

View File

@ -55,7 +55,7 @@ package org.apache.commons.math;
/**
* Signals a configuration problem with any of the factory methods.
* @version $Revision: 1.6 $ $Date: 2003/08/09 04:03:41 $
* @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathConfigurationException extends MathException {
@ -63,7 +63,7 @@ public class MathConfigurationException extends MathException {
* Default constructor.
*/
public MathConfigurationException() {
super();
this(null, null);
}
/**
@ -71,7 +71,7 @@ public class MathConfigurationException extends MathException {
* @param message message describing the problem
*/
public MathConfigurationException(final String message) {
super(message);
this(message, null);
}
/**
@ -90,6 +90,6 @@ public class MathConfigurationException extends MathException {
* @param throwable caught exception causing this problem
*/
public MathConfigurationException(final Throwable throwable) {
super(throwable);
this(null, throwable);
}
}

View File

@ -53,27 +53,31 @@
*/
package org.apache.commons.math;
import org.apache.commons.lang.exception.NestableException;
/**
* A generic exception indicating problems in the math package.
* @version $Revision: 1.5 $ $Date: 2003/08/09 04:03:41 $
* @version $Revision: 1.6 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathException extends Exception {
public class MathException extends NestableException {
/**
* Constructs a MathException
*/
public MathException() {
super();
this(null, null);
}
/**
* Create an exception with a given error message.
* @param message message describing the problem
*/
public MathException(final String message) {
super(message);
this(message, null);
}
/**
* Create an exception with a given error message and root cause.
* @param message message describing the problem
* @param throwable caught exception causing this problem
*/
@ -82,10 +86,10 @@ public class MathException extends Exception {
}
/**
* Create an exception with a given root cause.
* @param throwable caught exception causing this problem
*/
public MathException(final Throwable throwable) {
super(throwable);
this(null, throwable);
}
}

View File

@ -53,19 +53,28 @@
*/
package org.apache.commons.math.analysis;
import org.apache.commons.lang.exception.NestableRuntimeException;
/**
* Error thrown when a numerical computation can not be performed because the
* numerical result failed to converge to a finite value.
*
* @version $Revision: 1.2 $ $Date: 2003/07/09 20:02:43 $
* @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:33 $
*/
public class ConvergenceException extends RuntimeException {
public class ConvergenceException extends NestableRuntimeException {
/**
* Default constructor.
*/
public ConvergenceException() {
this(null, null);
}
/**
* Construct an exception with the given message.
* @param message descriptive error message.
*/
public ConvergenceException(String message) {
super(message);
this(message, null);
}
/**
@ -77,4 +86,12 @@ public class ConvergenceException extends RuntimeException {
super(message, cause);
}
/**
* Create an exception with a given root cause.
* @param throwable caught exception causing this problem
*/
public ConvergenceException(Throwable throwable) {
this(null, throwable);
}
}

View File

@ -56,18 +56,66 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.MathException;
/**
* Utility class comprised of root finding techniques.
*
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
* Utility routines for {@link UnivariateRealSolver} objects.
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:33 $
*/
public class RootFinding {
public class UnivariateRealSolverUtils {
/**
* Default constructor. Prohibit construction.
* Default constructor.
*/
private RootFinding() {
private UnivariateRealSolverUtils() {
super();
}
/**
* Method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/
public static double solve(UnivariateRealFunction f, double x0, double x1)
throws MathException
{
if(f == null){
throw new IllegalArgumentException("f can not be null.");
}
return UnivariateRealSolverFactory.newInstance().newDefaultSolver(f)
.solve(x0, x1);
}
/**
* Convience method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @param absoluteAccuracy the accuracy to be used by the solver.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/
public static double solve(
UnivariateRealFunction f,
double x0,
double x1,
double absoluteAccuracy)
throws MathException
{
if(f == null){
throw new IllegalArgumentException("f can not be null.");
}
UnivariateRealSolver solver = UnivariateRealSolverFactory.newInstance()
.newDefaultSolver(f);
solver.setAbsoluteAccuracy(absoluteAccuracy);
return solver.solve(x0, x1);
}
/**
* For a function, f, this method returns two values, a and b that bracket
* a root of f. That is to say, there exists a value c between a and b
@ -114,7 +162,7 @@ public class RootFinding {
double fa;
double fb;
int numIterations = 0 ;
do {
a = Math.max(a - 1.0, lowerBound);
b = Math.min(b + 1.0, upperBound);
@ -122,7 +170,7 @@ public class RootFinding {
fb = function.value(b);
numIterations += 1 ;
} while ( (fa * fb > 0.0) && ( numIterations < maximumIterations ) );
return new double[]{a, b};
}
}

View File

@ -54,16 +54,15 @@
package org.apache.commons.math.stat.distribution;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.RootFinding;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.UnivariateRealSolverUtil;
import org.apache.commons.math.analysis.UnivariateRealSolverUtils;
/**
* Base class for various continuous distributions. It provides default
* implementations for some of the methods that do not vary from distribution
* to distribution.
*
* @version $Revision: 1.8 $ $Date: 2003/07/30 21:58:11 $
* @version $Revision: 1.9 $ $Date: 2003/09/27 04:13:34 $
*/
public abstract class AbstractContinuousDistribution
implements ContinuousDistribution {
@ -121,12 +120,12 @@ public abstract class AbstractContinuousDistribution
try {
// bracket root
double[] bracket = RootFinding.bracket(rootFindingFunction,
double[] bracket = UnivariateRealSolverUtils.bracket(rootFindingFunction,
getInitialDomain(p), getDomainLowerBound(p),
getDomainUpperBound(p));
// find root
double root = UnivariateRealSolverUtil.solve(
double root = UnivariateRealSolverUtils.solve(
rootFindingFunction, bracket[0], bracket[1]);
return root;

View File

@ -68,7 +68,7 @@ import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
/**
* Provides univariate measures for an array of doubles.
* @version $Revision: 1.3 $ $Date: 2003/09/26 19:30:32 $
* @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:33 $
*/
public abstract class AbstractUnivariate implements Univariate {
@ -140,6 +140,11 @@ public abstract class AbstractUnivariate implements Univariate {
setWindowSize(window);
}
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
public abstract double apply(UnivariateStatistic stat);

View File

@ -62,7 +62,7 @@ import org.apache.commons.math.util.BeanTransformer;
* univariate statistics for a List of Java Beans by property. This
* implementation uses beanutils' PropertyUtils to get a simple, nested,
* indexed, mapped, or combined property from an element of a List.
* @version $Revision: 1.6 $ $Date: 2003/09/26 19:30:32 $
* @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:33 $
*/
public class BeanListUnivariateImpl extends ListUnivariateImpl {
@ -77,7 +77,7 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
* @param list Backing List
*/
public BeanListUnivariateImpl(List list) {
super(list);
this(list, null);
}
/**
@ -89,7 +89,6 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
public BeanListUnivariateImpl(List list, String propertyName) {
super(list);
setPropertyName(propertyName);
this.transformer = new BeanTransformer(propertyName);
}
/**
@ -103,9 +102,8 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
* @param propertyName Name of Property
*/
public void setPropertyName(String propertyName) {
System.out.println("Set prop name; " + propertyName);
this.propertyName = propertyName;
this.transformer = new BeanTransformer(propertyName);
setTransformer(new BeanTransformer(propertyName));
}
/**

View File

@ -63,7 +63,7 @@ import org.apache.commons.collections.HashBag;
* Accepts int, long or string values, converting
* all to Strings and maintaining frequency counts.
*
* @version $Revision: 1.4 $ $Date: 2003/07/09 21:45:23 $
* @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/
public class Frequency {
/** name for this frequency distribution. */
@ -85,7 +85,7 @@ public class Frequency {
*/
public Frequency(String name) {
super();
this.name = name;
setName(name);
}
/**

View File

@ -60,7 +60,7 @@ import org.apache.commons.math.util.DefaultTransformer;
import org.apache.commons.math.util.NumberTransformer;
/**
* @version $Revision: 1.6 $ $Date: 2003/09/26 19:30:32 $
* @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:33 $
*/
public class ListUnivariateImpl
extends AbstractStoreUnivariate
@ -80,9 +80,7 @@ public class ListUnivariateImpl
* @param list The list that will back this Univariate
*/
public ListUnivariateImpl(List list) {
super();
this.list = list;
transformer = new DefaultTransformer();
this(list, new DefaultTransformer());
}
/**
@ -188,8 +186,10 @@ public class ListUnivariateImpl
list.clear();
}
/* (non-Javadoc)
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic)
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();

View File

@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatistic;
import org.apache.commons.math.util.ContractableDoubleArray;
/**
* @version $Revision: 1.7 $ $Date: 2003/09/26 19:30:32 $
* @version $Revision: 1.8 $ $Date: 2003/09/27 04:13:33 $
*/
public class StoreUnivariateImpl extends AbstractStoreUnivariate {
@ -144,8 +144,10 @@ public class StoreUnivariateImpl extends AbstractStoreUnivariate {
}
}
/* (non-Javadoc)
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic)
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
public double apply(UnivariateStatistic stat) {
if (eDA != null) {

View File

@ -67,7 +67,7 @@ import org.apache.commons.math.util.FixedDoubleArray;
* Integers, floats and longs can be added, but they will be converted
* to doubles by addValue().
*
* @version $Revision: 1.20 $ $Date: 2003/09/26 19:30:32 $
* @version $Revision: 1.21 $ $Date: 2003/09/27 04:13:33 $
*/
public class UnivariateImpl
extends AbstractUnivariate
@ -161,8 +161,10 @@ public class UnivariateImpl
}
}
/* (non-Javadoc)
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic)
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
public double apply(UnivariateStatistic stat) {

View File

@ -55,11 +55,11 @@ package org.apache.commons.math.util;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.math.MathException;
import org.apache.commons.logging.LogFactory;
/**
* Uses PropertyUtils to map a Bean getter to a double value.
* @version $Revision: 1.5 $ $Date: 2003/09/17 19:19:09 $
* @version $Revision: 1.6 $ $Date: 2003/09/27 04:13:34 $
*/
public class BeanTransformer implements NumberTransformer {
@ -72,7 +72,7 @@ public class BeanTransformer implements NumberTransformer {
* Create a BeanTransformer
*/
public BeanTransformer() {
super();
this(null);
}
/**
@ -80,26 +80,8 @@ public class BeanTransformer implements NumberTransformer {
* @param property The property.
*/
public BeanTransformer(final String property) {
this.propertyName = property;
}
/**
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(final Object o) throws MathException {
double d = Double.NaN;
try {
d =
((Number) PropertyUtils.getProperty(o, propertyName))
.doubleValue();
} catch (IllegalAccessException e) {
throw new MathException(e.getMessage(),e);
} catch (InvocationTargetException e) {
throw new MathException(e.getMessage(),e);
} catch (NoSuchMethodException e) {
throw new MathException(e.getMessage(),e);
}
return d;
super();
setPropertyName(property);
}
/**
@ -118,4 +100,26 @@ public class BeanTransformer implements NumberTransformer {
propertyName = string;
}
/**
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(final Object o) {
double d = Double.NaN;
try {
d =
((Number) PropertyUtils.getProperty(o, getPropertyName()))
.doubleValue();
} catch (IllegalAccessException e) {
LogFactory.getLog(getClass()).error(
"Property can not be accessed. Using NaN.", e);
} catch (InvocationTargetException e) {
LogFactory.getLog(getClass()).error(
"Property accessor method threw an exception. Using NaN.", e);
e.printStackTrace();
} catch (NoSuchMethodException e) {
LogFactory.getLog(getClass()).error(
"Property accessor method does not exist. Using NaN.", e);
}
return d;
}
}

View File

@ -51,28 +51,30 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.converters.DoubleConverter;
/**
* A Default NumberTransformer for java.lang.Numbers and Numeric Strings.
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:04:12 $
* @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:34 $
*/
public class DefaultTransformer implements NumberTransformer {
/** Converter used to transform objects. */
private static final DoubleConverter converter =
new DoubleConverter(new Double(Double.NaN));
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public double transform(Object o) {
double d = Double.NaN;
if (o instanceof Number) {
return ((Number) o).doubleValue();
} else {
try {
d = Double.parseDouble(o.toString());
} catch (Exception e) {
e.printStackTrace();
}
double d;
try {
d = ((Double)converter.convert(Double.class, o)).doubleValue();
} catch(ConversionException ex){
d = Double.NaN;
}
return d;
}

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathConfigurationExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
MathConfigurationException ex = new MathConfigurationException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
MathConfigurationException ex = new MathConfigurationException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathConfigurationException ex = new MathConfigurationException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathConfigurationException ex = new MathConfigurationException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
MathException ex = new MathException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
MathException ex = new MathException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathException ex = new MathException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathException ex = new MathException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -58,16 +58,9 @@ import org.apache.commons.math.MathException;
import junit.framework.TestCase;
/**
* @version $Revision: 1.2 $ $Date: 2003/09/17 19:29:27 $
* @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:34 $
*/
public final class BisectionSolverTest extends TestCase {
/**
*
*/
public BisectionSolverTest(String name) {
super(name);
}
/**
*
*/
@ -124,4 +117,132 @@ public final class BisectionSolverTest extends TestCase {
result = solver.solve(0.85, 5);
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
}
/**
*
*/
public void testSetFunctionValueAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setFunctionValueAccuracy(expected);
assertEquals(expected, solver.getFunctionValueAccuracy(), 1.0e-2);
} catch (MathException ex) {
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetFunctionValueAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getFunctionValueAccuracy();
solver.setFunctionValueAccuracy(newValue);
solver.resetFunctionValueAccuracy();
assertEquals(oldValue, solver.getFunctionValueAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetAbsoluteAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setAbsoluteAccuracy(expected);
assertEquals(expected, solver.getAbsoluteAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetAbsoluteAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getAbsoluteAccuracy();
solver.setAbsoluteAccuracy(newValue);
solver.resetAbsoluteAccuracy();
assertEquals(oldValue, solver.getAbsoluteAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetMaximalIterationCount(){
int expected = 100;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
solver.setMaximalIterationCount(expected);
assertEquals(expected, solver.getMaximalIterationCount());
}
/**
*
*/
public void testResetMaximalIterationCount(){
int newValue = 10000;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
int oldValue = solver.getMaximalIterationCount();
solver.setMaximalIterationCount(newValue);
solver.resetMaximalIterationCount();
assertEquals(oldValue, solver.getMaximalIterationCount());
}
/**
*
*/
public void testSetRelativeAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setRelativeAccuracy(expected);
assertEquals(expected, solver.getRelativeAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetRelativeAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getRelativeAccuracy();
solver.setRelativeAccuracy(newValue);
solver.resetRelativeAccuracy();
assertEquals(oldValue, solver.getRelativeAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
}

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.analysis;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class ConvergenceExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
ConvergenceException ex = new ConvergenceException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
ConvergenceException ex = new ConvergenceException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
ConvergenceException ex = new ConvergenceException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
ConvergenceException ex = new ConvergenceException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -69,7 +69,7 @@ import junit.framework.TestSuite;
* default absolute accuracy of 10E-8 for sinus and the quintic function around
* zero, and 5..10 iterations for the other zeros.
*
* @version $Revision: 1.3 $ $Date: 2003/09/17 19:29:27 $
* @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:34 $
*/
public final class RealSolverTest extends TestCase {
@ -281,27 +281,27 @@ public final class RealSolverTest extends TestCase {
// 14 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 15);
// Static solve method
result = UnivariateRealSolverUtil.solve(f, -0.2, 0.2);
result = UnivariateRealSolverUtils.solve(f, -0.2, 0.2);
assertEquals(result, 0, solver.getAbsoluteAccuracy());
result = UnivariateRealSolverUtil.solve(f, -0.1, 0.3);
result = UnivariateRealSolverUtils.solve(f, -0.1, 0.3);
Assert.assertEquals(result, 0, 1E-8);
result = UnivariateRealSolverUtil.solve(f, -0.3, 0.45);
result = UnivariateRealSolverUtils.solve(f, -0.3, 0.45);
Assert.assertEquals(result, 0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.3, 0.7);
result = UnivariateRealSolverUtils.solve(f, 0.3, 0.7);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.2, 0.6);
result = UnivariateRealSolverUtils.solve(f, 0.2, 0.6);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.05, 0.95);
result = UnivariateRealSolverUtils.solve(f, 0.05, 0.95);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.25);
result = UnivariateRealSolverUtils.solve(f, 0.85, 1.25);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.8, 1.2);
result = UnivariateRealSolverUtils.solve(f, 0.8, 1.2);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.75);
result = UnivariateRealSolverUtils.solve(f, 0.85, 1.75);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.55, 1.45);
result = UnivariateRealSolverUtils.solve(f, 0.55, 1.45);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 5);
result = UnivariateRealSolverUtils.solve(f, 0.85, 5);
Assert.assertEquals(result, 1.0, 1E-6);
}
}

View File

@ -51,60 +51,70 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.analysis;
import org.apache.commons.math.MathException;
import junit.framework.TestCase;
/**
* Utility routines for {@link UnivariateRealSolver} objects.
* @version $Revision: 1.2 $ $Date: 2003/09/07 03:12:56 $
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class UnivariateRealSolverUtil {
public class UnivariateRealSolverUtilsTest extends TestCase {
/**
* Default constructor.
*
*/
private UnivariateRealSolverUtil() {
super();
public void testSolveNull(){
try {
UnivariateRealSolverUtils.solve(null, 0.0, 4.0);
fail();
} catch(MathException ex){
fail("math exception should no be thrown.");
} catch(IllegalArgumentException ex){
// success
}
}
/**
*
*/
public void testSolveSin(){
try {
double x = UnivariateRealSolverUtils.solve(new SinFunction(), 1.0,
4.0);
assertEquals(Math.PI, x, 1.0e-4);
} catch(MathException ex){
fail("math exception should no be thrown.");
}
}
/**
* Method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*
*/
public static double solve(UnivariateRealFunction f, double x0, double x1)
throws MathException {
return UnivariateRealSolverFactory.newInstance().newDefaultSolver(f)
.solve(x0, x1);
public void testSolveAccuracyNull(){
try {
double accuracy = 1.0e-6;
UnivariateRealSolverUtils.solve(null, 0.0, 4.0, accuracy);
fail();
} catch(MathException ex){
fail("math exception should no be thrown.");
} catch(IllegalArgumentException ex){
// success
}
}
/**
* Convience method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @param absoluteAccuracy the accuracy to be used by the solver.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*
*/
public static double solve(
UnivariateRealFunction f,
double x0,
double x1,
double absoluteAccuracy)
throws MathException {
UnivariateRealSolver solver = UnivariateRealSolverFactory.newInstance()
.newDefaultSolver(f);
solver.setAbsoluteAccuracy(absoluteAccuracy);
return solver.solve(x0, x1);
public void testSolveAccuracySin(){
try {
double accuracy = 1.0e-6;
double x = UnivariateRealSolverUtils.solve(new SinFunction(), 1.0,
4.0, accuracy);
assertEquals(Math.PI, x, accuracy);
} catch(MathException ex){
fail("math exception should no be thrown.");
}
}
}

View File

@ -57,26 +57,31 @@ package org.apache.commons.math.stat.distribution;
import junit.framework.TestCase;
/**
* @version $Revision: 1.4 $ $Date: 2003/09/17 19:29:30 $
* @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/
public class GammaDistributionTest extends TestCase {
/**
* Constructor for ChiSquareDistributionTest.
* @param name
*/
public GammaDistributionTest(String name) {
super(name);
}
public void testProbabilities(){
testProbability(15.5, 4.0, 2.0, .9499);
testProbability( 0.5, 4.0, 1.0, .0018);
testProbability(10.0, 1.0, 2.0, .9933);
testProbability( 5.0, 2.0, 2.0, .7127);
testProbability(-1.000, 4.0, 2.0, .0000);
testProbability(15.501, 4.0, 2.0, .9499);
testProbability( 0.504, 4.0, 1.0, .0018);
testProbability(10.011, 1.0, 2.0, .9933);
testProbability( 5.000, 2.0, 2.0, .7127);
}
public void testValues(){
testValue(15.501, 4.0, 2.0, .9499);
testValue( 0.504, 4.0, 1.0, .0018);
testValue(10.011, 1.0, 2.0, .9933);
testValue( 5.000, 2.0, 2.0, .7127);
}
private void testProbability(double x, double a, double b, double expected){
double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).cummulativeProbability(x);
assertEquals("probability for " + x, expected, actual, 10e-4);
}
private void testValue(double expected, double a, double b, double p){
double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).inverseCummulativeProbability(p);
assertEquals("critical value for " + p, expected, actual, 10e-4);
}
}

View File

@ -65,7 +65,7 @@ import org.apache.commons.math.beans.*;
/**
* Test cases for the {@link BeanListUnivariateImpl} class.
*
* @version $Revision: 1.4 $ $Date: 2003/09/17 19:29:32 $
* @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/
public final class BeanListUnivariateImplTest extends TestCase {
@ -137,5 +137,12 @@ public final class BeanListUnivariateImplTest extends TestCase {
ageU.getMax(), 0.001 );
}
public void testSetPropertyName(){
BeanListUnivariateImpl u = new BeanListUnivariateImpl(null);
String expected = "property";
u.setPropertyName(expected);
assertEquals(expected, u.getPropertyName());
}
}

View File

@ -53,6 +53,10 @@
*/
package org.apache.commons.math.stat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -60,7 +64,7 @@ import junit.framework.TestSuite;
/**
* Test cases for the {@link Frequency} class.
*
* @version $Revision: 1.2 $ $Date: 2003/07/07 23:19:19 $
* @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:33 $
*/
public final class FrequencyTest extends TestCase {
@ -103,7 +107,7 @@ public final class FrequencyTest extends TestCase {
/** test pcts */
public void testPcts() {
Frequency f = new Frequency("test counts");
Frequency f = new Frequency("test pcts");
f.addValue(oneL);
f.addValue(twoL);
f.addValue(oneI);
@ -116,6 +120,46 @@ public final class FrequencyTest extends TestCase {
assertEquals("two pct",0.25,f.getPct("2"),tolerance);
assertEquals("foo pct",0.5,f.getPct("foo"),tolerance);
assertEquals("bar pct",0,f.getPct("bar"),tolerance);
}
}
/**
*
*/
public void testToString(){
Frequency f = new Frequency("test toString");
f.addValue(oneL);
f.addValue(twoL);
f.addValue(oneI);
f.addValue(twoI);
String s = f.toString();
assertNotNull(s);
BufferedReader reader = new BufferedReader(new StringReader(s));
try {
String line = reader.readLine(); // header line
assertNotNull(line);
line = reader.readLine(); // one's or two's line
assertNotNull(line);
line = reader.readLine(); // one's or two's line
assertNotNull(line);
line = reader.readLine(); // no more elements
assertNull(line);
} catch(IOException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetName(){
String name = "name";
Frequency f = new Frequency();
f.setName(name);
assertEquals(name, f.getName());
}
}

View File

@ -0,0 +1,136 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import org.apache.commons.math.TestUtils;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class BeanTransformerTest extends TestCase {
/**
*
*/
public void testConstructor(){
BeanTransformer b = new BeanTransformer();
assertNull(b.getPropertyName());
}
/**
*
*/
public void testConstructorString(){
String name = "property";
BeanTransformer b = new BeanTransformer(name);
assertEquals(name, b.getPropertyName());
}
/**
*
*/
public void testSetPropertyName(){
String name = "property";
BeanTransformer b = new BeanTransformer();
b.setPropertyName(name);
assertEquals(name, b.getPropertyName());
}
/**
*
*/
public void testTransformNoSuchMethod(){
BeanTransformer b = new BeanTransformer("z");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
}
/**
*
*/
public void testTransform(){
BeanTransformer b = new BeanTransformer("x");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(1.0, value, 1.0e-2);
}
/**
*
*/
public void testTransformInvocationError(){
BeanTransformer b = new BeanTransformer("z");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
}
/**
*
*/
public void testTransformInvalidType(){
BeanTransformer b = new BeanTransformer("y");
TestBean target = new TestBean();
try {
b.transform(target);
fail();
} catch(ClassCastException ex){
// success
}
}
}

View File

@ -0,0 +1,125 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import java.math.BigDecimal;
import org.apache.commons.math.TestUtils;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class DefaultTransformerTest extends TestCase {
/**
*
*/
public void testTransformDouble(){
double expected = 1.0;
Double input = new Double(expected);
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformNull(){
double expected = Double.NaN;
DefaultTransformer t = new DefaultTransformer();
TestUtils.assertEquals(expected, t.transform(null), 1.0e-4);
}
/**
*
*/
public void testTransformInteger(){
double expected = 1.0;
Integer input = new Integer(1);
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformBigDecimal(){
double expected = 1.0;
BigDecimal input = new BigDecimal("1.0");
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformString(){
double expected = 1.0;
String input = "1.0";
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformObject(){
double expected = Double.NaN;
Boolean input = Boolean.TRUE;
DefaultTransformer t = new DefaultTransformer();
TestUtils.assertEquals(expected, t.transform(input), 1.0e-4);
}
}

View File

@ -0,0 +1,109 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class TestBean {
private Double x = new Double(1.0);
private String y = "1.0";
private Double z = new Double(2.0);
/**
*
*/
public Double getX() {
return x;
}
/**
*
*/
public String getY() {
return y;
}
/**
*
*/
public void setX(Double double1) {
x = double1;
}
/**
*
*/
public void setY(String string) {
y = string;
}
/**
*
*/
public Double getZ() {
throw new RuntimeException();
}
/**
*
*/
public void setZ(Double double1) {
z = double1;
}
}

View File

@ -0,0 +1,141 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class TransformerMapTest extends TestCase {
/**
*
*/
public void testPutTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertEquals(expected, map.getTransformer(TransformerMapTest.class));
}
/**
*
*/
public void testContainsClass(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
}
/**
*
*/
public void testContainsTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsTransformer(expected));
}
/**
*
*/
public void testRemoveTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
assertTrue(map.containsTransformer(expected));
map.removeTransformer(TransformerMapTest.class);
assertFalse(map.containsClass(TransformerMapTest.class));
assertFalse(map.containsTransformer(expected));
}
/**
*
*/
public void testClear(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
map.clear();
assertFalse(map.containsClass(TransformerMapTest.class));
}
/**
*
*/
public void testClasses(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.classes().contains(TransformerMapTest.class));
}
/**
*
*/
public void testTransformers(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.transformers().contains(expected));
}
}