Skip to content

Commit 1b06660

Browse files
committed
Fix some spelling and format
1 parent 064f8dc commit 1b06660

File tree

10 files changed

+78
-78
lines changed

10 files changed

+78
-78
lines changed

src/CompositionalNetworks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export regularization
3939
export show_layers
4040
export symbols
4141
export transformation_layer
42-
export weigths
43-
export weigths!
44-
export weigths_bias
42+
export weights
43+
export weights!
44+
export weights_bias
4545

4646
# Include utils
4747
include("utils.jl")

src/composition.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Output the composition as a layered collection of `Symbol`s.
4343
symbols(c::Composition) = c.symbols
4444

4545
"""
46-
compose(icn, weigths=nothing)
47-
Return a function composed by some of the operations of a given ICN. Can be applied to any vector of variables. If `weigths` are given, will assign to `icn`.
46+
compose(icn, weights=nothing)
47+
Return a function composed by some of the operations of a given ICN. Can be applied to any vector of variables. If `weights` are given, will assign to `icn`.
4848
"""
49-
function compose(icn::ICN, weigths::BitVector = BitVector())
50-
!isempty(weigths) && weigths!(icn, weigths)
49+
function compose(icn::ICN, weights::BitVector = BitVector())
50+
!isempty(weights) && weights!(icn, weights)
5151
composition, symbols = _compose(icn)
5252
return Composition(composition, symbols)
5353
end

src/icn.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mutable struct ICN
1414
arithmetic::Layer
1515
aggregation::Layer
1616
comparison::Layer
17-
weigths::BitVector
17+
weights::BitVector
1818

1919
function ICN(;
2020
param = Vector{Symbol}(),
@@ -23,7 +23,7 @@ mutable struct ICN
2323
ag_layer = aggregation_layer(),
2424
co_layer = comparison_layer(param),
2525
)
26-
w = generate_weigths([tr_layer, ar_layer, ag_layer, co_layer])
26+
w = generate_weights([tr_layer, ar_layer, ag_layer, co_layer])
2727
return new(tr_layer, ar_layer, ag_layer, co_layer, w)
2828
end
2929
end
@@ -42,40 +42,40 @@ Base.length(icn::ICN) = sum(length, layers(icn))
4242

4343
"""
4444
nbits(icn)
45-
Return the expected number of bits of a viable weigth of an ICN.
45+
Return the expected number of bits of a viable weight of an ICN.
4646
"""
4747
nbits(icn) = mapreduce(l -> exclu(l) ? nbits_exclu(l) : length(l), +, layers(icn))
4848

4949
"""
50-
weigths(icn)
51-
Access the current set of weigths of an ICN.
50+
weights(icn)
51+
Access the current set of weights of an ICN.
5252
"""
53-
weigths(icn) = icn.weigths
53+
weights(icn) = icn.weights
5454

55-
function is_viable(icn::ICN, weigths)
55+
function is_viable(icn::ICN, weights)
5656
_start = 0
5757
_end = 0
5858

5959
for layer in layers(icn)
6060
_start = _end + 1
6161
_end += exclu(layer) ? nbits_exclu(layer) : length(layer)
6262

63-
w = @view weigths[_start:_end]
63+
w = @view weights[_start:_end]
6464

6565
!is_viable(layer, w) && return false
6666
end
6767
return true
6868
end
69-
is_viable(icn::ICN) = is_viable(icn, weigths(icn))
69+
is_viable(icn::ICN) = is_viable(icn, weights(icn))
7070

7171
"""
72-
weigths!(icn, weigths)
73-
Set the weigths of an ICN with a `BitVector`.
72+
weights!(icn, weights)
73+
Set the weights of an ICN with a `BitVector`.
7474
"""
75-
function weigths!(icn, weigths)
76-
length(weigths) == nbits(icn) || @warn icn weigths nbits(icn)
77-
@assert length(weigths) == nbits(icn)
78-
return icn.weigths = weigths
75+
function weights!(icn, weights)
76+
length(weights) == nbits(icn) || @warn icn weights nbits(icn)
77+
@assert length(weights) == nbits(icn)
78+
return icn.weights = weights
7979
end
8080

