Mercurial > hg > jslab
annotate src/samer/functions/BiLaplacian.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 Sparsified Laplacian, v1 |
samer@0 | 15 Log prior for an laplacian distribution with |
samer@0 | 16 an extra mass at zero, eg a mixture of a laplacian |
samer@0 | 17 with another much narrower laplacian. The log prior is |
samer@0 | 18 basically an abs function with with a extra-deep pit at |
samer@0 | 19 zero. |
samer@0 | 20 Paramters control the width and depth of the pit. |
samer@0 | 21 */ |
samer@0 | 22 |
samer@0 | 23 public class BiLaplacian extends Function |
samer@0 | 24 { |
samer@0 | 25 double width=1, A=1, slope=2; |
samer@0 | 26 |
samer@0 | 27 public void setWidth(double b) { width=b; slope=(width+A)/width; } |
samer@0 | 28 public void setStrength(double a) { A=a; slope=(width+A)/width; } |
samer@0 | 29 public double getJump() { return slope; } |
samer@0 | 30 |
samer@0 | 31 public String format(String t) { return "BiLaplace("+t+")"; } |
samer@0 | 32 |
samer@0 | 33 public final double apply(double t) { |
samer@0 | 34 t = Math.abs(t); |
samer@0 | 35 if (t<width) return -A+slope*t; |
samer@0 | 36 else return t; |
samer@0 | 37 } |
samer@0 | 38 |
samer@0 | 39 public Function derivative() { |
samer@0 | 40 return new Function() { |
samer@0 | 41 public String format(String t) { return "dBiLaplace("+t+")"; } |
samer@0 | 42 public final double apply(double t) { |
samer@0 | 43 if (t>0) { |
samer@0 | 44 if (t<width) return slope; |
samer@0 | 45 else return 1; |
samer@0 | 46 } else if (t<0) { |
samer@0 | 47 if (t>-width) return -slope; |
samer@0 | 48 else return -1; |
samer@0 | 49 } else return 0; |
samer@0 | 50 } |
samer@0 | 51 }; |
samer@0 | 52 } |
samer@0 | 53 } |
samer@0 | 54 |