Sample slices in MATLAB

I have a question about the slicing algorithm in MATLAB ( slicesample ).

Consider a random variable g(X) with non-normalized pdf f:=1(g(X)=g) , where g is a real number.

Suppose I compute g(X) in the @dens_slice helper function for any given value x of x .

Let starting be the value of x of x such that g(X)=g .

Then I installed

 slicesample(starting,num,'pdf',@dens_slice); 

with num=2000 denoting the nsamples input.

Suppose I keep the entire estimate g(X) performed by the algorithm in column vector A After some time, the algorithm stops and A consists much more than 2000 .

Does 2000 correspond to the number of values ​​in A equal to g ?


Example:

 %%%%%%MAIN%%%%%%% clear all %Set slice sampling rng('default'); rng(1); global U U = randn(2, 1); S_init = U(1)*3 + U(2)*2; global starting starting = [S_init 3 2]; global iteration iteration = 0; global resultslice resultslice = [starting(1), iteration, starting(2:end)]; % For each row: obj.func, iteration, parameter values save('resultslice.mat', 'resultslice') num = 100; param = slicesample(starting(2:end), num, 'pdf', @dens_slice); exit %%%%DENS_SLICE%%%%% function ind = dens_slice(param) global starting global resultslice global iteration global U S = criterion_slice(param); ind = 1.*(S==starting(1)); iteration = iteration + 1; % Update iteration resultslice = [resultslice;[S iteration param]]; %update result save('resultslice.mat', 'resultslice') end %%%%CRITERION_SLICE%%%%% function S = criterion_slice(param) global U beta1 = param(1); beta2 = param(2); S = beta1*U(1) + beta2*U(2); end 

In the above example, A is the first column of resultslice .

+7
matlab
source share

No one has answered this question yet.

See related questions:

244
Differences between Octave and MATLAB?
196
Xkcd style graphs in MATLAB
5
Matlab plot in loop error
one
Two algorithms for the Jacobi method: why time change?
one
Printing vectors whose length is not known A-Priori :: MATLAB
one
Implementing the Simplex Infinite Loop Method
one
Matlab Butterworth filter preserving NaN
one
How to catch this approximation error in my matlab script?
one
Increasing MATLAB runtime
0
Change the displayed string in the MATLAB GUI edit box by changing the value in another edit window

All Articles