数据扰动 - 如何执行?

Data perturbation - How to perform it?

我正在做一些与使用 R 基于 "Introduction to Scientific Programming and Simulation Using R" 的统计模拟相关的项目,在学生项目 session(第 24 章)中我正在做 "The pipe spiders of Brunswick" 问题,但是我我卡在进化算法的一部分,你需要根据下面的句子进行一些数据扰动:

"向量的每个元素被独立扰动的概率为 0.5 其他的,按正态分布的数量,平均值为 0,标准 偏差 0.1"

"perturbed" 在这里的真正含义是什么?我真的不知道我应该对我的向量进行哪种操作才能使这种扰动发生,而且我找不到这个问题的任何答案。 提前致谢!

扰动只是意味着给一个数字添加一个小的、嘈杂的移位。您的代码可能看起来像这样。

x = sample(10, 10)
ind = rbinom(length(x), 1, 0.5) == 1
x[ind] = x[ind] + rnorm(sum(ind), 0, 0.1)

rbinom 获取要修改的元素概率 0.5 并且 rnorm 添加扰动。

# using the most important features, we create a ML model: 

m1 <- lm(PREDICTED_VALUE ~  PREDICTER_1 + PREDICTER_2 + PREDICTER_N  )
#summary(m1)
#anova(m1)

# after creating the model, we perturb as follows:
#install.packages("perturb") #install the package
library(perturb)
set.seed(1234)  # for same results each time you run the code
p1_new <- perturb(m1, pvars=c("PREDICTER_1","PREDICTER_N") , prange = c(1,1),niter=200)  # your can change the number of iterations to any value n. Total number of iteration would come to be n+1
p1_new  # check the values of p1
summary(p1_new)