Mercurial > hg > jslab
comparison src/samer/maths/random/PowerLaw.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.maths.random; | |
11 import samer.core.types.*; | |
12 import java.util.*; | |
13 | |
14 /* | |
15 * Generates random numbers from a single-sider power-law | |
16 * with a lower cut-off, but no upper cut-off. The | |
17 * exponent must therefore be strictly less than 1. | |
18 */ | |
19 public class PowerLaw extends BaseRandom implements Observer | |
20 { | |
21 VDouble min = new VDouble("min",1); | |
22 VDouble D = new VDouble("exponent",1); | |
23 double a, b; | |
24 | |
25 public void dispose() { min.dispose(); D.dispose(); } | |
26 public double next() { return a*Math.pow(rnd.nextDouble(),b); } | |
27 | |
28 public PowerLaw() | |
29 { | |
30 min.addObserver(this); | |
31 D.addObserver(this); | |
32 update(null,null); | |
33 } | |
34 | |
35 public void update(Observable o, Object oo) { | |
36 a=min.value; | |
37 b=-1/D.value; | |
38 } | |
39 } |