summaryrefslogtreecommitdiff
path: root/src/genome
diff options
context:
space:
mode:
Diffstat (limited to 'src/genome')
-rw-r--r--src/genome/genome.js9
-rw-r--r--src/genome/genome.test.js25
2 files changed, 34 insertions, 0 deletions
diff --git a/src/genome/genome.js b/src/genome/genome.js
index d35b68c..16b5e4d 100644
--- a/src/genome/genome.js
+++ b/src/genome/genome.js
@@ -120,3 +120,12 @@ export function mut_genome_insert(
[...genome, [source, sink, weight]],
];
}
+
+
+export function mut_genome_delete(
+ [n_input, n_internal, n_output, genome], r
+) {
+ const del_idx = Math.floor(r * genome.length);
+ const new_genome = genome.filter((_, idx) => idx != del_idx);
+ return [n_input, n_internal, n_output, new_genome];
+}
diff --git a/src/genome/genome.test.js b/src/genome/genome.test.js
index d7dbe72..a021073 100644
--- a/src/genome/genome.test.js
+++ b/src/genome/genome.test.js
@@ -8,6 +8,7 @@ import {
mut_gene_weight,
mut_genome_expand,
mut_genome_insert,
+ mut_genome_delete,
} from './genome';
@@ -186,3 +187,27 @@ test('insert new genes', () => {
[[0, 2, -4], [2, 1, 4]]
]);
});
+
+
+test('remove genes', () => {
+ const n_input = 0;
+ const n_output = 0;
+ const n_internal = 3;
+ const genome = [
+ [0, 1, 0], [1, 2, 0],
+ ];
+
+ expect(mut_genome_delete([
+ n_input, n_internal, n_output, genome
+ ], 0.0)).toEqual([
+ n_input, n_internal, n_output,
+ [[1, 2, 0]],
+ ]);
+
+ expect(mut_genome_delete([
+ n_input, n_internal, n_output, genome
+ ], 0.99)).toEqual([
+ n_input, n_internal, n_output,
+ [[0, 1, 0]],
+ ]);
+});