8181
"""
@@ -84,11 +84,11 @@ Return a formated string with each layers in the icn.
8484
"""
8585
show_layers(icn) = map(show_layer, layers(icn))
8686

87-
generate_weigths(icn::ICN) = generate_weigths(layers(icn))
87+
generate_weights(icn::ICN) = generate_weights(layers(icn))
8888

8989
"""
9090
regularization(icn)
91-
Return the regularization value of an ICN weigths, which is proportional to the normalized number of operations selected in the icn layers.
91+
Return the regularization value of an ICN weights, which is proportional to the normalized number of operations selected in the icn layers.
9292
"""
9393
function regularization(icn)
9494
Σmax = 0
@@ -100,7 +100,7 @@ function regularization(icn)
100100
_start = _end + 1
101101
_end += exclu(layer) ? nbits_exclu(layer) : l
102102
if !exclu(layer)
103-
Σop += selected_size(layer, @view weigths(icn)[_start:_end])
103+
Σop += selected_size(layer, @view weights(icn)[_start:_end])
104104
Σmax += length(layer)
105105
end
106106
end
@@ -132,14 +132,14 @@ function _compose(icn::ICN)
132132
_end += exclu(layer) ? nbits_exclu(layer) : length(layer)
133133

134134
if exclu(layer)
135-
f_id = as_int(@view weigths(icn)[_start:_end])
135+
f_id = as_int(@view weights(icn)[_start:_end])
136136
s = symbol(layer, f_id + 1)
137137
push!(funcs, [functions(layer)[s]])
138138
push!(symbols, [s])
139139
else
140140
layer_funcs = Vector{Function}()
141141
layer_symbs = Vector{Symbol}()
142-
for (f_id, b) in enumerate(@view weigths(icn)[_start:_end])
142+
for (f_id, b) in enumerate(@view weights(icn)[_start:_end])
143143
if b
144144
s = symbol(layer, f_id)
145145
push!(layer_funcs, functions(layer)[s])

src/layer.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ Return a string that contains the elements in a layer.
4545
show_layer(layer) = layer |> functions |> keys |> string
4646

4747
"""
48-
selected_size(layer, layer_weigths)
49-
Return the number of operations selected by `layer_weigths` in `layer`.
48+
selected_size(layer, layer_weights)
49+
Return the number of operations selected by `layer_weights` in `layer`.
5050
"""
51-
selected_size(layer, layer_weigths) = exclu(layer) ? 1 : sum(layer_weigths)
51+
selected_size(layer, layer_weights) = exclu(layer) ? 1 : sum(layer_weights)
5252

5353
"""
5454
is_viable(layer, w)
5555
is_viable(icn)
5656
is_viable(icn, w)
57-
Assert if a pair of layer/icn and weigths compose a viable pattern. If no weigths are given with an icn, it will check the current internal value.
57+
Assert if a pair of layer/icn and weights compose a viable pattern. If no weights are given with an icn, it will check the current internal value.
5858
"""
5959
is_viable(layer::Layer, w) = exclu(layer) ? as_int(w) < length(layer) : any(w)
6060

6161
"""
6262
generate_inclusive_operations(predicate, bits)
6363
generate_exclusive_operation(max_op_number)
64-
Generates the operations (weigths) of a layer with inclusive/exclusive operations.
64+
Generates the operations (weights) of a layer with inclusive/exclusive operations.
6565
"""
6666
function generate_inclusive_operations(predicate, bits)
6767
ind = falses(bits)
@@ -78,11 +78,11 @@ function generate_exclusive_operation(max_op_number)
7878
end
7979

