Effacer les filtres
Effacer les filtres

Generate pdf distribution with bias

2 vues (au cours des 30 derniers jours)
Tyler
Tyler le 6 Avr 2017
Commenté : Tyler le 2 Mai 2017
I'm curious if anyone knows how to bias a probability density function. For example, I want to create a pdf from vector A, but I want to bias it according to vector B (without changing the values in A). So if A = [1 2 3 4 5] and B = [1 1 1 1 0.5], the 5th element of A would count half as much as the rest when computing my pdf.
In that case, a simple work-around is to re-create the other elements in A to weight them twice as much, so A' = [1 2 3 4 5 1 2 3 4]. However, this gets more difficult if the biases are not easy integers. If my weighted vector B = [.4265 1 .9361 1 .1532], it would not be easy to simply add more elements. The only solution I can think of is to find the closest common denominator for the biases and add elements accordingly. Seeing as I will be repeating this with much larger vectors and changing biases, a better way would be nice. I haven't been able to find any toolboxes or function options that offer this. If anyone knows a simpler solution I would be most appreciative. Thanks!

Réponse acceptée

John D'Errico
John D'Errico le 6 Avr 2017
Modifié(e) : John D'Errico le 6 Avr 2017
Simpler than you apparently think. Even trivial.
A = 1:5;
B = [1 1 1 1 0.5];
B = cumsum([0,B])/sum(B);
N = 10000;
[~,~,bin] = histcounts(rand(N,1),B);
X = A(bin);
hist(X,100)
I think you should see that the above code will work regardless of the weights, integer, non-integer. So for your other example...
B = [0.4265 1 .9361 1 0.1532]
B = cumsum([0,B])/sum(B);
N = 1000000;
[~,~,bin] = histcounts(rand(N,1),B);
X = A(bin);
hist(X,100)
With a much larger sample, you can see the sample accurately follows the desired distribution.
  2 commentaires
Tyler
Tyler le 11 Avr 2017
Modifié(e) : Tyler le 11 Avr 2017
Thanks! Does it matter what N is? Just a high enough number to get an accurate spread?
Tyler
Tyler le 2 Mai 2017
Thanks John. I notice my results change depending on the value of N. Is there a rule of thumb on that value? Should it be a multiple of the size of my B vector, or just a big enough number to ensure an accurate weighting?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by