Generate pdf distribution with bias

2 visualizaciones (últimos 30 días)
Tyler
Tyler el 6 de Abr. de 2017
Comentada: Tyler el 2 de Mayo de 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!

Respuesta aceptada

John D'Errico
John D'Errico el 6 de Abr. de 2017
Editada: John D'Errico el 6 de Abr. de 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 comentarios
Tyler
Tyler el 11 de Abr. de 2017
Editada: Tyler el 11 de Abr. de 2017
Thanks! Does it matter what N is? Just a high enough number to get an accurate spread?
Tyler
Tyler el 2 de Mayo de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by