Weighted sampling with 2 vectors

我的未来我决定 提交于 2019-12-11 20:38:11

问题


(1) I have two column vectors.

                           Eg. x = [283167.778           
                                   *289387.207                
                                   289705.322]            

                               y = [9121643.314
                                    9098348.666*
                                    9099832.621]

(2) I'd like to make a weighted random sampling using these vectors: when I'll select the element 289387.207 in vector x, necessarily I'll choose the element 9098348.666 in vector y.

(3) Also, I have the weighted w vector for each element in vector x and y.

How can I implement this in MatLab? Thanks!


回答1:


For random selection:

sel_idx= randi(3);
outputx = x(sel_idx);
outputy = y(sel_idx);

for random weighing:

w = rand(size(x));
w = w./sum(w); % normalize
outputx = w(:)'*x(:);
outputy = w(:)'*y(:);


来源:https://stackoverflow.com/questions/16549174/weighted-sampling-with-2-vectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!