8080
"""
81-
generate_weigths(layers)
82-
generate_weigths(icn)
83-
Generate the weigths of a collection of layers or of an ICN.
81+
generate_weights(layers)
82+
generate_weights(icn)
83+
Generate the weights of a collection of layers or of an ICN.
8484
"""
85-
function generate_weigths(layers)
85+
function generate_weights(layers)
8686
bitvecs = map(
8787
l ->
8888
exclu(l) ? generate_exclusive_operation(length(l)) :

src/layers/comparison.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ co_param_minus_val(x; param, dom_size = 0, nvars = 0) = max(0.0, param - x)
2424

2525
"""
2626
co_euclidian_param(x; param, dom_size)
27-
Compute an euclidian norm with domain size `dom_size`, weigthed by `param`, of a scalar.
27+
Compute an euclidian norm with domain size `dom_size`, weighted by `param`, of a scalar.
2828
"""
2929
function co_euclidian_param(x; param, dom_size, nvars = 0)
3030
return x == param ? 0.0 : (1.0 + abs(x - param) / dom_size)

src/learn.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function learn_compose(
2121
parameters...,
2222
)
2323
icn = ICN(; parameters...)
24-
_, weigths =
24+
_, weights =
2525
optimize!(icn, solutions, non_sltns, dom_size, metric, optimizer; parameters...)
2626
compositions = Dictionary{Composition,Int}()
2727

28-
for (bv, occurences) in pairs(weigths)
28+
for (bv, occurences) in pairs(weights)
2929
set!(compositions, compose(deepcopy(icn), bv), occurences)
3030
end
3131

src/metrics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ minkowski(x, X, p) = mapreduce(Distances.minkowski(x, y, p), min, X)
1515
manhattan(x, X) = mapreduce(y -> Distances.cityblock(x, y), min, X)
1616

1717
"""
18-
weigths_bias(x)
18+
weights_bias(x)
1919
A metric that bias `x` towards operations with a lower bit. Do not affect the main metric.
2020
"""
21-
weigths_bias(x) = sum(p -> p[1] * log2(1.0 + p[2]), enumerate(x)) / length(x)^4
21+
weights_bias(x) = sum(p -> p[1] * log2(1.0 + p[2]), enumerate(x)) / length(x)^4

test/Aqua.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# TODO: Fix the broken tests and remove the `broken = true` flag
66
Aqua.test_all(
77
CompositionalNetworks;
8-
ambiguities=(broken=true,),
9-
deps_compat=false,
10-
piracies=(broken=false,),
8+
ambiguities = (broken = true,),
9+
deps_compat = false,
10+
piracies = (broken = false,),
1111
)
1212

1313
@testset "Ambiguities: CompositionalNetworks" begin
@@ -21,7 +21,7 @@
2121
@testset "Dependencies compatibility (no extras)" begin
2222
Aqua.test_deps_compat(
2323
CompositionalNetworks;
24-
check_extras=false, # ignore = [:Random]
24+
check_extras = false, # ignore = [:Random]
2525
)
2626
end
2727
end

test/genetic.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
generate_population(icn, pop_size
3-
Generate a pôpulation of weigths (individuals) for the genetic algorithm weigthing `icn`.
3+
Generate a pôpulation of weights (individuals) for the genetic algorithm weighting `icn`.
44
"""
55
function generate_population(icn, pop_size)
66
population = Vector{BitVector}()
@@ -10,7 +10,7 @@ end
1010

1111
"""
1212
_optimize!(icn, X, X_sols; metric = hamming, pop_size = 200)
13-
Optimize and set the weigths of an ICN with a given set of configuration `X` and solutions `X_sols`.
13+
Optimize and set the weights of an ICN with a given set of configuration `X` and solutions `X_sols`.
1414
"""
1515
function _optimize!(
1616
icn,
@@ -20,8 +20,8 @@ function _optimize!(
2020
metric,
2121
pop_size,
2222
iterations;
23-
samples=nothing,
24-
memoize=false,
23+
samples = nothing,
24+
memoize = false,
2525
parameters...,
2626
)
2727
inplace = zeros(dom_size, max_icn_length())
@@ -32,32 +32,32 @@ function _optimize!(
3232
f = composition(compo)
3333
S = Iterators.flatten((solutions, _non_sltns))
3434
σ = sum(
35-
x -> abs(f(x; X=inplace, dom_size, parameters...) - metric(x, solutions)),
35+
x -> abs(f(x; X = inplace, dom_size, parameters...) - metric(x, solutions)),
3636
S,
3737
)
38-
return σ + regularization(icn) + weigths_bias(w)
38+
return σ + regularization(icn) + weights_bias(w)
3939
end
4040

4141
_fitness = memoize ? (@memoize Dict memoize_fitness(w) = fitness(w)) : fitness
4242

4343
_icn_ga = GA(;
44-
populationSize=pop_size,
45-
crossoverRate=0.8,
46-
epsilon=0.05,
47-
selection=tournament(2),
48-
crossover=SPX,
49-
mutation=flip,
50-
mutationRate=1.0,
44+
populationSize = pop_size,
45+
crossoverRate = 0.8,
46+
epsilon = 0.05,
47+
selection = tournament(2),
48+
crossover = SPX,
49+
mutation = flip,
50+
mutationRate = 1.0,
5151
)
5252

5353
pop = generate_population(icn, pop_size)
5454
r = Evolutionary.optimize(_fitness, pop, _icn_ga, Evolutionary.Options(; iterations))
55-
return weigths!(icn, Evolutionary.minimizer(r))
55+
return weights!(icn, Evolutionary.minimizer(r))
5656
end
5757

5858
"""
5959
optimize!(icn, X, X_sols, global_iter, local_iter; metric=hamming, popSize=100)
60-
Optimize and set the weigths of an ICN with a given set of configuration `X` and solutions `X_sols`. The best weigths among `global_iter` will be set.
60+
Optimize and set the weights of an ICN with a given set of configuration `X` and solutions `X_sols`. The best weights among `global_iter` will be set.
6161
"""
6262
function optimize!(
6363
icn,
@@ -68,15 +68,15 @@ function optimize!(
6868
dom_size,
6969
metric,
7070
pop_size;
71-
sampler=nothing,
72-
memoize=false,
71+
sampler = nothing,
72+
memoize = false,
7373
parameters...,
7474
)
7575
results = Dictionary{BitVector,Int}()
7676
aux_results = Vector{BitVector}(undef, global_iter)
7777
nt = Base.Threads.nthreads()
7878

79-
@info """Starting optimization of weigths$(nt > 1 ? " (multithreaded)" : "")"""
79+
@info """Starting optimization of weights$(nt > 1 ? " (multithreaded)" : "")"""
8080
samples = isnothing(sampler) ? nothing : sampler(length(solutions) + length(non_sltns))
8181
@qthreads for i = 1:global_iter
8282
@info "Iteration $i"
@@ -93,11 +93,11 @@ function optimize!(
9393
memoize,
9494
parameters...,
9595
)
96-
aux_results[i] = weigths(aux_icn)
96+
aux_results[i] = weights(aux_icn)
9797
end
9898
foreach(bv -> incsert!(results, bv), aux_results)
9999
best = rand(findall(x -> x == maximum(results), results))
100-
weigths!(icn, best)
100+
weights!(icn, best)
101101
return best, results
102102
end
103103

@@ -110,11 +110,11 @@ struct GeneticOptimizer <: AbstractOptimizer
110110
end
111111

112112
function GeneticOptimizer(;
113-
global_iter=Threads.nthreads(),
114-
local_iter=64,
115-
memoize=false,
116-
pop_size=64,
117-
sampler=nothing,
113+
global_iter = Threads.nthreads(),
114+
local_iter = 64,
115+
memoize = false,
116+
pop_size = 64,
117+
sampler = nothing,
118118
)
119119
return GeneticOptimizer(global_iter, local_iter, memoize, pop_size, sampler)
120120
end

0 commit comments

Comments
 (0)