From a32853e60029fa7f08d4d713ee613ee03196fbef Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 30 Oct 2023 01:18:23 -0500 Subject: add mut_genome_contract --- src/genome/genome.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/genome/genome.js') diff --git a/src/genome/genome.js b/src/genome/genome.js index 16b5e4d..d2650b5 100644 --- a/src/genome/genome.js +++ b/src/genome/genome.js @@ -106,6 +106,25 @@ export function mut_genome_expand( } +export function mut_genome_contract( + [n_input, n_internal, n_output, genome], r +) { + const contract_idx = Math.floor(n_internal * r) + n_input; + const new_source = (source) => source >= contract_idx ? source-1 : source; + const new_sink = (sink) => sink > contract_idx ? sink-1 : sink; + + const new_genome = genome.map(([source, sink, weight]) => [ + new_source(source), + new_sink(sink), + weight, + ]); + + return [ + n_input, n_internal-1, n_output, new_genome + ]; +} + + export function mut_genome_insert( [n_input, n_internal, n_output, genome], weight_max, -- cgit v1.2.1