User Guide - Overview Robert Burrell Donkin Phil Steitz

This guide is intended to help programmers quickly find what they need to develop solutions using Commons Math. It also provides a supplement to the javadoc API documentation, providing a little more explanation of the mathematical objects and functions included in the package.

Commons Math is made up of a small set of math/stat utilities addressing programming problems like the ones in the list below. This list is not exhaustive, it's just meant to give a feel for the kinds of things that Commons Math provides.

  • Computing means, variances and other summary statistics for a list of numbers
  • Fitting a line to a set of data points using linear regression
  • Solving equations involving real-valued functions (i.e. root-finding)
  • Performing statistical significance tests
  • Solving systems of linear equations
  • Generating random numbers with more restrictions (e.g distribution, range) than what is possible using the JDK
  • Generating random samples and/or datasets that are "like" the data in an input file
  • Finding a smooth curve that passes through a collection of points (interpolation)
  • Miscellaneous mathematical functions such as factorials and binomial coefficients

Commons Math is a new project and we are actively seeking ideas for additional components that fit into the Commons Math vision of a set of lightweight, self-contained math/stat components useful for solving common programming problems. Suggestions for new components or enhancements to existing functionality are always welcome! All feedback/suggestions for improvement should be sent to the commons-dev mailing list with [math] at the beginning of the subject line.

Commons Math is divided into 6 subpackages, based on functionality provided.

  1. org.apache.commons.math.stat - statistics, statistical tests, probability distributions
  2. org.apache.commons.math.analysis - rootfinding and interpolation
  3. org.apache.commons.math.random - random numbers, strings and data generation
  4. org.apache.commons.math.special - special functions (Gamma, Beta)
  5. org.apache.commons.math.linear - matrices, solving linear systems
  6. org.apache.commons.math.util - common math/stat functions extending java.lang.Math
Package javadocs are here

You should always read the javadoc class and method comments carefully when using Commons Math components in your programs. The javadoc provides references to the algorithms that are used, usage notes about limitations, performance, etc. as well as interface contracts. Interface contracts are specified in terms of preconditions (what has to be true in order for the method to return valid results), special values returned (e.g. Double.NaN) or exceptions that may be thrown if the preconditions are not met, and definitions for returned values/objects or state changes.

When the actual parameters provide to a method or the internal state of an object make a computation meaningless, an IllegalArgumentException or IllegalStateException may be thrown. Exact conditions under which runtime exceptions (and any other exceptions) are thrown are specified in the javadoc method comments. In some cases, to be consistent with the IEEE 754 standard for floating point arithmetic and with java.lang.Math, Commons Math methods return Double.NaN values. Conditions under which Double.NaN or other special values are returned are fully specified in the javadoc method comments.

Commons Math requires JDK 1.2+ and has no dependencies other than the following Jakarta Commons components:

  • commons-beanutils 1.5
  • commons-collections 2.1
  • commons-logging 1.0.3