Sampling according to difference in function value

2 vues (au cours des 30 derniers jours)
Sepp
Sepp le 18 Juin 2016
Modifié(e) : per isakson le 18 Juin 2016
Hello
I have 20 values x1,...x20. Each value is between 0 and 1, for example 0.22,0.23,0.25,...
x = rand(20,1);
x = sort(x);
Now I would like to choose one data point but not uniform at random. The data point with the lowest value should have the highest probability and the other values should have a probability proportional to the difference in function value to the lowest value.
For example, if the lowest function value is 0.22, a data point with a function value of 0.23 has a difference to the best value of 0.23 - 0.22 = 0.01 and should therefore have a probability similar to the 0.22 value. But a value of 0.3 has a difference of 0.3 - 0.22 = 0.08 and should therefore have a much smaller probability.
How can this be done?

Réponse acceptée

per isakson
per isakson le 18 Juin 2016
Modifié(e) : per isakson le 18 Juin 2016
A homemade approach
%%Sample data that better fits the tooltip display
x = randi([1,100],[1,20]); % 100 is magic number
x = sort(x);
dx = x - x(1) + 4; % 4 is magic number
f = @(d) 1./(d.*d); % "much smaller probability"
csf = [ 0, cumsum( f(dx) ) / sum(f(dx)) ];
is = histc( rand, csf ) == 1;
disp( x(is) )
"other values should have a probability proportional to the difference in function value to the lowest value." &nbsp I don't understand the descripton on how to calculate the weight. However, replacing &nbsp f = @(d) 1./(d.*d); &nbsp by &nbsp f = @(d) 1./d; &nbsp may be closer.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by