How to get the probability value (y) for a given (x) from a probability normalised histogram?

15 visualizzazioni (ultimi 30 giorni)
Hello all,
Need some help with a prediction experiment I'm trying to run. I have some live-feed values, which I take in chunks and turn into histograms with probability normalisation. I need some way of getting the probability of a given value, based on that histogram. Basically I need the invert of a quantile function. The quantile gives me what the value is, given a probability. So if you imagine the histogram as a X, Y plot, the quantile is fed an Y value and it gives the associated X, I need something that I can feed an X value, and gives me the Y (which is the probability in the histogram). I hope my explanation makes sense.
  1 Commento
Alexander Grantcharov
Alexander Grantcharov il 22 Mar 2018
Just to clarify... Let's suggest we have this sample data in the X array.
X=[1 1 1 2 2 3 3 3 4 4 ];
h=histogram(X,4,'Normalization','probability');
If we build a histogram for the probabilities of the entries in the array we get this histogram:
Then I want to say what is the probability of getting 2 and I want the function to result in 0.2, or might ask what is the probability of getting a 5 and the function will give me a result of 0. Mind that I don't know the distribution or want to do fitting.

Accedi per commentare.

Risposta accettata

dpb
dpb il 22 Mar 2018
Modificato: dpb il 22 Mar 2018
If you fit a functional to the distribution, then use icdf (inverse cdf) with those parameters; if empirical only then it's a lookup to the empirical data or a fit thereof.
ADDENDUM
For that, there is a function...
[N,edges] = histcounts(X,5); % return the edges vector for lookup later
P=N/sum(N); % the normalized P values per bin
fnInvP=@(x) P(discretize(x,edges));
This will need to ensure that x is within range of X, however; wrap in a try...catch block would be one way; have to decide how to handle the error case of course.
  1 Commento
Alexander Grantcharov
Alexander Grantcharov il 22 Mar 2018
The distribution of my live feed could be completely random, so fitting a specific distribution function will not do. Anyways, I found a workaround. It is not particularly elegant one, but it works:
X=[1 1 1 2 2 3 3 3 4 4 ];
h=histogram(X,5,'Normalization','probability');
[N,edges] = histcounts(X,5);
T_Count = sumabs(N);
All_P = N/T_Count;
CheckValue = input('Enter a value to check its probability: ');
if CheckValue > edges(1,1) && CheckValue <= edges(1,2)
P = All_P(1,1);
elseif CheckValue > edges(1,2) && CheckValue <= edges(1,3)
P = All_P(1,2);
elseif CheckValue > edges(1,3) && CheckValue <= edges(1,4)
P = All_P(1,3);
elseif CheckValue > edges(1,4) && CheckValue <= edges(1,5)
P = All_P(1,4);
elseif CheckValue > edges(1,5) && CheckValue <= edges(1,6)
P = All_P(1,5);
else
P = 0;
end
disp(P);
Basically I construct two arrays containing the probability values and the edges of the bins. Then I check which bin the entered value corresponds to, and then address the necessary probability that corresponds to it. If the value is outside of the scope (has not occurred) it gets a probability of 0. Choppy, but it works. Was just hoping there is a function available to do this :)
Cheers!

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by