Skip to content

Commit

Permalink
Apply formatting suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Nov 5, 2024
1 parent 97fd5e9 commit 15d35ae
Show file tree
Hide file tree
Showing 26 changed files with 2,186 additions and 1,589 deletions.
26 changes: 26 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
indent = 4
margin = 92
always_for_in = true
for_in_replacement = "in"
whitespace_typedefs = true
whitespace_ops_in_indices = true
remove_extra_newlines = true
import_to_using = true
pipe_to_function_call = true
short_to_long_function_def = false
force_long_function_def = false
long_to_short_function_def = false
always_use_return = true
whitespace_in_kwargs = true
annotate_untyped_fields_with_any = false
format_docstrings = false
conditional_to_if = false
normalize_line_endings = "unix"
trailing_comma = true
trailing_zero = true # TODO
join_lines_based_on_source = false
indent_submodule = false
separate_kwargs_with_semicolon = false
surround_whereop_typeparameters = true
short_circuit_to_if = false
disallow_single_arg_nesting = true
Empty file removed dev/.JuliaFormatter.toml
Empty file.
10 changes: 3 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using CodingTheory, Documenter

Documenter.makedocs(
Documenter.makedocs(;
clean = true,
doctest = true,
modules = Module[CodingTheory],
repo = "",
highlightsig = true,
sitename = "CodingTheory Documentation",
expandfirst = [],
pages = [
"Index" => "index.md",
]
pages = ["Index" => "index.md"],
)

deploydocs(;
repo = "github.com/jakewilliami/CodingTheory.jl.git",
)
deploydocs(; repo = "github.com/jakewilliami/CodingTheory.jl.git")

# deploydocs(
# target = "build",
Expand Down
128 changes: 69 additions & 59 deletions examples/bounds.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/usr/bin/env bash
#=
exec julia -tauto --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
"${BASH_SOURCE[0]}" "$@"
=#

using CSV, DataFrames, StatsPlots, ProgressMeter

include(joinpath(dirname(dirname(@__FILE__)), "src", "CodingTheory.jl"))
Expand All @@ -16,29 +10,29 @@ function integer_search(stop_at::Integer)::Array{Array{Number, 1}}
A = []
upper_bound = 10
increment_bound = 10
processed = []
i = 0
processed = []
i = 0
p = Progress(stop_at, 1) # minimum update interval: 1 second

while true
for q in 1:upper_bound, n in 1:upper_bound, d in 1:upper_bound
# skip configurations that have already been processed
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
(q, n, d) processed && continue
# skip configurations that have already been processed
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
(q, n, d) processed && continue
# note that we actually don't want to filter out non-linear codes
# distance shouldn't be larger than the block length; filter trivial distances of one; we filter out combinations when all are equal; filter out codes that are generalised hamming codes; filter out even distances
# if d < n && ! isone(q) #&& ! CodingTheory.allequal(q, n, d) && ! ishammingperfect(q, n, d) && ! iseven(d) && ! isprimepower(q)
q, n, d = big(q), big(n), big(d)
hb = hamming_bound(q, n, d, no_round)
sb = singleton_bound(q, n, d, no_round)
# if isinteger(hb) #&& ! isone(hb) && ! isone(sb) && hb ≤ sb
push!(processed, (q, n, d))
# i += 1; println("$i:\t$q, $n, $d")
push!(A, [q, n, d, hb, sb])
isequal(length(A), stop_at) && return A
next!(p)
# end
# distance shouldn't be larger than the block length; filter trivial distances of one; we filter out combinations when all are equal; filter out codes that are generalised hamming codes; filter out even distances
# if d < n && ! isone(q) #&& ! CodingTheory.allequal(q, n, d) && ! ishammingperfect(q, n, d) && ! iseven(d) && ! isprimepower(q)
q, n, d = big(q), big(n), big(d)
hb = hamming_bound(q, n, d, no_round)
sb = singleton_bound(q, n, d, no_round)

# if isinteger(hb) #&& ! isone(hb) && ! isone(sb) && hb ≤ sb
push!(processed, (q, n, d))
# i += 1; println("$i:\t$q, $n, $d")
push!(A, [q, n, d, hb, sb])
isequal(length(A), stop_at) && return A
next!(p)
# end
# end
end
upper_bound += increment_bound
Expand All @@ -47,41 +41,52 @@ end

function make_integer_csv(stop_at::Integer)
A = integer_search(stop_at)
D = DataFrame(q = Number[], n = Number[], d = Number[], hamming_bound = Number[], singleton_bound = Number[])
D = DataFrame(;
q = Number[],
n = Number[],
d = Number[],
hamming_bound = Number[],
singleton_bound = Number[],
)

for i in A
push!(D, i)
end

data_file_desktop = joinpath(homedir(), "Desktop", "bound_integers_$(stop_at).csv")
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "bound_integers_$(stop_at).csv")

