필터 지우기
필터 지우기

Sampling according to difference in function value

조회 수: 1 (최근 30일)
Sepp
Sepp 2016년 6월 18일
편집: per isakson 2016년 6월 18일
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?

채택된 답변

per isakson
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." &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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by