How do I use histcounts with overlapping bins?

8 vues (au cours des 30 derniers jours)
Prodip Das
Prodip Das le 27 Mar 2019
Commenté : Steven Lord le 29 Mar 2019
First off, there's only this post I found with some relevant inputs, although the comments suggested overlapping bins may not work with histcounts?
My question is this: Is there a way to create bin egdes by giving the number of bins (which histcounts does) and the percentage overlap between bins to generate a set of overlapping bins which can be used with accumarray later on?
More specifically, I have vectors x, y and z covering a spatial volume. I need to "discretize" this volume and bin the vector V.. (which is when I found the answer on 3D binning). I am looking for a way to extend this by adding overlapping bins.
Is there a way to achieve this? Any help is appreciated. Thanks!
  4 commentaires
Prodip Das
Prodip Das le 29 Mar 2019
The main use in this case is to generate a more "filled" data set. This could be achieved by making the bins smaller in principle. But if the data to be binned is somewhat sparse then collecting those points over bigger overlapping bins gives a well-averaged effect. This is my understanding of it, which may not be the best reason out there.
Steven Lord
Steven Lord le 29 Mar 2019
Do you need to visualize the overlapping bins (histogram) or just compute with overlapping bins (histcounts)?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Mar 2019
Discretize three times per dimension, once with the bins exactly where you want them, once with the bins [overlap] earlier, once with the bins [overlap] later. Do the 27 different 3D binnings (each possible combination of early, middle, late), taking lists of indices. Then take the union of all of the indices in corresponding bins.
  6 commentaires
Prodip Das
Prodip Das le 29 Mar 2019
Thanks Walter.
This is going to take me a while to completely get my head around as its not immediately clear to me.
I'll post the matrix collating bit as a separate question.
Walter Roberson
Walter Roberson le 29 Mar 2019
I think I might have the union loop wrong, possibly.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 28 Mar 2019
Modifié(e) : Matt J le 28 Mar 2019
If you're willing to make some approximations in the interest of speed, this is a method that will do the whole 3D accumarray operation. It uses some FEX contributions that you must download, namely KronProd and ndSparse. Basically, it first histograms the x,y,z data normally into super-thin, non-overlapping bins. Then it basically consolidates those into overlapping bins by separable convolution.
%% simulated data
vmin=0; vmax=10; %integer min and max assumed here
x=rand(1,10000)*(vmax-vmin)+vmin;
y=rand(1,10000)*(vmax-vmin)+vmin;
z=rand(1,10000)*(vmax-vmin)+vmin;
%% binning parameter selections
binShift=0.5; binWidth=1;
%% Set-up computations
lowerEdges=vmin:binShift:vmax-binWidth;
upperEdges=lowerEdges+binWidth;
Nbins=numel(lowerEdges);
delta=vmax-vmin;
N=1000*delta;
L=(lowerEdges.')*N/delta+1;
U=(upperEdges.')*N/delta+1;
T=cumsum(sparse(1:Nbins,L,1,Nbins,N+1)-sparse(1:Nbins,U,1,Nbins,N+1),2);
C=KronProd({T(:,1:N)},[1,1,1]); %separable convolution operator
%% Do computation
tic;
e=linspace(vmin,vmax,N);
I=discretize(x,e).';
J=discretize(y,e).';
K=discretize(z,e).';
H=ndSparse.build([I,J,K],1,[N,N,N]);
A=full(C*H); %The "accumarray" result
toc; %Elapsed time is 1.182683 seconds.
  1 commentaire
Prodip Das
Prodip Das le 29 Mar 2019
Thanks for the answer Matt ! I wasn't certain where the approximations lay, and wasn't very well versed with separable convolution. Needed a more quick fix as of now, will revert back to this in the future hopefully to understand better.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by