|
| 1 | +using Revise |
| 2 | +using BosonSampling |
1 | 3 | using Permanents
|
2 |
| -using Plots |
3 |
| -using Test |
4 |
| -using Combinatorics |
5 |
| -using Random |
6 |
| -using IterTools |
7 |
| -using Statistics |
8 |
| -using LinearAlgebra #removed so as to be able to use generic types such as BigFloats, can be put back if needed |
9 |
| -using PolynomialRoots |
10 |
| -using StatsBase |
11 |
| -#using JLD |
12 |
| -using CSV |
13 |
| -using DataFrames |
14 |
| -using Tables |
15 |
| -using Plots#; plotly() #plotly allows to make "dynamic" plots where you can point the mouse and see the values, they can also be saved like that but note that this makes them heavy (and html instead of png) |
16 |
| -using PrettyTables #to display large matrices |
17 |
| -using Roots |
18 |
| -using BenchmarkTools |
19 |
| -using Optim |
20 |
| -using ProgressMeter |
21 |
| -using Parameters |
| 4 | +using PrettyTables |
22 | 5 | using ArgCheck
|
23 |
| -using Distributions:Normal |
| 6 | +using Test |
| 7 | + |
| 8 | +### multiple counts buisness ### |
| 9 | + |
| 10 | + |
| 11 | +### first, a simple bayesian estimator ### |
| 12 | + |
| 13 | +confidence(χ) = χ/(1+χ) |
| 14 | + |
| 15 | +function update_confidence(event, p_q, p_a, χ) |
| 16 | + |
| 17 | + χ *= p_q(event)/p_a(event) |
| 18 | + χ |
| 19 | + |
| 20 | +end |
| 21 | + |
| 22 | +function compute_χ(events, p_q, p_a) |
| 23 | + χ = 1. |
| 24 | + for event in events |
| 25 | + χ = update_confidence(event, p_q, p_a, χ) |
| 26 | + end |
| 27 | + χ |
| 28 | +end |
| 29 | + |
| 30 | +function compute_confidence(events,p_q, p_a) |
| 31 | + |
| 32 | + """a bayesian confidence estimator: |
| 33 | +
|
| 34 | + returns the probability that the null hypothesis Q is right compared to |
| 35 | + the alternative hypothesis A |
| 36 | +
|
| 37 | + the functions take in events |
| 38 | + p_q is a function that takes in an event and gives its probability in the null hypothesis |
| 39 | + p_a is the same for the alternative hypothesis |
| 40 | + χ is the ratio between null hypothesis probabilities and alternative ones |
| 41 | +
|
| 42 | + """ |
| 43 | + |
| 44 | + confidence(compute_χ(events,p_q, p_a)) |
| 45 | +end |
| 46 | + |
| 47 | +function compute_confidence_array(events, p_q, p_a) |
| 48 | + |
| 49 | + """gives an array of the probability of H being true |
| 50 | + as we process more and more events""" |
| 51 | + |
| 52 | + χ_array = [1.] |
| 53 | + |
| 54 | + for event in events |
| 55 | + push!(χ_array, update_confidence(event, p_q, p_a, χ_array[end])) |
| 56 | + end |
| 57 | + |
| 58 | + confidence.(χ_array) |
| 59 | + |
| 60 | +end |
| 61 | + |
| 62 | +### tests with standard boson sampling ### |
| 63 | + |
| 64 | +# we will test that we are indeed in the bosonic case |
| 65 | +# compared to the distinguishable one |
| 66 | + |
| 67 | +# first we generate a series of bosonic events |
| 68 | + |
| 69 | +n_events = 10 |
| 70 | +n = 3 |
| 71 | +m = 4 |
| 72 | +interf = RandHaar(m) |
| 73 | +input_state = Input{Bosonic}(first_modes(n,m)) |
| 74 | + |
| 75 | +events = [] |
| 76 | + |
| 77 | +OutputMeasurement{FockDetection}(random_mode_occupation_collisionless(n,m)) |
| 78 | + |
| 79 | +for i in 1:n_events |
| 80 | + |
| 81 | + # generate a random output pattern |
| 82 | + output_state = FockDetection(random_mode_occupation_collisionless(n,m)) |
| 83 | + |
| 84 | + # compute the event probability |
| 85 | + this_event = Event(input_state, output_state, interf) |
| 86 | + compute_probability!(this_event) |
| 87 | + push!(events, this_event) |
| 88 | + |
| 89 | +end |
| 90 | + |
| 91 | +# now we have the vector of observed events with probabilities |
| 92 | + |
| 93 | +events |
| 94 | + |
| 95 | +# next, from events, recover the probabilities under both |
| 96 | +# hypothesis |
| 97 | + |
| 98 | +function p_B(event::Event) |
| 99 | + |
| 100 | + interf = event.interferometer |
| 101 | + r = event.input_state.r |
| 102 | + input_state = Input{Bosonic}(r) |
| 103 | + output_state = event.output_measurement |
| 104 | + |
| 105 | + event_H = Event(input_state, output_state, interf) |
| 106 | + compute_probability!(event_H) |
| 107 | + |
| 108 | + event_H.proba_params.probability |
| 109 | + |
| 110 | +end |
| 111 | + |
| 112 | +function p_D(event::Event) |
| 113 | + |
| 114 | + interf = event.interferometer |
| 115 | + r = event.input_state.r |
| 116 | + input_state = Input{Distinguishable}(r) |
| 117 | + output_state = event.output_measurement |
| 118 | + |
| 119 | + event_A = Event(input_state, output_state, interf) |
| 120 | + compute_probability!(event_A) |
24 | 121 |
|
25 |
| -const ATOL = 1e-10 |
| 122 | + event_A.proba_params.probability |
26 | 123 |
|
| 124 | +end |
27 | 125 |
|
28 |
| -include("special_matrices.jl") |
29 |
| -include("matrix_tests.jl") |
30 |
| -include("proba_tools.jl") |
31 |
| -include("type_functions.jl") |
32 |
| -include("types/types.jl") |
33 |
| -include("scattering.jl") |
| 126 | +# hypothesis : the events were from a bosonic distribution |
34 | 127 |
|
35 |
| -include("circuits/circuit_elements.jl") |
| 128 | +p_q = p_B |
| 129 | +p_a = p_D |
36 | 130 |
|
37 |
| -include("partitions/legacy.jl") |
38 |
| -include("partitions/partitions.jl") |
| 131 | +confidence(compute_χ(events, p_q, p_a)) |
39 | 132 |
|
40 |
| -include("bunching/bunching.jl") |
| 133 | +# hypothesis : the events were from a distinguishable distribution |
41 | 134 |
|
| 135 | +p_q = p_D |
| 136 | +p_a = p_B |
42 | 137 |
|
| 138 | +confidence(compute_χ(events, p_q, p_a)) |
43 | 139 |
|
44 |
| -include("permanent_conjectures/bapat_sunder.jl") |
45 |
| -include("permanent_conjectures/counter_example_functions.jl") |
46 |
| -include("permanent_conjectures/counter_example_numerical_search.jl") |
47 |
| -include("permanent_conjectures/permanent_on_top.jl") |
| 140 | +@test confidence(compute_χ(events, p_q, p_a)) + confidence(compute_χ(events, p_a, p_q)) ≈ 1 atol = 1e-10 |
48 | 141 |
|
49 |
| -permanent = ryser |
| 142 | +##### the only thing I see is a problem in the probabilities themselves? |
| 143 | +####### it just looks like stuff is inversed somewhere... |
0 commit comments