[944] | 1 | classdef mexLaplaceBM < mexBM |
---|
| 2 | % Approximate Bayesian estimator of parameters of Laplace distributed observation. |
---|
| 3 | % Maximum likelihood approximation of the Bayes rule is used, posterior is in the form of dirac. |
---|
| 4 | properties |
---|
[983] | 5 | max_window_length = 10; % max window length (default = 10) |
---|
| 6 | data_window =[]; % sliding window of data |
---|
[944] | 7 | end |
---|
| 8 | methods |
---|
[983] | 9 | function obj=validate(obj) % prepare all internal objects for use |
---|
[944] | 10 | obj.apost_pdf = mexDirac; |
---|
| 11 | obj.apost_pdf.point = [0;0]; |
---|
[983] | 12 | obj.log_evidence = 0; % evidence is not computed! |
---|
[944] | 13 | disp('val'); |
---|
| 14 | end |
---|
| 15 | |
---|
| 16 | function dims=dimensions(obj) |
---|
[983] | 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] |
---|
[944] | 19 | end |
---|
[983] | 20 | function obj=bayes(obj,dt,cond) % approximate bayes rule |
---|
[944] | 21 | if size(obj.data_window,2)>=obj.max_window_length |
---|
| 22 | obj.data_window = [dt obj.data_window(1:end-1)]; |
---|
| 23 | else |
---|
| 24 | obj.data_window = [dt obj.data_window]; |
---|
| 25 | end |
---|
| 26 | % transform old estimate into new estimate |
---|
| 27 | m_hat = mean(obj.data_window); |
---|
| 28 | b_hat = sum(abs(obj.data_window-m_hat))/ size(obj.data_window,2); |
---|
[983] | 29 | obj.apost_pdf.point = [m_hat; b_hat]; % store result in psoterior pdf |
---|
[944] | 30 | end |
---|
[983] | 31 | function p=epredictor(obj,cond) % when predictive density is needed approximate it by Laplace with point estimates |
---|
[944] | 32 | % return predictive density (max likelihood) |
---|
| 33 | p = mexLaplace; |
---|
| 34 | p.mu = obj.apost_pdf.point(1); |
---|
| 35 | p.b = obj.apost_pdf.point(2); |
---|
| 36 | p=p.validate; |
---|
| 37 | end |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | end |
---|