选择概率与信任成正比的节点

发布于 2024-08-21 07:13:40 字数 797 浏览 6 评论 0原文

有谁知道与选择项目相关的算法或数据结构,它们被选择的概率与某些附加值成比例?换句话说: http://en.wikipedia.org/wiki/Sampling_% 28statistics%29#Probability_proportional_to_size_sampling

这里的上下文是一个去中心化的声誉系统,因此附加值是一个用户对另一个用户的信任值。在这个系统中,所有节点要么以完全信任的朋友身份开始,要么以完全不信任的未知身份开始。这在大型 P2P 网络中本身并没有什么用处,因为节点数量比你的朋友多得多,并且你需要知道在不是你直接朋友的一大群用户中该信任谁,所以我实现了一个动态的信任系统,未知者可以通过朋友的朋友关系获得信任。

每个用户经常会选择固定数量(为了速度和带宽)的目标节点,根据另一个选定的固定数量的中间节点对他们的信任程度来重新计算他​​们的信任。选择目标节点进行重新计算的概率将与其当前的信任度成反比,因此未知的节点有很大的机会变得更加为人所知。中间节点将以同样的方式被选择,只不过中间节点被选择的概率与其当前的信任成正比。

我自己编写了一个简单的解决方案,但它相当慢,我想找到一个 C++ 库来为我处理这方面的问题。当然,我已经完成了自己的搜索,并设法找到了我现在正在挖掘的 TRSL。因为这似乎是一个相当简单且可能是常见的问题,所以我希望有更多的 C++ 库可以用于此目的,所以我问这个问题是希望这里有人能对此有所了解。

Does anyone know of an algorithm or data structure relating to selecting items, with a probability of them being selected proportional to some attached value? In other words: http://en.wikipedia.org/wiki/Sampling_%28statistics%29#Probability_proportional_to_size_sampling

The context here is a decentralized reputation system and the attached value is therefore the value of trust one user has in another. In this system all nodes either start as friends which are completely trusted or unknowns which are completely untrusted. This isn't useful by itself in a large P2P network because there will be many more nodes than you have friends and you need to know who to trust in the large group of users that aren't your direct friends, so I've implemented a dynamic trust system in which unknowns can gain trust via friend-of-a-friend relationships.

Every so often each user will select a fixed number (for the sake of speed and bandwidth) of target nodes to recalculate their trust based on how much another selected fixed number of intermediate nodes trust them. The probability of selecting a target node for recalculation will be inversely proportional to its current trust so that unknowns have a good chance of becoming better known. The intermediate nodes will be selected in the same way, except that the probability of selection of an intermediary is proportional to its current trust.

I've written up a simple solution myself but it is rather slow and I'd like to find a C++ library to handle this aspect for me. I have of course done my own search and I managed to find TRSL which I'm digging through right now. Since it seems like a fairly simple and perhaps common problem, I would expect there to be many more C++ libraries I could use for this, so I'm asking this question in the hope that someone here can shed some light on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落星ぅ辰 2024-08-28 07:13:40

这就是我要做的:

int select(double *weights, int n) {
    // This step only necessary if weights can be arbitrary
    // (we know total = 1.0 for probabilities)
    double total = 0;
    for (int i = 0; i < n; ++i) {
        total += weights[i];
    }

    // Cast RAND_MAX to avoid overflow
    double r = (double) rand() * total / ((double) RAND_MAX + 1);
    total = 0;
    for (int i = 0; i < n; ++i) {
        // Guaranteed to fire before loop exit
        if (total <= r && total + weights[i] > r) {
            return i;
        }

        total += weights[i];
    }
}

您当然可以根据需要多次重复第二个循环,每次选择一个新的 r 来生成多个样本。

This is what I'd do:

int select(double *weights, int n) {
    // This step only necessary if weights can be arbitrary
    // (we know total = 1.0 for probabilities)
    double total = 0;
    for (int i = 0; i < n; ++i) {
        total += weights[i];
    }

    // Cast RAND_MAX to avoid overflow
    double r = (double) rand() * total / ((double) RAND_MAX + 1);
    total = 0;
    for (int i = 0; i < n; ++i) {
        // Guaranteed to fire before loop exit
        if (total <= r && total + weights[i] > r) {
            return i;
        }

        total += weights[i];
    }
}

You can of course repeat the second loop as many times as you want, choosing a new r each time, to generate multiple samples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文