In R
language version 4.4.1
(the version should not matter, just for the sake of discussion), we write the code :
set.seed(1234)
x <- 5
y <- rnorm(1, mean = x, sd = 0.1)
We will be able to print the number y
. Suppose that there is a second person, he knows the number y
, that we are using seed 1234
and that he knows the number is generated using this code. The only thing he does not know is the number x
. Can he work out that x=5
?
0
It looks like the source code for rnorm() roughly defines it as:
rnorm(1, mean, sd) = mean + sd * norm_rand()
or using your variable names y = x + 0.1*norm_rand()
So to reverse it, I’d think the following would work:
set.seed(1234)
x <- y - 0.1*norm_rand()
If norm_rand() isn’t an exposed function, I think you could replace it with rnorm(1,0,1)
I’m not an ‘R’ coder, and haven’t tried this myself, but it looks straightforward.
2
If we knew x was an integer, we could try to estimate how much the normal distribution is shifted by subtracting a normal distribution with mean 0 and same sd from y to see how much it is shifted.
> set.seed(1234)
> x <- 5
> y <- rnorm(1, mean=x, sd=0.1)
> f <- (y, sd) {y - rnorm(1L, 0, sd)}
> est <- replicate(10, f(y, 0.1))
> summary(est)
Min. 1st Qu. Median Mean 3rd Qu. Max.
4.771 4.840 4.930 4.910 4.937 5.114
This would strongly suggest x == 5
.
The problem is that this only works for x integer or when SD is very low and would fail dramatically if it was higher:
> set.seed(1234)
> x <- 5
> y <- rnorm(1, mean=x, sd=2)
> f <- (y, sd) {y - rnorm(1L, 0, 2)}
> est <- replicate(1e3, f(y, 2))
> summary(est)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.806 1.354 2.665 2.639 3.932 9.378
You probably had a low SD in mind when you did your thought experiment?