Skip to content

Commit

Permalink
Support for binary symmetric channel
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimneu committed Jan 20, 2019
1 parent 8cf08d2 commit 1abf363
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/BridgeCh2DE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module BridgeCh2DE
using Polar.Channels
using Polar.DensityEvolution
using Polar.CommunicationsUtils
using Polar.Utils


function channeloutputdistribution(ch::BiAWGNChannel)
Expand All @@ -21,4 +22,10 @@ module BridgeCh2DE
return DiscreteDEDistribution{PostPPValue{Tllr,f_map}}(Dict( PostPPValue{Tllr,f_map}(val) => prob for (val, prob) in channeloutputdistribution(ch, Tllr) ))
end

function channeloutputdistribution(ch::BSChannel)
@assert !(ch.p 0.0)
Δ = ln((1-ch.p)/ch.p)
return DiscreteDEDistribution{FloatValue}(Dict( FloatValue(+Δ) => (1-ch.p), FloatValue(-Δ) => ch.p ))
end

end
57 changes: 56 additions & 1 deletion src/Channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__()
module Channels

using SpecialFunctions
using Polar.GF2n: GF2Element, toint
using Polar.GF2n: GF2Element, toint, GF2_0, GF2_1,
using Polar.CommunicationsUtils


Expand Down Expand Up @@ -32,6 +32,7 @@ module Channels
export AbstractCommunicationsChannel
export AWGNChannel, BiAWGNChannel
export BEChannel
export BSChannel
export intype, outtype, get_w, get_f, get_llr

abstract type AbstractCommunicationsChannel end
Expand Down Expand Up @@ -127,4 +128,58 @@ module Channels
return llr
end


struct BSChannel <: AbstractCommunicationsChannel
p::Float64

function BSChannel(p::Float64)
@assert 0.0 <= p <= 0.5
return new(p)
end
end
intype(::Type{BSChannel}) = BinaryAlphabet
outtype(::Type{BSChannel}) = BinaryAlphabet
function get_w(ch::BSChannel, x::BinaryAlphabet)
function w(y::BinaryAlphabet)::Float64
if x == y
return 1-ch.p
else # x != y
return ch.p
end
end
return w
end
function get_f(ch::BSChannel)
function f(x::BinaryAlphabet)::BinaryAlphabet
if rand() <= ch.p
return x GF2_1
else
return x
end
end
return f
end
function get_llr(ch::BSChannel)
if ch.p 0.0
function llr1(y::BinaryAlphabet)
if y == GF2_0
return +Inf
else # y == GF2_1
return -Inf
end
end
return llr1
else
Δ = ln((1-ch.p)/ch.p)
function llr2(y::BinaryAlphabet)
if y == GF2_0
return +Δ
else # y == GF2_1
return -Δ
end
end
return llr2
end
end

end
6 changes: 4 additions & 2 deletions src/SimulationUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ module SimulationUtils
tic!(result, :MLError)
elseif pm_opt == pm_ml
# the list does contain the true data, don't add it
if rand() > 1. / (count(list_pms .== pm_ml) + 0)
# if rand() > 1. / (count(list_pms .== pm_ml) + 0)
if rand() > 1. / (count(x -> x == pm_ml, list_pms) + 0)
tic!(result, :MLError)
end
end
Expand All @@ -258,7 +259,8 @@ module SimulationUtils
tic!(result, :MLError)
elseif pm_opt == pm_ml
# the list does not contain the true data, add it
if rand() > 1. / (count(list_pms .== pm_ml) + 1)
# if rand() > 1. / (count(list_pms .== pm_ml) + 1)
if rand() > 1. / (count(x -> x == pm_ml, list_pms) + 1)
tic!(result, :MLError)
end
end
Expand Down

0 comments on commit 1abf363

Please sign in to comment.