Binning 3D data und reasign Bin properties to data

2 Ansichten (letzte 30 Tage)
Marc Laub
Marc Laub am 8 Dez. 2022
Beantwortet: Shubham am 8 Sep. 2023
Hey, following problem
I have following problem: I have 3D data from which I need to calculate properties.
To reduce the calculation time I want to bin the data, and then only calculate the properties of the bin-voxel that are populated and then reasign the calculated voxel properties to the data points that are within that specific bin.
Right now my sollution looks like this:
a5pre=compositions(:,1);
a7pre=compositions(:,2);
a8pre=compositions(:,3);
%% BINNING
a5pre_edges=[0,linspace(0.005,0.995,19),1];
a5pre_val=(a5pre_edges(1:end-1) + a5pre_edges(2:end))/2;
a5pre_val(1)=0;
a5pre_val(end)=1;
a7pre_edges=[0,linspace(0.005,0.995,49),1];
a7pre_val=(a7pre_edges(1:end-1) + a7pre_edges(2:end))/2;
a7pre_val(1)=0;
a7pre_val(end)=1;
a8pre_edges=a7pre_edges;
a8pre_val=a7pre_val;
[~,~,bin1]=histcounts(a5pre,a5pre_edges);
[~,~,bin2]=histcounts(a7pre,a7pre_edges);
[~,~,bin3]=histcounts(a8pre,a8pre_edges);
bins=[bin1,bin2,bin3];
[A,~,C]=unique(bins,'rows','stable');
a5pre=a5pre_val(A(:,1));
a7pre=a7pre_val(A(:,2));
a8pre=a8pre_val(A(:,3));
It works, but I am not sure if its the smartes way to do it. I also wrote it as a mex function with the coder, because i thought that functions like histcount and unique would be faste that way because I think those are the time critical functions, but it actually took twice as long...
I know of one more restriction:
initial data 0.9<composition(:,2) + composition(:,3) <1
But I am not sure how to include this in the histcount functions, because this would reduce the number of bins in which data points can be in and so make it faster.
Anybody has an idea how to improve it, or is this the way to go? Length of Compositions can be 200 but could also be 40k
EDIT: From the "Run and Time" function i know that a huge portion of that time is spend in the unique2012a function.
Best regards

Antworten (1)

Shubham
Shubham am 8 Sep. 2023
I understand that you want to reduce the calculation time. You are trying to bin the data to improve the efficiency.
You can improve the solution by using the restriction you mentioned:
initial data 0.9<composition(:,2) + composition(:,3) <1
The “a5pre’” and a7pre uses the 2nd and 3rd columns of the composition matrix, respectively. Therefore, you can reduce your bins that do not satisfy this condition.
For better understanding, kindly go through the following piece of code:
valid_bins = (0.9 < a7pre + a8pre) & (a7pre + a8pre < 1);
bins = [bin1(valid_bins), bin2(valid_bins), bin3(valid_bins)];
This would give you the bins that follow the restriction that you mentioned.
Hope this helps!!

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by