how to get common range between 20 intervals?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have 20 intervals such as [21,23], [20,22] and [19,20.4]. I want to find the common range (intersection) for those twenty intervals if exists, if not then I want to answer what would be the common range that satisfies the most out of those twenty intervals, such as finding a range that can satisfy around 15 intervals out of the 20. I have seen the following references but they won't work out for my application.
0 Commenti
Risposte (3)
John D'Errico
il 22 Feb 2022
Your question is too fuzzy. You want to satisfy some of the intervals. Most. How many is most? And how is a computer to choose? Around 15. What if the desired region of overlap was not contiguous, so broken into disjoint sub-intervals? No problem. :) Seriously, you need to recognize that computers don't do wishy washy very well.
And you don't actually give any specific data, besides a few examples. So let me make some data up.
n = 20;
LB = randn(1,n);
UB = LB + 3 + rand(1,n);
Now plot the various intervals.
N = (1:n);
plot([LB;UB],[N;N],'-o')
Can we find some domain of best approximate overlap, with 15 of the 20 intervals included? Logically, we might look at an appropriate percentile on the lower bounds, then use the reverse percentile on the upper bounds.
overlapfrac = 0.75;
overlapinterval = [prctile(LB,100*overlapfrac),prctile(UB,100*(1-overlapfrac))]
xline(overlapinterval)
In some cases, the overlap interval may be such that the lower bound is greater then the upper bound. That would tell you no interval exists with the desired property.
Is this the perfect solution? Hardly so, since I honestly have no clue what you really expect. If you want something better, you need to provide answers to the questions I posed above.
DGM
il 22 Feb 2022
Modificato: DGM
il 22 Feb 2022
Finding a non-empty intersection is easy enough, so I'm going to concentrate on the latter part of the question. I'm sure there are other ways, but this is what I came up with.
% let's say we have a set of intervals in a Mx2 matrix
rng(123)
ivals = [randi([20 60],20,1) randi([40 80],20,1)]
% pull out the lower and upper boundaries for clarity
LB = ivals(:,1);
UB = ivals(:,2);
% find the intersection
% in this case, the intersection is empty
% so we need to find the smallest nonzero range
% which intersects as many of the intervals as possible
intsect_ivals = [max(LB) min(UB)]
% get sorted copies of the boundaries
LBs = sort(LB,'descend');
UBs = sort(UB,'ascend');
[LBs UBs]
% find the span between all lower and upper bounds
% we're only looking for positive nonzero cases
span = UBs.' - LBs;
span(span<=0) = NaN
% find locations where the minimal nonzero span occurs
candidatemap = span == min(span(:))
% these are all intersections which have the same minimal span
% map subscripts are indices into LBs, UBs
[idxL idxU] = find(candidatemap);
idxLU = [idxL idxU];
% since LBs,UBs are sorted, the index pair with the lowest maximum
% includes the largest fraction of the original set of intervals
[~,bestidx] = min(max(idxLU,[],2));
bestLUidx = idxLU(bestidx,:);
bestinterval = [LBs(bestLUidx(1)) UBs(bestLUidx(2))]
Image Analyst
il 22 Feb 2022
Can you supply some data? What I'd do is to take a histogram of all the aggregated data and look for bins that cover all of the range or most of the range. You can examine the counts.
You can also do it yourself manually by making a number line and assigning values. Like
numberLine = linspace(0, 30, 1000);
counts = zeros(1, length(numberLine));
% Add in interval 1
indexRange = numberLine >= interval1Min & numberLine <= interval1Max
counts(indexRange) = counts(indexRange) + 1;
% Now repeat for interval 2.
indexRange = numberLine >= interval2Min & numberLine <= interval2Max
counts(indexRange) = counts(indexRange) + 1;
% etc.
plot(numberLine, counts, 'b-', 'LineWidth', 2);
You can decide what range to take after you examine the counts.
You forgot to attach any data. Doing so would have gotten you a better answer.
Vedere anche
Categorie
Scopri di più su Multirate Signal Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!