summaryrefslogtreecommitdiff
path: root/src/genome/genome.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-10-13 12:36:51 -0500
committersanine <sanine.not@pm.me>2023-10-13 12:36:51 -0500
commitac0e4eb51ca2fd595814031087039932729199ae (patch)
tree10e0d3aea2264f680ce239944226cd5d54564069 /src/genome/genome.js
parente257d91ac1a9504a4f058c124fe315034fae2b10 (diff)
implement genome parsing
Diffstat (limited to 'src/genome/genome.js')
-rw-r--r--src/genome/genome.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/genome/genome.js b/src/genome/genome.js
index 71e18c1..0f7275f 100644
--- a/src/genome/genome.js
+++ b/src/genome/genome.js
@@ -1,5 +1,7 @@
'use strict';
+import { network } from '../mind/topology';
+
export const mutation_type = Object.freeze({
none: 'none',
@@ -71,3 +73,19 @@ export function get_size(num_input, num_output, genome) {
return max_index + 1;
}
}
+
+
+export function parse_genome(num_input, num_output, genome) {
+ const size = get_size(num_input, num_output, genome);
+ if (size < 0) {
+ // bad genome
+ throw new Error('invalid genome sequence!');
+ }
+
+ const n = genome.reduce(
+ (acc, [source, sink, weight]) => acc.connect(source, sink, weight),
+ network(num_input, size-num_input-num_output, num_output)
+ );
+
+ return n;
+}