Revision 1054, 1.0 kB
(checked in by smidl, 14 years ago)
|
doc
|
Line | |
---|
1 | %> @file mexLaplace.m |
---|
2 | %> @brief Matrlab implemnetation of Laplace density |
---|
3 | % ====================================================================== |
---|
4 | %> @brief Unconditional Laplace density |
---|
5 | % |
---|
6 | %> \f[ f(x|\mu,b) \propto \exp(-|x-\mu|/b)\f] |
---|
7 | % ====================================================================== |
---|
8 | classdef mexLaplace < mexEpdf |
---|
9 | properties |
---|
10 | % from wikipedia |
---|
11 | mu |
---|
12 | b |
---|
13 | end |
---|
14 | methods |
---|
15 | function m=mean(obj) |
---|
16 | m = obj.mu; |
---|
17 | end |
---|
18 | function obj=validate(obj) |
---|
19 | if length(obj.mu)~=length(obj.b) |
---|
20 | error('incompatible mu and b'); |
---|
21 | end |
---|
22 | end |
---|
23 | function dim=dimension(obj) |
---|
24 | dim = size(obj.mu,1); |
---|
25 | end |
---|
26 | function v=variance(obj) |
---|
27 | v=2*obj.b^2; |
---|
28 | end |
---|
29 | function l=evallog(obj,x) |
---|
30 | l=-log(2*obj.b)-abs(x-obj.mu)/obj.b; |
---|
31 | end |
---|
32 | function s=sample(obj) |
---|
33 | v=-log(rand);%sample_exponential(0,1); |
---|
34 | z = randn; |
---|
35 | s = obj.mu+obj.b*sqrt(2*v)*z; |
---|
36 | end |
---|
37 | end |
---|
38 | end |
---|