Skip to content

Commit

Permalink
Add a small bias to differentiate composition with similar fitness
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Jul 15, 2021
1 parent d7bb0b8 commit 26d144d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/genetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
Optimize and set the weigths of an ICN with a given set of configuration `X` and solutions `X_sols`.
"""
function _optimize!(icn, X, X_sols, dom_size, param=nothing; metric=hamming, pop_size=200, iter=100)
fitness = weigths -> loss(X, X_sols, icn, weigths, metric, dom_size, param)
fitness = w -> loss(X, X_sols, icn, w, metric, dom_size, param) + weigths_bias(w)

_icn_ga = GA(
populationSize=pop_size,
Expand Down
5 changes: 5 additions & 0 deletions src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ minkowski(x, X, p) = mapreduce(y -> sum(abs(x .- y)^p)^(1/p), min, X; init = sum
"""
manhattan(x, X) = minkowski(x, X, 1)

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

0 comments on commit 26d144d

Please sign in to comment.