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.functions; samer@0: import samer.maths.*; samer@0: samer@0: /** samer@0: Log prior for an laplacian distribution with samer@0: an extra mass at zero, eg a mixture of a laplacian samer@0: with another much narrower laplacian. The log prior is samer@0: basically an abs function with with a extra-deep pit at samer@0: zero. samer@0: Paramters control the width and depth of the pit. samer@0: samer@0: Two linear phases blended exponentially. samer@0: */ samer@0: samer@0: public class BiLaplacianBlend extends Function samer@0: { samer@0: double beta=1, A=1; samer@0: samer@0: public void setExponent(double b) { beta=b; } samer@0: public void setStrength(double a) { A=a; } samer@0: public double getJump() { return 1+A*beta; } samer@0: samer@0: public String format(String t) { return "SparseLaplacian("+t+")"; } samer@0: samer@0: public final double apply(double t) { samer@0: t = Math.abs(t); samer@0: double s=beta*t; samer@0: if (s<24) return t-A*Math.exp(-s); samer@0: else return t; samer@0: } samer@0: samer@0: public Function derivative() { samer@0: return new Function() { samer@0: public final double apply(double t) { samer@0: if (t>0) { samer@0: double s=beta*t; samer@0: if (s>24) return 1; samer@0: else return 1+A*beta*Math.exp(-s); samer@0: } else if (t<0) { samer@0: double s=-beta*t; samer@0: if (s>24) return -1; samer@0: else return -1-A*beta*Math.exp(-s); samer@0: } else return 0; samer@0: } samer@0: public String format(String t) { return "dBiLaplacian("+t+")"; } samer@0: }; samer@0: } samer@0: } samer@0: