MATLAB: Generate pdf distribution with bias

biasMATLABpdfstatistics

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!

Best Answer

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.