本文介绍了添加高斯噪声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .arff 文件,其中包含一个浮点数列表。我需要给每个数字加上高斯噪声,在MATLAB中是:

I have a .arff file which contains a list of float numbers. I need to add to every number a gaussian noise, which in MATLAB would be:

m = m+k*randn(size(m)

其中 m 列表中的数字和 k 是标准偏差,并且值 0.1 什么是 C ++ 相当于 randn()

where m is one of the numbers in the list and k is a standard deviation and has value 0.1. What is the C++ equivalent to randn()?

你能提供一个例子吗?

Could you please provide an example?

推荐答案

c ++标准现在包括随机数的几个分布。

The c++ standard now includes several distributions for random numbers.

您正在查找。

在文档中,您还可以找到代码示例

In the documentation you can also find a code sample

  // construct a trivial random generator engine from a time-based seed:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  std::default_random_engine generator (seed);

  std::normal_distribution<double> distribution (0.0,1.0);

  std::cout << "some Normal-distributed(0.0,1.0) results:" << std::endl;
  for (int i=0; i<10; ++i)
    std::cout << distribution(generator) << std::endl;

赋给构造函数std :: normal_distribution的参数是第一个平均值偏差(1.0)。

The parameters given to the constructor, std::normal_distribution, are first mean (0.0) and standard-deviation (1.0).

这篇关于添加高斯噪声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:00