Revision 937, 0.7 kB
(checked in by smidl, 15 years ago)
|
matlab class extension for pdf
|
Line | |
---|
1 | classdef mexLaplace < mexEpdf |
---|
2 | properties |
---|
3 | % from wikipedia |
---|
4 | mu |
---|
5 | b |
---|
6 | end |
---|
7 | methods |
---|
8 | function m=mean(p) |
---|
9 | m = p.mu; |
---|
10 | end |
---|
11 | function validate(p) |
---|
12 | if size(p.mu)<1 & (size(p.b)<1) |
---|
13 | error('incompatible mu and b'); |
---|
14 | end |
---|
15 | end |
---|
16 | function dim=dimension(p) |
---|
17 | dim = size(p.mu,1); |
---|
18 | end |
---|
19 | function v=variance(p) |
---|
20 | v=2*p.b^2; |
---|
21 | end |
---|
22 | function l=evallog(p,x) |
---|
23 | l=-log(2*p.b)-abs(x-p.mu)/p.b; |
---|
24 | end |
---|
25 | function s=sample(p); |
---|
26 | v=-log(rand);%sample_exponential(0,1); |
---|
27 | z = randn; |
---|
28 | s = p.mu+p.b*sqrt(2*v)*z; |
---|
29 | end |
---|
30 | end |
---|
31 | end |
---|