diff options
author | sanine <sanine.not@pm.me> | 2023-10-30 01:00:53 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-10-30 01:00:53 -0500 |
commit | 17fc9fe64f4de1bc58596034c54ddb487f992c9f (patch) | |
tree | a71e5e706dcec5364e51c235603a776e52d1dac6 | |
parent | 9fbeab4652b075fb545cbe54984a91f91be1d627 (diff) |
add mut_genome_delete
-rw-r--r-- | src/genome/genome.js | 9 | ||||
-rw-r--r-- | src/genome/genome.test.js | 25 |
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]],
+ ]);
+});
|