diff --git a/src/genetic.jl b/src/genetic.jl index b145160..1d54800 100644 --- a/src/genetic.jl +++ b/src/genetic.jl @@ -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, diff --git a/src/metrics.jl b/src/metrics.jl index 080e799..74d48e2 100644 --- a/src/metrics.jl +++ b/src/metrics.jl @@ -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