~ubuntu-branches/ubuntu/vivid/elki/vivid

« back to all changes in this revision

Viewing changes to src/de/lmu/ifi/dbs/elki/math/statistics/distribution/LogGammaDistribution.java

  • Committer: Package Import Robot
  • Author(s): Erich Schubert
  • Date: 2014-01-22 16:23:20 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140122162320-dtqtgcdiki8t9unc
Tags: 0.6.0-1
* New upstream final.
* 3DPC extension is not included, but may be uploaded as a separate
  package when there is actual need (it is a demo software, not meant
  for use outside of research, so just get the source code!)
* Upgrade to policy 3.9.5.0 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import java.util.Random;
27
27
 
 
28
import de.lmu.ifi.dbs.elki.utilities.RandomFactory;
 
29
import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
 
30
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
 
31
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.DoubleParameter;
 
32
 
28
33
/**
29
34
 * Log-Gamma Distribution, with random generation and density functions.
30
35
 * 
34
39
 * 
35
40
 * @author Erich Schubert
36
41
 */
37
 
public class LogGammaDistribution implements Distribution {
 
42
public class LogGammaDistribution extends AbstractDistribution {
38
43
  /**
39
44
   * Alpha == k.
40
45
   */
51
56
  private final double shift;
52
57
 
53
58
  /**
54
 
   * The random generator.
55
 
   */
56
 
  private Random random;
57
 
 
58
 
  /**
59
59
   * Constructor for Gamma distribution.
60
60
   * 
61
61
   * @param k k, alpha aka. "shape" parameter
64
64
   * @param random Random generator
65
65
   */
66
66
  public LogGammaDistribution(double k, double theta, double shift, Random random) {
67
 
    super();
68
 
    if (!(k > 0.0) || !(theta > 0.0)) { // Note: also tests for NaNs!
69
 
      throw new IllegalArgumentException("Invalid parameters for Gamma distribution: " + k + " " + theta);
70
 
    }
71
 
 
72
 
    this.k = k;
73
 
    this.theta = theta;
74
 
    this.shift = shift;
75
 
    this.random = random;
 
67
    super(random);
 
68
    if (!(k > 0.0) || !(theta > 0.0)) { // Note: also tests for NaNs!
 
69
      throw new IllegalArgumentException("Invalid parameters for Gamma distribution: " + k + " " + theta);
 
70
    }
 
71
 
 
72
    this.k = k;
 
73
    this.theta = theta;
 
74
    this.shift = shift;
 
75
  }
 
76
 
 
77
  /**
 
78
   * Constructor for Gamma distribution.
 
79
   * 
 
80
   * @param k k, alpha aka. "shape" parameter
 
81
   * @param shift Location offset
 
82
   * @param theta Theta = 1.0/Beta aka. "scaling" parameter
 
83
   * @param random Random generator
 
84
   */
 
85
  public LogGammaDistribution(double k, double theta, double shift, RandomFactory random) {
 
86
    super(random);
 
87
    if (!(k > 0.0) || !(theta > 0.0)) { // Note: also tests for NaNs!
 
88
      throw new IllegalArgumentException("Invalid parameters for Gamma distribution: " + k + " " + theta);
 
89
    }
 
90
 
 
91
    this.k = k;
 
92
    this.theta = theta;
 
93
    this.shift = shift;
76
94
  }
77
95
 
78
96
  /**
83
101
   * @param shift Location offset
84
102
   */
85
103
  public LogGammaDistribution(double k, double theta, double shift) {
86
 
    this(k, theta, shift, null);
 
104
    this(k, theta, shift, (Random) null);
87
105
  }
88
106
 
89
107
  @Override
191
209
  public static double quantile(double p, double k, double theta, double shift) {
192
210
    return Math.exp(GammaDistribution.quantile(p, k, theta)) + shift;
193
211
  }
 
212
 
 
213
  /**
 
214
   * Parameterization class
 
215
   * 
 
216
   * @author Erich Schubert
 
217
   * 
 
218
   * @apiviz.exclude
 
219
   */
 
220
  public static class Parameterizer extends AbstractDistribution.Parameterizer {
 
221
    /**
 
222
     * Shifting offset parameter.
 
223
     */
 
224
    public static final OptionID SHIFT_ID = new OptionID("distribution.loggamma.shift", "Shift offset parameter.");
 
225
 
 
226
    /** Parameters. */
 
227
    double k, theta, shift;
 
228
 
 
229
    @Override
 
230
    protected void makeOptions(Parameterization config) {
 
231
      super.makeOptions(config);
 
232
 
 
233
      DoubleParameter kP = new DoubleParameter(GammaDistribution.Parameterizer.K_ID);
 
234
      if (config.grab(kP)) {
 
235
        k = kP.doubleValue();
 
236
      }
 
237
 
 
238
      DoubleParameter thetaP = new DoubleParameter(GammaDistribution.Parameterizer.THETA_ID);
 
239
      if (config.grab(thetaP)) {
 
240
        theta = thetaP.doubleValue();
 
241
      }
 
242
 
 
243
      DoubleParameter shiftP = new DoubleParameter(SHIFT_ID);
 
244
      if (config.grab(shiftP)) {
 
245
        shift = shiftP.doubleValue();
 
246
      }
 
247
    }
 
248
 
 
249
    @Override
 
250
    protected LogGammaDistribution makeInstance() {
 
251
      return new LogGammaDistribution(k, theta, shift, rnd);
 
252
    }
 
253
  }
194
254
}