Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mrd/jelly/random/Gamma.java


1   /*
2    * Copyright (C) 2002-2003, Mark Diggory 
3    *
4    * This file is part of the Repast Taglibrary Package for use with Jelly.
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. License 
19   * information is also available at http://www.gnu.org.
20   *
21   * @author Mark Diggory <mdiggory@latte.harvard.edu>
22   */
23  
24  package org.mrd.jelly.random;
25  
26  import org.apache.commons.jelly.*;
27  
28  /** This is a random number generation class that produces pseudo-random
29   * doubles acording to a configured Lambda Distribution. The Distribution is
30   * supported by the cern.jet.random.Gamma Distribution Class.
31   *
32   * The distribution can be configured by two strategies
33   *
34   * 1.) Alpha and Lambda parameters can be provided for the distribution.
35   *
36   *
37   * @author Mark R. Diggory
38   */
39  public class Gamma extends DistributionTagBase {
40      
41      /** Holds value of property alpha. */
42      private double alpha;
43      
44      /** Holds value of property lambda. */
45      private double lambda;
46      
47      /** Used by Ant to check if the appropriate attributes have been filled out.
48       * @throws BuildException if attribute is not correctly filled in.
49       */
50      public void doStartTag(XMLOutput xMLOutput)
51      throws MissingAttributeException,
52      JellyTagException {
53          
54          
55          if (getVar() == null)
56              throw new MissingAttributeException("var");
57          
58          if(!(alpha > Double.MIN_VALUE))
59              throw new MissingAttributeException("alpha");
60          
61          if(!(lambda > Double.MIN_VALUE))
62              throw new MissingAttributeException("lambda");
63          
64          context.setVariable(getVar(),new cern.jet.random.Gamma(alpha, lambda,this.getRandomElement()));
65        
66      }
67      
68      
69      /** Getter for property alpha.
70       * @return Value of property alpha.
71       */
72      public double getAlpha() {
73          return alpha;
74      }
75      
76      /** Setter for property alpha.
77       * @param alpha New value of property alpha.
78       */
79      public void setAlpha(double alpha) {
80          this.alpha = alpha;
81      }
82      
83      /** Getter for property lambda.
84       * @return Value of property lambda.
85       */
86      public double getLambda() {
87          return lambda;
88      }
89      
90      /** Setter for property lambda.
91       * @param lambda New value of property lambda.
92       */
93      public void setLambda(double lambda) {
94          this.lambda = lambda;
95      }
96      
97  }