生成具有相同标准差和均值的新列表

发布于 2024-11-01 18:00:08 字数 144 浏览 1 评论 0原文

如何从与原始列表具有相同均值和标准差的随机数生成新列表?

我尝试了 newlist = Mean(list) + std(list)*randn(100,1);我在 Matlab 网站上找到了它,但它生成的标准差和均值与原始值略有不同,因为新的均值总是更大。

How do I generate a new list from random numbers that have the same mean and standard deviation from the original list?

I tried newlist = mean(list) + std(list)*randn(100,1); which I found on the Matlab website but it was generating slightly different std and mean from the original since the new mean is always bigger.

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

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

发布评论

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

评论(2

哭了丶谁疼 2024-11-08 18:00:08

诀窍是生成平均值为 0 且标准差为 1 的随机数。我们通过生成任何旧的随机数,然后修复平均值和标准差来实现这一点。

% generate your random numbers
r = randn(100, 1);

% scale the variance
r2 = r / std(r);

% shift the mean
r3 = r2 - mean(r2);

%check your answer
abs(mean(r3)) < sqrt(eps)
abs(std(r3) - 1) < sqrt(eps)

现在 newlist = Mean(list) + std(list) * r3 应该可以满足您的需求。

The trick is to generate random numbers with mean 0 and std dev 1. We do this by generating any old random numbers, then fixing the mean and standard deviation afterwards.

% generate your random numbers
r = randn(100, 1);

% scale the variance
r2 = r / std(r);

% shift the mean
r3 = r2 - mean(r2);

%check your answer
abs(mean(r3)) < sqrt(eps)
abs(std(r3) - 1) < sqrt(eps)

Now newlist = mean(list) + std(list) * r3 should give you what you need.

吐个泡泡 2024-11-08 18:00:08

很抱歉用问题来回答问题,但我必须问...

为什么需要确保随机数向量的平均值与原始向量完全相同?同样,为什么标准差需要完全相同?

如果我运行蒙特卡洛模拟或类似的模拟,我会尝试发现可能会发生什么。
如果您调整随机数,使平均值恰好为 X,标准差恰好为 Y,您就会降低模拟包含极端事件的机会。反过来,这意味着出现问题的可能性较小。

这些类型的转换作为学术练习很好,但是,我对在现实世界中使用这种类型的方法感到非常担忧。

  1. 你违背了模拟的全部目的
  2. 如果你的方法太敏感以至于不起作用,那么平均值和标准差偏离了任意小的量,这本身就应该告诉你一些事情

Sorry to answer a question with a question, but I have to ask...

Why do you need to ensure that the mean of your vector of random numbers is precisely same as your original vector? In a similar vein, why does the standard deviation need to be precisely the same?

If I run a monte carlo simulation or some such, I'm trying to discover what might happen.
If you adjust your random numbers so that the mean is precisely X and the standard deviation is exactly Y you're decreasing the chance that your simulation will contain an extreme event. In turn, this mean's that its less likely that something is going to go wrong.

These types of transforms are fine as an academic exercise, however, I'd have grave concerns about employing this type of method in the real world.

  1. You're defeating the whole purpose of your simulation
  2. If your methods are so sensitive that they won't work is the mean and standard deviation are off by some arbitrarily small amount this, in and of itself, should tell you something
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文