matlab 角度方差

发布于 2024-10-16 17:32:23 字数 370 浏览 14 评论 0原文

我有一个包含角度的矩阵,我需要计算平均值和方差。 对于平均而言,我以这种方式进行: 对于每个角度计算 sin 和 cos 并对所有 sin 和 cos 求和 平均值由 atan2(sin, cos) 给出 它有效 我的问题是如何计算已知平均值的角度方差?

感谢您的回答

我附上我的matlab代码:

for i=1:size(im2,1)

    for j=1:size(im2,2)
        y=y+sin(hue(i, j));
        x=x+cos(hue(i, j));
    end
end
mean=atan2(y, x);

if mean<0

    mean=mean+(2*pi);
end

I have a matrix containing angles and I need to compute the mean and the variance.
for the mean I procede in this way:
for each angles compute sin and cos and sum all sin and all cos
the mean is given by the atan2(sin, cos)
and it works
my question is how to compute the variance of angles knowing the mean?

thank you for the answers

I attach my matlab code:

for i=1:size(im2,1)

    for j=1:size(im2,2)
        y=y+sin(hue(i, j));
        x=x+cos(hue(i, j));
    end
end
mean=atan2(y, x);

if mean<0

    mean=mean+(2*pi);
end

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

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

发布评论

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

评论(4

最初的梦 2024-10-23 17:32:23

为了计算角度的方差,您不能使用标准方差。这是计算角度 var 的公式:

R = 1 - sqrt((sum(sin(angle)))^2 + (sum(cos(angle)))^2)/n;

还有类似的其他公式:

var(angle) = var(sin(angle)) + var(cos(angle));

参考:
http://www.ebi.ac.uk/ thornton-srv/software/PROCHECK/nmr_manual/man_cv.html

In order to compute variance of an angle you can not use standard variance. This is the formulation to compute var of an angles:

R = 1 - sqrt((sum(sin(angle)))^2 + (sum(cos(angle)))^2)/n;

There is similar other formulation as well:

var(angle) = var(sin(angle)) + var(cos(angle));

Ref:
http://www.ebi.ac.uk/thornton-srv/software/PROCHECK/nmr_manual/man_cv.html

明天过后 2024-10-23 17:32:23

我不是 100% 确定你在做什么,但也许这可以通过在 MATLAB 函数中构建实现相同的效果 均值var

>> [file path] = uigetfile;
>> someImage = imread([path file]);
>> hsv = rgb2hsv(someImage);
>> hue = hsv(:,:,1);
>> m = mean(hue(:))

m =

    0.5249

>> v = var(hue(:))

v =

    0.2074

编辑:我假设您有一个图像,因为您的变量名称 hue 。但对于任何矩阵来说都是一样的。

编辑2:也许这就是您正在寻找的:

>> sumsin = sum(sin(hue(:)));
>> sumcos = sum(cos(hue(:)));
>> meanvalue = atan2(sumsin,sumcos)

meanvalue =

    0.5276

>> sumsin = sum(sin((hue(:)-meanvalue).^2));
>> sumcos = sum(cos((hue(:)-meanvalue).^2));
>> variance = atan2(sumsin,sumcos)

variance =

    0.2074

I am not 100% sure what you are doing, but maybe this would achieve the same thing with the build in MATLAB functions mean and var.

>> [file path] = uigetfile;
>> someImage = imread([path file]);
>> hsv = rgb2hsv(someImage);
>> hue = hsv(:,:,1);
>> m = mean(hue(:))

m =

    0.5249

>> v = var(hue(:))

v =

    0.2074

EDIT: I am assuming you have an image because of your variable name hue. But it would be the same for any matrix.

EDIT 2: Maybe that is what you are looking for:

>> sumsin = sum(sin(hue(:)));
>> sumcos = sum(cos(hue(:)));
>> meanvalue = atan2(sumsin,sumcos)

meanvalue =

    0.5276

>> sumsin = sum(sin((hue(:)-meanvalue).^2));
>> sumcos = sum(cos((hue(:)-meanvalue).^2));
>> variance = atan2(sumsin,sumcos)

variance =

    0.2074
旧情别恋 2024-10-23 17:32:23

循环数据的方差不能像实线上无界数据的方差一样对待。 (对于非常小的方差,它们实际上是等价的,但是对于大的方差,等价性就会被破坏。您应该清楚这是为什么。)我推荐 NI Fisher 的循环数据统计分析。本书包含广泛使用的圆方差定义,该定义是根据与角度相对应的单位向量的平均合成长度计算得出的。

>> sumsin = sum(sin((hue(:)-meanvalue).^2));
>> sumcos = sum(cos((hue(:)-meanvalue).^2));

是错误的。你不能这样减去角度。

顺便说一句,这个问题确实与MATLAB无关。您可能可以在统计堆栈交换上发布更多/更好的答案

The variance of circular data can not be treated like the variance of unbounded data on the real line. (For very small variances, they are effectively equivalent, but for large variances the equivalence breaks down. It should be clear to you why this is.) I recommend Statistical Analysis of Circular Data by N.I. Fisher. This book contains a widely-used definition of circular variance that is computed from the mean resultant length of the unit vectors that correspond to the angles.

>> sumsin = sum(sin((hue(:)-meanvalue).^2));
>> sumcos = sum(cos((hue(:)-meanvalue).^2));

is wrong. You can't subtract angles like that.

By the way, this question really has nothing to do with MATLAB. You can probably get more/better answers posting on the statistics stack exchange

养猫人 2024-10-23 17:32:23

我们遇到了同样的问题,在 python 中,我们可以使用 scipy.cirvar 来解决这个问题,它计算假设在某个范围内的样本的循环方差。例如:

from scipy.stats import circvar
circvar([0, 2*np.pi/3, 5*np.pi/3])
# 2.19722457734

circvar([0, 2*np.pi])
# -0.0

所提出的 MATLAB 代码的问题是 [0, 6.28] 的方差应为零。通过查看 scipy.circvar 的实现,它就像:


# Recast samples as radians that range between 0 and 2 pi and calculate the sine and cosine
samples, sin_samp, cos_samp, nmask = _circfuncs_common(samples, high, low)

sin_mean = sin_samp.mean()
cos_mean = cos_samp.mean()

R = np.minimum(1, hypot(sin_mean, cos_mean))
circular_variance = ((high - low)/2.0/pi)**2 * -2 * np.log(R)

We had the same problem and in python, we could fix that with using scipy.cirvar which computes the circular variance for samples assumed to be in a range. For example:

from scipy.stats import circvar
circvar([0, 2*np.pi/3, 5*np.pi/3])
# 2.19722457734

circvar([0, 2*np.pi])
# -0.0

The problem with the proposed MATLAB code is that the variance of [0, 6.28] should be zero. By looking at the implementation of scipy.circvar it is like:


# Recast samples as radians that range between 0 and 2 pi and calculate the sine and cosine
samples, sin_samp, cos_samp, nmask = _circfuncs_common(samples, high, low)

sin_mean = sin_samp.mean()
cos_mean = cos_samp.mean()

R = np.minimum(1, hypot(sin_mean, cos_mean))
circular_variance = ((high - low)/2.0/pi)**2 * -2 * np.log(R)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文