summaryrefslogtreecommitdiff
path: root/src/genome/genome.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-10-30 00:31:47 -0500
committersanine <sanine.not@pm.me>2023-10-30 00:31:47 -0500
commitae504c5f500b523eecb51b41eaf3b51d799d8a5f (patch)
treef8e64ef017ea7ae18540ed6e1cf9f4700367859a /src/genome/genome.js
parent3793cddeb12993da492f9934b59849442c68aa12 (diff)
add mut_genome_expand
Diffstat (limited to 'src/genome/genome.js')
-rw-r--r--src/genome/genome.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/genome/genome.js b/src/genome/genome.js
index c288d02..7688b32 100644
--- a/src/genome/genome.js
+++ b/src/genome/genome.js
@@ -88,3 +88,19 @@ export function mut_gene_weight(weight_max, gene, r) {
clamp(new_weight, -weight_max, weight_max),
];
}
+
+
+export function mut_genome_expand(
+ [n_input, n_internal, n_output, genome], r
+) {
+ const expand_index = Math.floor(n_internal * r) + n_input;
+ const new_genome = genome.map(([source, sink, weight]) => [
+ source >= expand_index ? source+1 : source,
+ sink >= expand_index ? sink+1 : sink,
+ weight,
+ ]);
+
+ return [
+ n_input, n_internal+1, n_output, new_genome,
+ ];
+}