View Javadoc

    1   package baseCode.math.distribution;
    2
    3   /***
    4    * Generate probabilities from the uniform distribution.
    5    * <hr>
    6    * <p>
    7    * Copyright (c) 2004 Columbia University
    8    *
    9    * @author pavlidis
    10   * @version $Id: UniformProbabilityComputer.java,v 1.1 2004/12/31 01:14:48 pavlidis Exp $
    11   */
    12  public class UniformProbabilityComputer implements ProbabilityComputer {
    13
    14     double min = 0;
    15     double max = 1;
    16
    17     /***
    18      * Create a UniformProbabilityComputer where the density is defined over the unit inteval [0,1].
    19      */
    20     public UniformProbabilityComputer() {
    21        this( 0, 1 );
    22     }
    23
    24     /***
    25      * Create a UniformProbabilityComputer where the density is defined over the interval given
    26      *
    27      * @param min
    28      * @param max
    29      */
    30     public UniformProbabilityComputer( double min, double max ) {
    31        if ( max <= min ) {
    32           throw new IllegalArgumentException( "Max must be higher than min" );
    33        }
    34        this.min = min;
    35        this.max = max;
    36     }
    37
    38     /*
    39      * (non-Javadoc)
    40      *
    41      * @see baseCode.math.ProbabilityComputer#probability(double)
    42      */
    43     public double probability( double x ) {
    44        if ( x < min ) return 0;
    45        if ( x > max ) return 1;
    46        return ( x - min ) / ( max - min );
    47     }
    48
    49     /*
    50      * (non-Javadoc)
    51      *
    52      * @see baseCode.math.ProbabilityComputer#probability(double, boolean)
    53      */
    54     public double probability( double x, boolean upperTail ) {
    55
    56        if ( !upperTail ) {
    57           return probability( x );
    58        }
    59
    60        if ( x < min ) return 0;
    61
    62        if ( x > max ) return 1.0;
    63
    64        return ( max - x ) / ( max - min );
    65     }
    66
    67  }