角度的加权平均值

发布于 2024-08-10 10:58:42 字数 361 浏览 6 评论 0原文

我想计算一组角度的加权平均值。

这个问题中,有一个回答如何计算平均值 如此页面所示。

现在我想弄清楚如何计算加权平均值。 即每个角度都有一个权重(权重总和为1)

0.25,0度 0.5、20度 0.25, 90 度

加权平均值(如果我没有犯错的话)应该是 32 度。

I want to calculate the weighted mean of a set of angles.

In this Question, there's an answer how to calculate the mean
as shown in this page.

Now I'm trying to figure out how to calculate the weighted average.
That is, for each angle there is a weight (the weights sum up to 1)

0.25, 0 degrees
0.5, 20 degrees
0.25, 90 degrees

The weighted avg should (if I didn't make a mistake) be 32 degrees.

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

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

发布评论

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

评论(2

野の 2024-08-17 10:58:42

好吧,我的尝试是将这些值与权重相乘:

def circular_mean(weights, angles):
    x = y = 0.
    for angle, weight in zip(angles, weights):
        x += math.cos(math.radians(angle)) * weight
        y += math.sin(math.radians(angle)) * weight

    mean = math.degrees(math.atan2(y, x))
    return mean

似乎工作正常。我必须考虑好的测试数据。

OK, my attemp was to just multiply the values with the weights:

def circular_mean(weights, angles):
    x = y = 0.
    for angle, weight in zip(angles, weights):
        x += math.cos(math.radians(angle)) * weight
        y += math.sin(math.radians(angle)) * weight

    mean = math.degrees(math.atan2(y, x))
    return mean

It SEEMS to work correct. I have to think of good test data.

后eg是否自 2024-08-17 10:58:42

根据您的应用,该问题有不同的答案。如上所述,您可能需要标准化您的值,并且您可能需要有符号角度,或者您可能不希望这样做。除非您知道角度生成函数是什么,否则可能没有唯一的答案。

这对我(从事几何工作)来说是一个足够的问题,我编写了自己的角度类。

Depending on your application the question has different answers. As mentioned above you may need to normalize your values and you may need to have signed angles, or you may not wish to. Unless you know what the angle generating function is there may not be a unique answer.

This was a sufficient problem for me (working in geometry) I wrote my own Angle class.

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