Mercurial > hg > jslab
annotate src/samer/functions/BiLaplacianBlend.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
rev | line source |
---|---|
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.functions; |
samer@0 | 11 import samer.maths.*; |
samer@0 | 12 |
samer@0 | 13 /** |
samer@0 | 14 Log prior for an laplacian distribution with |
samer@0 | 15 an extra mass at zero, eg a mixture of a laplacian |
samer@0 | 16 with another much narrower laplacian. The log prior is |
samer@0 | 17 basically an abs function with with a extra-deep pit at |
samer@0 | 18 zero. |
samer@0 | 19 Paramters control the width and depth of the pit. |
samer@0 | 20 |
samer@0 | 21 Two linear phases blended exponentially. |
samer@0 | 22 */ |
samer@0 | 23 |
samer@0 | 24 public class BiLaplacianBlend extends Function |
samer@0 | 25 { |
samer@0 | 26 double beta=1, A=1; |
samer@0 | 27 |
samer@0 | 28 public void setExponent(double b) { beta=b; } |
samer@0 | 29 public void setStrength(double a) { A=a; } |
samer@0 | 30 public double getJump() { return 1+A*beta; } |
samer@0 | 31 |
samer@0 | 32 public String format(String t) { return "SparseLaplacian("+t+")"; } |
samer@0 | 33 |
samer@0 | 34 public final double apply(double t) { |
samer@0 | 35 t = Math.abs(t); |
samer@0 | 36 double s=beta*t; |
samer@0 | 37 if (s<24) return t-A*Math.exp(-s); |
samer@0 | 38 else return t; |
samer@0 | 39 } |
samer@0 | 40 |
samer@0 | 41 public Function derivative() { |
samer@0 | 42 return new Function() { |
samer@0 | 43 public final double apply(double t) { |
samer@0 | 44 if (t>0) { |
samer@0 | 45 double s=beta*t; |
samer@0 | 46 if (s>24) return 1; |
samer@0 | 47 else return 1+A*beta*Math.exp(-s); |
samer@0 | 48 } else if (t<0) { |
samer@0 | 49 double s=-beta*t; |
samer@0 | 50 if (s>24) return -1; |
samer@0 | 51 else return -1-A*beta*Math.exp(-s); |
samer@0 | 52 } else return 0; |
samer@0 | 53 } |
samer@0 | 54 public String format(String t) { return "dBiLaplacian("+t+")"; } |
samer@0 | 55 }; |
samer@0 | 56 } |
samer@0 | 57 } |
samer@0 | 58 |