Changeset 983 for applications/bdmtoolbox/mex
- Timestamp:
- 05/25/10 22:33:29 (14 years ago)
- Location:
- applications/bdmtoolbox/mex/mex_classes
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/mex_classes/mexDirac.m
r944 r983 1 1 classdef mexDirac < mexEpdf 2 2 % Dirac delta probability distribution 3 properties 4 point % point of the support3 properties % DATA structures 4 point % point of the support 5 5 end 6 6 methods 7 function m=mean(obj) 7 function m=mean(obj) % compute mean values of the density 8 8 m = obj.point; 9 9 end 10 function obj=validate(obj) 10 function obj=validate(obj) % check if data structures are consistent 11 11 % point should be a column 12 12 if (size(obj.point,2)>1) … … 18 18 end 19 19 end 20 function dim=dimension(obj) 20 function dim=dimension(obj) % inform others about your dimensions 21 21 dim = size(obj.point,1); 22 22 end 23 function v=variance(obj) 23 function v=variance(obj) % compute variance 24 24 v=zeros(size(obj.point)); 25 25 end 26 function l=evallog(obj,x) 26 function l=evallog(obj,x) % return logarithm of your density at point x 27 27 if obj.point==x 28 28 l = inf; … … 31 31 end 32 32 end 33 function s=sample(obj); 33 function s=sample(obj); % return random sample from your density 34 34 s = obj.point; 35 35 end -
applications/bdmtoolbox/mex/mex_classes/mexLaplaceBM.m
r944 r983 3 3 % Maximum likelihood approximation of the Bayes rule is used, posterior is in the form of dirac. 4 4 properties 5 max_window_length = 10; % max window length6 data_window =[]; % estimate of mu is median of observations5 max_window_length = 10; % max window length (default = 10) 6 data_window =[]; % sliding window of data 7 7 end 8 8 methods 9 function obj=validate(obj) 10 % prepare all internal objects for use 9 function obj=validate(obj) % prepare all internal objects for use 11 10 obj.apost_pdf = mexDirac; 12 11 obj.apost_pdf.point = [0;0]; 13 obj.log_evidence = 0; % evidence is not computed!12 obj.log_evidence = 0; % evidence is not computed! 14 13 disp('val'); 15 14 end 16 15 17 16 function dims=dimensions(obj) 18 %please fill 19 %dims = [size_of_posterior size_of_data size_of_condition] 20 dims = [2,1,0] % we have: [2d parameters, 1d observations, 0d condition] 17 %please fill: dims = [size_of_posterior size_of_data size_of_condition] 18 dims = [2,1,0] % we have: [2d parameters, 1d observations, 0d condition] 21 19 end 22 function obj=bayes(obj,dt,cond) 20 function obj=bayes(obj,dt,cond) % approximate bayes rule 23 21 if size(obj.data_window,2)>=obj.max_window_length 24 22 obj.data_window = [dt obj.data_window(1:end-1)]; … … 29 27 m_hat = mean(obj.data_window); 30 28 b_hat = sum(abs(obj.data_window-m_hat))/ size(obj.data_window,2); 31 obj.apost_pdf.point = [m_hat; b_hat]; 29 obj.apost_pdf.point = [m_hat; b_hat]; % store result in psoterior pdf 32 30 end 33 function p=epredictor(obj,cond) 31 function p=epredictor(obj,cond) % when predictive density is needed approximate it by Laplace with point estimates 34 32 % return predictive density (max likelihood) 35 33 p = mexLaplace;