필터 지우기
필터 지우기

Indices after accumarray in order to do N-dimensional histograms

조회 수: 2 (최근 30일)
Hello everyone,
I am using an accumarray function in my script in order to computer N-dimensional histograms. This is the line:
ht = accumarray(sub, 1, nBins+1 .* ones(1, nFeat));
where nBins stands for the number of Bins in my histogram and nFeat the number of features (so the dimension of my histogram).
If I use for example this set of data:
[1 2 ; 2 3 ; 1 2 ; 1 3 ; 1 1 ; 3 2]
My 2-dimensional histogram will be:
H = [1 2 1;
0 0 1;
0 1 0]
The first value for example says that there is 1 occurrence of 1 1, the second value 2 occurrences of 1 2...
However I want to keep the indices. In this example, I would like to have something like that:
Hind = {5}, {[1 3]}, {4};
{ }, { }, {2};
{ }, { 6 }, { }
I don't really care about it being in cells or something else.
The number is the cell are just the linear indices of the values that contributed to the histogram.
Basically, I want the indices that could allow me to generate my histogram for example by doing:
H = cell2mat(cellfun(@numel, Hind, 'Un', false));
I hope this was clear.
Thanks a lot,
Quentin
  댓글 수: 4
Steven Lord
Steven Lord 2019년 6월 9일
So nFeat could be up to 10. What is an upper bound on nBins? If it's too large, even storing "only the indices" could require more memory than is available on the planet or in the known universe.
Quentin Garçon
Quentin Garçon 2019년 6월 10일
nBins follows a dimensionality curse... So the goof thing is that I have to decrease it as soon as nFeat is increasing. So for now nBins = 16 is already big.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 9일
ht = accumarray(sub, (1:size(sub,1)).', nBins+1 .* ones(1, nFeat), @(v) {v});
  댓글 수: 1
Quentin Garçon
Quentin Garçon 2019년 6월 10일
Thank you!
This is exactly what I wanted. This is perfect. I had already done another method thinking about what Steven Lord told me. However reducing the memory cost was possible but it has a big cost in computation time.
I will try this solution!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Quentin Garçon
Quentin Garçon 2019년 6월 8일
Hi!
I can't find any other solution than using a lot of if loop in order to find back the indices. No one has a better syntax with the accumarray?

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by