data_file_desktop = joinpath(homedir(), "Desktop", "bound_integers_$(stop_at).csv")
data_file_other = joinpath(
dirname(dirname(@__FILE__)), "other", "bound_integers_$(stop_at).csv"
)

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
println("\nWrote data to $(data_file_other).")
return println("\nWrote data to $(data_file_other).")
end

function bound_comparison(stop_at::Integer)::Tuple{Int, Array{Array{Number, 1}}}
A = Array{AbstractFloat}[]
processed = []
processed = []
upper_bound = 10
increment_bound = 10
i = 0
i = 0

while true
@showprogress for q in 1:upper_bound, n in 1:upper_bound, d in 1:upper_bound
# skip configurations that have already been processed
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
(q, n, d) processed && continue
# remove q non prime powers
# skip configurations that have already been processed
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
(q, n, d) processed && continue
# remove q non prime powers
if isprimepower(big(q))
hb = hamming_bound(q, n, d)
sb = singleton_bound(q, n, d)
# filter out the more trivial bounds that are one (or if distance is one); filter out distances that are more than or equal to the block length, as they don't make sense in our context; filter out even distances
# if d < n || 1 ∉ (hb, sb, d)
if d < n && ! isone(d) && ! CodingTheory.allequal(q, n, d) && ! iszero(mod(d, 2))
push!(processed, (q, n, d))
# i += 1; println("$i:\t$q, $n, $d")
# filter out the more trivial bounds that are one (or if distance is one); filter out distances that are more than or equal to the block length, as they don't make sense in our context; filter out even distances
# if d < n || 1 ∉ (hb, sb, d)
if d < n &&
!isone(d) &&
!CodingTheory.allequal(q, n, d) &&
!iszero(mod(d, 2))
push!(processed, (q, n, d))
# i += 1; println("$i:\t$q, $n, $d")
comparison = hb > sb ? 1 : (sb > hb ? -1 : 0)
push!(A, [q, n, d, hb, sb, comparison])
isequal(length(A), stop_at) && return stop_at, A
Expand All @@ -93,27 +98,32 @@ function bound_comparison(stop_at::Integer)::Tuple{Int, Array{Array{Number, 1}}}
end

function plot_bound_comparison(stop_at::Integer)
number_of_bounds, A = bound_comparison(stop_at)
D = DataFrame(q = Number[], n = Number[], d = Number[], hamming_bound = Number[], singleton_bound = Number[], comparison = Number[])

for i in A
push!(D, i)
end

data_file_desktop = joinpath(homedir(), "Desktop", "bound_comparison_$(stop_at).csv")
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "bound_comparison_$(stop_at).csv")

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
println("Data written to $(data_file_desktop) and $(data_file_other)")

`Rscript --vanilla "~"/projects/CodingTheory.jl/other/regression-tree.R $data_file_other $stop_at`
println("Regression tree saved at $(joinpath(dirname(dirname(@__FILE__)), "other", "Rplots_$(stop_at).pdf"))")
end
number_of_bounds, A = bound_comparison(stop_at)
D = DataFrame(;
q = Number[],
n = Number[],
d = Number[],
hamming_bound = Number[],
singleton_bound = Number[],
comparison = Number[],
)

for i in A
push!(D, i)
end

data_file_desktop = joinpath(homedir(), "Desktop", "bound_comparison_$(stop_at).csv")
data_file_other = joinpath(
dirname(dirname(@__FILE__)), "other", "bound_comparison_$(stop_at).csv"
)

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
println("Data written to $(data_file_desktop) and $(data_file_other)")

