home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (distribution.xml)

This example Java source code file (distribution.xml) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

apache, asf, continuous, distributions, for, integerdistribution, license, math, overview, realdistribution, the, user

The distribution.xml Java example source code

<?xml version="1.0"?>

<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
  -->
  
<?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
<document url="distribution.html">
  <properties>
    <title>The Commons Math User Guide - Distributions
  </properties>
  <body>
    <section name="8 Probability Distributions">
      <subsection name="8.1 Overview" href="overview">
        <p>
          The distributions package provides a framework and implementations for some commonly used
          probability distributions. Continuous univariate distributions are represented by implementations of
          the <a href="../apidocs/org/apache/commons/math3/distribution/RealDistribution.html">RealDistribution
          interface.  Discrete distributions implement
          <a href="../apidocs/org/apache/commons/math3/distribution/IntegerDistribution.html">IntegerDistribution
          (values must be mapped to integers) and there is an
          <a href="../apidocs/org/apache/commons/math3/distribution/EnumeratedDistribution.html">EnumeratedDistribution
          class representing discrete distributions with a finite, enumerated set of values.  Finally, multivariate
          real-valued distributions can be represented via the 
          <a href="../apidocs/org/apache/commons/math3/distribution/MultiVariateRealDistribution.html">MultivariateRealDistribution
          interface.
        </p>
        <p>
          An overview of available continuous distributions:<br/>
          <img src="../images/userguide/real_distribution_examples.png" alt="Overview of continuous distributions"/>
        </p>
      </subsection>
      <subsection name="8.2 Distribution Framework" href="distributions">
        <p>
          The distribution framework provides the means to compute probability density
          functions (<code>density(·)), probability mass functions
          (<code>probability(·)) and distribution functions
          (<code>cumulativeProbability(·)) for both
          discrete (integer-valued) and continuous probability distributions.
          The framework also allows for the computation of inverse cumulative probabilities
          and sampling from distributions.
        </p>
        <p>
          For an instance <code>f of a distribution F,
          and a domain value, <code>x, f.cumulativeProbability(x)
          computes <code>P(X <= x) where X is a random variable distributed
          as <code>f, i.e., f.cumulativeProbability(·) represents
          the distribution function of <code>f. If f is continuous,
          (implementing the <code>RealDistribution interface) the probability density
          function of <code>f is represented by f.density(·).
          For discrete <code>f (implementing IntegerDistribution), the probability
          mass function is represented by <code>f.probability(·).  Continuous
          distributions also implement <code>probability(·) with the same
          definition (<code>f.probability(x) represents P(X = x)
          where <code>X is distributed as f), though in the continuous
          case, this will usually be identically 0. 
        </p>
<source>TDistribution t = new TDistribution(29);
double lowerTail = t.cumulativeProbability(-2.656);     // P(T(29) <= -2.656)
double upperTail = 1.0 - t.cumulativeProbability(2.75); // P(T(29) >= 2.75)</source>
        <p>
          All distributions implement a <code>sample() method to support random sampling from the
          distribution. Implementation classes expose constructors allowing the default 
          <a href="../apidocs/org/apache/commons/math3/random/RandomGenerator.html">RandomGenerator
          used by the sampling algorithm to be overridden.  If sampling is not going to be used, providing
          a null <code>RandomGenerator constructor argument will avoid the overhead of initializing
          the default generator.
        </p>
        <p>
          Inverse distribution functions can be computed using the
          <code>inverseCumulativeProbability methods.  For continuous f
          and <code>p a probability, f.inverseCumulativeProbability(p) returns
          <code>
    <li>inf{x in R | P(X≤x) ≥ p} for 0 < p < 1}, <li>inf{x in R | P(X≤x) > 0} for p = 0}. </ul> where X is distributed as f.
    For discrete <code>f, the definition is the same, with Z (the integers) in place of <code>R. Note that in the discrete case, the ≥ in the definition can make a difference when <code>p is an attained value of the distribution. </p> </subsection> <!-- TODO: add section on multivariate distributions --> <subsection name="8.3 User Defined Distributions" href="userdefined"> <p> User-defined distributions can be implemented using <a href="../apidocs/org/apache/commons/math3/distribution/RealDistribution.html">RealDistribution, <a href="../apidocs/org/apache/commons/math3/distribution/IntegerDistribution.html">IntegerDistribution and <a href="../apidocs/org/apache/commons/math3/distribution/MultivariateRealDistribution.html">MultivariateRealDistribution interfaces serve as base types. These serve as the basis for all the distributions directly supported by Apache Commons Math. To aid in implementing distributions, the <a href="../apidocs/org/apache/commons/math3/distribution/AbstractRealDistribution.html">AbstractRealDistribution, <a href="../apidocs/org/apache/commons/math3/distribution/AbstractIntegerDistribution.html">AbstractIntegerDistribution and <a href="../apidocs/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.html">AbstractMultivariateRealDistribution provide implementation building blocks and offer basic distribution functionality. By extending these abstract classes directly, much of the repetitive distribution implementation is already developed and should save time and effort in developing user-defined distributions. </p> </subsection> </section> </body> </document>

Other Java examples (source code examples)

Here is a short list of links related to this Java distribution.xml source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.