Skip to content

Commit

Permalink
preliminary spoofing figures
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitseron committed Jun 17, 2024
1 parent 0bfd27c commit 5972d27
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Binary file added spoofing_high_density.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spoofing_no_collision.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions src/spoofing/spoofing_trials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,78 @@ using LinearRegression
using DataStructures





function tvd_two_partitions(n,m,n_subsets)
ib = Input{Bosonic}(first_modes(n,m))
interf = RandHaar(m)
part_a = random_partition(m,n_subsets)
part_b = part_a
while part_a == part_b
part_b = random_partition(m,n_subsets)
end

o_a = PartitionCountsAll(part_a)
o_b = PartitionCountsAll(part_b)

ev_a = Event(ib,o_a,interf)
ev_b = Event(ib,o_b,interf)

compute_probability!(ev_a)
compute_probability!(ev_b)

tvd(ev_a.proba_params.probability.proba, ev_b.proba_params.probability.proba)

end

function variation_two_partitions(n,m, n_subsets, n_iter)
tvd_array = zeros(n_iter)
for i in 1:n_iter
tvd_array[i] = tvd_two_partitions(n,m,n_subsets)
end

mean_tvd = mean(tvd_array)
std_tvd = std(tvd_array)
return mean_tvd, std_tvd
end

n_array = 2:1:12
m_array = n_array
n_subsets_array = 2:3
n_iter = 100

plt = plot()



for n_subset in n_subsets_array
mean_tvd_array = []
std_tvd_array = []


for (i,n) in enumerate(n_array)
if n_subset <= n

@show (n,m_array[i], n_subset, n_iter)
mean_tvd, std_tvd = variation_two_partitions(n,m_array[i], n_subset, n_iter)
push!(mean_tvd_array, mean_tvd)
push!(std_tvd_array, std_tvd)

else

push!(mean_tvd_array, NaN)
push!(std_tvd_array, NaN)
end
end
plot!(plt, n_array, mean_tvd_array, ribbon = std_tvd_array, label = "n_subsets = $n_subset")
end

xlabel!(L"n")
ylabel!(L"tvd")
title!("spoofabilitiy - high density regime")
# title!("spoofabilitiy - no collision regime")
plt

# savefig(plt, "spoofing_no_collision.png")
savefig(plt, "spoofing_high_density.png")
28 changes: 28 additions & 0 deletions src/types/partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,34 @@ function partition_from_subset_lengths(subset_lengths)
Partition(convert(Vector{Subset}, subsets))

end
function random_partition(m::Int, n_subsets::Int)
if n_subsets > m
error("Number of subsets cannot be greater than the size of the interval")
end

# Generate `n_subsets - 1` unique random cut points
cut_points = sort(unique(rand(1:(m-1), n_subsets - 1)))

# Ensure we have exactly `n_subsets - 1` cut points
while length(cut_points) < n_subsets - 1
new_points = sort(unique(rand(1:(m-1), n_subsets - 1 - length(cut_points))))
cut_points = sort(unique(vcat(cut_points, new_points)))
end

# Add the start and end points of the interval
cut_points = [0; cut_points; m]

# Create the partitions based on the cut points
partitions = [((cut_points[i] + 1):(cut_points[i+1])) for i in 1:n_subsets]

lengths = [length(partitions[i]) for i in 1:n_subsets]

try
return partition_from_subset_lengths(lengths)
catch
error("invalid subset: $partitions")
end
end

"""
equilibrated_partition_vector(m,n_subsets)
Expand Down

0 comments on commit 5972d27

Please sign in to comment.