Skip to content

Instantly share code, notes, and snippets.

@shimazaki
Created August 27, 2012 03:48
Show Gist options
  • Save shimazaki/3485337 to your computer and use it in GitHub Desktop.
Save shimazaki/3485337 to your computer and use it in GitHub Desktop.
resampling from 2d data
data %2d data
subplot(2,2,1);
[optW,C,W,Z,X,Y,dx,dy]=sskernel2d(data);
axis square;
fx = sum(Z'* dy);
fy = sum(Z * dx);
x = X(:,1); y = Y(1,:);
subplot(2,2,3); plot(x,fx);
subplot(2,2,4); plot(y,fy);
for i = 1: 1e4
cdfx = cumsum(fx*dx);
idx_x = find(rand<cdfx,1,'first');
rx = x(idx_x);
fy_x =Z(idx_x,:) / fx(idx_x);
cdfy = cumsum(fy_x*dy);
idx_y = find(rand<cdfy,1,'first');
ry = y(idx_y);
subplot(2,2,3); hold on; plot(x(idx_x),fx(idx_x),'rs');
subplot(2,2,4); hold on; plot(y,fy_x,'r'); plot(y(idx_y),fy_x(idx_y),'rs');
subplot(2,2,2);
hold on; plot(x(idx_x),y(idx_y),'k.');
axis square;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment