2个向量的加权采样 [英] Weighted sampling with 2 vectors

查看:94
本文介绍了2个向量的加权采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(1)我有两个列向量.

(1) I have two column vectors.

                           Eg. x = [283167.778           
                                   *289387.207                
                                   289705.322]            

                               y = [9121643.314
                                    9098348.666*
                                    9099832.621]

(2)我想使用这些向量进行加权随机抽样:当我在向量x中选择元素289387.207时,必然会在向量y中选择元素9098348.666.

(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)另外,我对向量x和y中的每个元素都有加权w向量.

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

如何在MatLab中实现此功能? 谢谢!

How can I implement this in MatLab? Thanks!

推荐答案

随机选择:

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

随机称重:

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

这篇关于2个向量的加权采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