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