View Javadoc

1   package baseCode.math.distribution;
2   
3   /***
4    * <hr>
5    * <p>
6    * Copyright (c) 2004 Columbia University
7    * 
8    * @author pavlidis
9    * @version $Id: UniformDensityComputer.java,v 1.1 2004/12/31 01:14:48 pavlidis Exp $
10   */
11  public class UniformDensityComputer implements DensityGenerator {
12  
13     double min = 0;
14     double max = 1;
15  
16     /***
17      * Create a UniformDensityComputer where the density is defined over the unit inteval [0,1].
18      */
19     public UniformDensityComputer() {
20        this( 0, 1 );
21     }
22  
23     /***
24      * Create a UniformDensityComputer where the density is defined over the interval given
25      * 
26      * @param min
27      * @param max
28      */
29     public UniformDensityComputer( double min, double max ) {
30        if ( max <= min ) {
31           throw new IllegalArgumentException( "Max must be higher than min" );
32        }
33        this.min = min;
34        this.max = max;
35     }
36  
37     /*
38      * (non-Javadoc)
39      * 
40      * @see baseCode.math.DensityGenerator#density(double)
41      */
42     public double density( double x ) {
43  
44        if ( x > max || x < min ) return 0;
45  
46        return 1 / ( max - min );
47     }
48  
49  }