samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.maths.random; samer@0: import samer.core.types.*; samer@0: import java.util.*; samer@0: samer@0: /* samer@0: * Hyperbolic distribution: power law with exponent 1. samer@0: * Integral of pdf diverges in both directions, so we samer@0: * need both upper and lower cut-offs. samer@0: */ samer@0: public class BoundedHyperbolic extends BaseRandom implements Observer samer@0: { samer@0: VDouble min = new VDouble("min",1); samer@0: VDouble max = new VDouble("max",2); samer@0: double a, b; samer@0: samer@0: public void dispose() { min.dispose(); max.dispose(); } samer@0: public double next() { return b*Math.exp(a*rnd.nextDouble()); } samer@0: samer@0: public BoundedHyperbolic( double min, double max) samer@0: { samer@0: this(); samer@0: this.min.value = min; this.min.changed(); samer@0: this.max.value = max; this.max.changed(); samer@0: } samer@0: samer@0: public BoundedHyperbolic() samer@0: { samer@0: min.addObserver(this); samer@0: max.addObserver(this); samer@0: update(null,null); samer@0: } samer@0: samer@0: public void update(Observable o, Object oo) { samer@0: a=Math.log(min.value/max.value); samer@0: b=max.value; samer@0: } samer@0: }