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