samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.maths.random;
|
samer@0
|
11 import samer.core.types.*;
|
samer@0
|
12 import java.util.*;
|
samer@0
|
13
|
samer@0
|
14 /*
|
samer@0
|
15 * Hyperbolic distribution: power law with exponent 1.
|
samer@0
|
16 * Integral of pdf diverges in both directions, so we
|
samer@0
|
17 * need both upper and lower cut-offs.
|
samer@0
|
18 */
|
samer@0
|
19 public class BoundedHyperbolic extends BaseRandom implements Observer
|
samer@0
|
20 {
|
samer@0
|
21 VDouble min = new VDouble("min",1);
|
samer@0
|
22 VDouble max = new VDouble("max",2);
|
samer@0
|
23 double a, b;
|
samer@0
|
24
|
samer@0
|
25 public void dispose() { min.dispose(); max.dispose(); }
|
samer@0
|
26 public double next() { return b*Math.exp(a*rnd.nextDouble()); }
|
samer@0
|
27
|
samer@0
|
28 public BoundedHyperbolic( double min, double max)
|
samer@0
|
29 {
|
samer@0
|
30 this();
|
samer@0
|
31 this.min.value = min; this.min.changed();
|
samer@0
|
32 this.max.value = max; this.max.changed();
|
samer@0
|
33 }
|
samer@0
|
34
|
samer@0
|
35 public BoundedHyperbolic()
|
samer@0
|
36 {
|
samer@0
|
37 min.addObserver(this);
|
samer@0
|
38 max.addObserver(this);
|
samer@0
|
39 update(null,null);
|
samer@0
|
40 }
|
samer@0
|
41
|
samer@0
|
42 public void update(Observable o, Object oo) {
|
samer@0
|
43 a=Math.log(min.value/max.value);
|
samer@0
|
44 b=max.value;
|
samer@0
|
45 }
|
samer@0
|
46 }
|