Sampling according to difference in function value
2 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
per isakson
2016 年 6 月 18 日
編集済み: per isakson
2016 年 6 月 18 日
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."   I don't understand the descripton on how to calculate the weight. However, replacing   f = @(d) 1./(d.*d);   by   f = @(d) 1./d;   may be closer.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!