diff options
author | sanine-a <sanine.not@pm.me> | 2023-08-10 15:27:32 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-08-10 15:27:32 -0500 |
commit | 49312fea07e56e2d74179f4160a16cac6f614f97 (patch) | |
tree | d46e6c0f88d40b38969c8e844063545b7b7ccd7e /src/genome/genome.js | |
parent | 0460985d38d137fd02db4919c66d316a83d2919e (diff) |
add is_valid()
Diffstat (limited to 'src/genome/genome.js')
-rw-r--r-- | src/genome/genome.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/genome/genome.js b/src/genome/genome.js index e2bf83e..3445fe9 100644 --- a/src/genome/genome.js +++ b/src/genome/genome.js @@ -49,3 +49,22 @@ export function mutate(gene, type, value) { }
+export function is_valid(num_input, num_output, genome) {
+ const [ max_index, max_weight ] = genome.reduce(
+ ([max_index, max_weight ], [ source, sink, weight]) => [
+ Math.max(max_index, source, sink),
+ Math.max(max_weight, Math.abs(weight)),
+ ],
+ [ 0, 0 ]
+ );
+
+ if (max_index < num_input + num_output - 1) {
+ return false;
+ }
+ else if (max_weight > 4.0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+}
|