| 1 | %> @file mexEpdf.m | 
|---|
| 2 | %> @brief File mappring root class of epdf from BDM | 
|---|
| 3 | % ====================================================================== | 
|---|
| 4 | %> @brief Abstract class of unconditional probability density function (epdf)  | 
|---|
| 5 | % | 
|---|
| 6 | %> This class provides a bridge between bdm::epdf and Matlab | 
|---|
| 7 | % ====================================================================== | 
|---|
| 8 | classdef mexEpdf | 
|---|
| 9 |     properties | 
|---|
| 10 |             %> Description of random variable (see definitiopn of RV) | 
|---|
| 11 |             rv=RV;  | 
|---|
| 12 |     end | 
|---|
| 13 |     methods | 
|---|
| 14 |              %> Function returning mean value of this epdf | 
|---|
| 15 |         function m=mean(p) | 
|---|
| 16 |             error('define how to compute mean') | 
|---|
| 17 |         end | 
|---|
| 18 |              %> This function is called before using the object. It should check consistency of the properties and fill default values. | 
|---|
| 19 |         function validate(p) | 
|---|
| 20 |             error('check if the density is consistent') | 
|---|
| 21 |         end | 
|---|
| 22 |              %> Tell the world around it dimension of the random variable | 
|---|
| 23 |         function dim=dimension(p) | 
|---|
| 24 |             error('return dimension of the density') | 
|---|
| 25 |         end | 
|---|
| 26 |              %> Function returning variance of this epdf | 
|---|
| 27 |         function v=variance(p) | 
|---|
| 28 |             error('define how to compute mean') | 
|---|
| 29 |         end | 
|---|
| 30 |              %> Function returning logarithm of likelihood function in point x | 
|---|
| 31 |         function l=evallog(p,x) | 
|---|
| 32 |             error('define how to evaluate log of this density at point x') | 
|---|
| 33 |         end | 
|---|
| 34 |              %> Function returning a signle sample from this density | 
|---|
| 35 |          function l=sample(p) | 
|---|
| 36 |             error('define how to sample from this density') | 
|---|
| 37 |         end | 
|---|
| 38 |          | 
|---|
| 39 |         %%% default functions -- no need to redefine %%% | 
|---|
| 40 |          | 
|---|
| 41 |              %> Function returning logarithm of NON-normalized likelihood function in point x (speed optimization) | 
|---|
| 42 |         function l=evallog_nn(p,x) | 
|---|
| 43 |             % define how to evaluate non-normalized log of this density at point x | 
|---|
| 44 |             % makes sense if faster than normalized | 
|---|
| 45 |             l=evallog(p,x); | 
|---|
| 46 |         end | 
|---|
| 47 |  | 
|---|
| 48 |                   function r=get_rv(p) | 
|---|
| 49 |                         r=p.rv; | 
|---|
| 50 |           end | 
|---|
| 51 |              %> Function returning a matrix of n samples from this density,  | 
|---|
| 52 |           function m = samplemat(obj, n) | 
|---|
| 53 |               m = zeros(obj.dimension, n); | 
|---|
| 54 |               for i=1:n | 
|---|
| 55 |                   m(:,i) = obj.sample; | 
|---|
| 56 |               end | 
|---|
| 57 |           end | 
|---|
| 58 |     end | 
|---|
| 59 | end | 
|---|