Generate pdf distribution with bias

조회 수: 4 (최근 30일)
Tyler
Tyler 2017년 4월 6일
댓글: Tyler 2017년 5월 2일
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!

채택된 답변

John D'Errico
John D'Errico 2017년 4월 6일
편집: John D'Errico 2017년 4월 6일
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
Tyler
Tyler 2017년 4월 11일
편집: Tyler 2017년 4월 11일
Thanks! Does it matter what N is? Just a high enough number to get an accurate spread?
Tyler
Tyler 2017년 5월 2일
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?

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by