root/applications/bdmtoolbox/mex/mex_classes/mexLaplace.m @ 1054

Revision 1054, 1.0 kB (checked in by smidl, 14 years ago)

doc

RevLine 
[1054]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% ======================================================================
[937]8classdef mexLaplace < mexEpdf
9    properties
10      % from wikipedia
11        mu
12        b
13    end
14    methods
[944]15        function m=mean(obj)
16            m = obj.mu;
[937]17        end
[944]18        function obj=validate(obj)
19            if length(obj.mu)~=length(obj.b)
[937]20                error('incompatible mu and b');
21            end
22        end
[944]23        function dim=dimension(obj)
24            dim = size(obj.mu,1);
[937]25        end
[944]26        function v=variance(obj)
27            v=2*obj.b^2;
[937]28        end
[944]29        function l=evallog(obj,x)
30            l=-log(2*obj.b)-abs(x-obj.mu)/obj.b;
[937]31        end
[944]32        function s=sample(obj)
[937]33            v=-log(rand);%sample_exponential(0,1);
34            z = randn;
[944]35            s = obj.mu+obj.b*sqrt(2*v)*z;
[937]36        end
37    end
38end
Note: See TracBrowser for help on using the browser.