I have got a simple problem to calculate Posterior after some signal disturbances.
Say the input signal is a sequence of 0 and 1 with 70% of chance is 1. And somehow we know that after the transmission, the output have 0 an 1 of equal chance. I want to calculate what the probability when we get 1 in output and it is truly 1 in the input.
I write the following code to implement the simulation. I want to randomly set seeds and see what happened to my simulation.
using Random, StatsBase k = rand(1:2000); Random.seed!(k); t = sample(0:1,weights([0.3,0.7]),1000); Random.seed!(k); r = sample(0:1,weights([0.5,0.5]),1000); Post = sum(t[r.==1])/sum(r[r.==1]) Prior =sum(r[t.==1])/sum(t[t.==1])
The result is not right, with Post always 1.0 and Prior around 0.7.
I am thinking of several potential problems:
- I was conceptually wrong to implement the simulation this way. Maybe r is not the correct realization of t after disturbance, and I should modify t base on my knowledge of the disturbance instead of generating r directly.
- I used sample() in a wrong way.
- I calculated Post and Prior wrongly.
Please help me out on this simulation problem.