`Rscript --vanilla "~"/projects/CodingTheory.jl/other/regression-tree.R $data_file_other $stop_at`
return println("Regression tree saved at $(joinpath(dirname(dirname(@__FILE__)), "other", "Rplots_$(stop_at).pdf"))",)
end

# make_integer_csv constructs a csv file which looks for hamming bounds (given certain conditions) that are integers before rounding
make_integer_csv(stop_at) # takes a command line argument
Expand Down
48 changes: 31 additions & 17 deletions examples/get_codewords_time_analysis.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/usr/bin/env bash
#=
exec julia --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
"${BASH_SOURCE[0]}" "$@"
=#

using StatsPlots, ProgressMeter, CSV, DataFrames

include(joinpath(dirname(dirname(@__FILE__)), "src", "CodingTheory.jl"))
Expand All @@ -16,34 +10,54 @@ function graphing_time(stop_at::Integer)
stop_n_at = 8
num_of_datapoints = stop_at
data = Matrix{Float64}(undef, num_of_datapoints, 3) # needs 3 columns: q, n, and time

@showprogress for i in 1:num_of_datapoints
q = rand(1:stop_q_at)
n = rand(1:stop_n_at)
time_took = @elapsed get_all_words(q, n)
data[i, :] .= [q, n, time_took]
end

save_path = joinpath(dirname(@__DIR__), "other", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.pdf")
save_path = joinpath(
dirname(@__DIR__),
"other",
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.pdf",
)
theme(:solarized)

plot_points = scatter(data[:,1:2], data[:,3], fontfamily = font("Times"), ylabel = "Time elapsed during calculation [seconds]", clabel = "Value of q or n", label = ["q" "n"], smooth = true)#, xlims = (0, stop_n_at)) # smooth = true


plot_points = scatter(
data[:, 1:2],
data[:, 3];
fontfamily = font("Times"),
ylabel = "Time elapsed during calculation [seconds]",
clabel = "Value of q or n",
label = ["q" "n"],
smooth = true,
)#, xlims = (0, stop_n_at)) # smooth = true

savefig(plot_points, save_path)
println("Plot saved at $save_path.")
D = DataFrame(q = Number[], n = Number[], time = Number[])

D = DataFrame(; q = Number[], n = Number[], time = Number[])

for i in eachrow(data)
push!(D, i)
end

data_file_desktop = joinpath(homedir(), "Desktop", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv")
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv")

data_file_desktop = joinpath(
homedir(),
"Desktop",
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv",
)
data_file_other = joinpath(
dirname(dirname(@__FILE__)),
"other",
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv",
)

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
println("Wrote data to $(data_file_other).")
return println("Wrote data to $(data_file_other).")
end

graphing_time(stop_at)
18 changes: 6 additions & 12 deletions examples/plot_random.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#!/usr/bin/env bash
#=
exec julia -tauto --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
"${BASH_SOURCE[0]}" "$@"
=#

include("plot_random_core.jl")

if isempty(ARGS) || length(ARGS) < 4
throw(error("""
Please specify the number of datapoints you want to calculate from the command line, along with q, n, and d. For example
./examples/plot_random.jl 6 7 3 1000 10000 # q, n, d, num_data_points, selection_set_size
That is respectively: the size of the alphabet; the block length of the words; the distance of the code; the number of datapoints in the code; and the selection set size of each "random" sample.
"""))
throw(error("""
Please specify the number of datapoints you want to calculate from the command line, along with q, n, and d. For example
./examples/plot_random.jl 6 7 3 1000 10000 # q, n, d, num_data_points, selection_set_size
That is respectively: the size of the alphabet; the block length of the words; the distance of the code; the number of datapoints in the code; and the selection set size of each "random" sample.
""",),)
end

global q = parse(Int, ARGS[1])
Expand All @@ -24,4 +18,4 @@ global upper_bound_adjustment = 10
global 🐖 = length(get_codewords_greedy(q, n, d))
global 🍖 = hamming_bound(q, n, d)
global 🐺 = singleton_bound(q, n, d)
graphing(q, n, d, stop_at, m = m)
graphing(q, n, d, stop_at; m = m)
Loading

0 comments on commit 15d35ae

Please sign in to comment.