diff --git a/test/CRISPR.ts b/test/CRISPR.ts index 76d3d59b..29cdd60c 100644 --- a/test/CRISPR.ts +++ b/test/CRISPR.ts @@ -131,7 +131,7 @@ Deno.test("REMOVE", () => { } }); -Deno.test("CRISPR-multi-outputs", () => { +Deno.test("CRISPR-multi-outputs1", () => { const json: NetworkInternal = { nodes: [ { type: "hidden", squash: "LOGISTIC", bias: -1, index: 3, uuid: "h1" }, @@ -208,3 +208,81 @@ Deno.test("CRISPR-multi-outputs", () => { Deno.writeTextFileSync("test/data/CRISPR/.actual-sane.json", actualTXT); assertEquals(actualTXT, expectedTXT, "should have converted"); }); + +Deno.test("CRISPR-multi-outputs2", () => { + const json: NetworkInternal = { + nodes: [ + { type: "hidden", squash: "LOGISTIC", bias: -1, index: 3, uuid: "h1" }, + // { type: "hidden", squash: "LOGISTIC", bias: -0.5, index: 4, uuid: "h2" }, + // { type: "hidden", squash: "LOGISTIC", bias: 0, index: 5, uuid: "h3" }, + // { type: "hidden", squash: "LOGISTIC", bias: 0.5, index: 6, uuid: "h4" }, + // { type: "hidden", squash: "MEAN", bias: -0.25, index: 7, uuid: "h5" }, + { + type: "output", + squash: "IDENTITY", + index: 4, + uuid: "h6", + bias: 0, + }, + { + type: "output", + squash: "IDENTITY", + index: 5, + uuid: "h7", + bias: 0, + }, + { + type: "output", + squash: "LOGISTIC", + index: 6, + uuid: "h8", + bias: 0, + }, + ], + connections: [ + { from: 1, to: 3, weight: 0.1 }, + { from: 2, to: 4, weight: 0.2 }, + { from: 3, to: 5, weight: 0.3 }, + // { from: 3, to: 4, weight: 0.3 }, + { from: 2, to: 6, weight: 0.4 }, + // { from: 5, to: 10, weight: 0.4 }, + // { from: 1, to: 6, weight: 0.5 }, + // { from: 4, to: 7, weight: 0.7 }, + // { from: 6, to: 8, weight: 0.8 }, + // { from: 7, to: 9, weight: 0.9 }, + ], + input: 3, + output: 3, + }; + const network = Network.fromJSON(json); + Deno.writeTextFileSync( + "test/data/CRISPR/.network-sane2.json", + JSON.stringify(network.internalJSON(), null, 2), + ); + network.validate(); + const crispr = new CRISPR(network); + const dnaTXT = Deno.readTextFileSync("test/data/CRISPR/DNA-SANE.json"); + + const networkSANE = Network.fromJSON(crispr.apply(JSON.parse(dnaTXT))); + networkSANE.validate(); + const expectedJSON = JSON.parse( + Deno.readTextFileSync("test/data/CRISPR/expected-sane2.json"), + ); + + const expectedTXT = JSON.stringify( + Network.fromJSON(expectedJSON).internalJSON(), + null, + 2, + ); + + Deno.writeTextFileSync("test/data/CRISPR/.expected-sane2.json", expectedTXT); + + const actualTXT = JSON.stringify( + networkSANE.internalJSON(), + null, + 2, + ); + + Deno.writeTextFileSync("test/data/CRISPR/.actual-sane2.json", actualTXT); + assertEquals(actualTXT, expectedTXT, "should have converted"); +}); diff --git a/test/data/CRISPR/expected-sane2.json b/test/data/CRISPR/expected-sane2.json new file mode 100644 index 00000000..16ef83d3 --- /dev/null +++ b/test/data/CRISPR/expected-sane2.json @@ -0,0 +1,140 @@ +{ + "nodes": [ + { + "type": "hidden", + "index": 3, + "uuid": "h1", + "bias": -1, + "squash": "LOGISTIC" + }, + { + "type": "hidden", + "index": 4, + "uuid": "h6", + "bias": 0, + "squash": "IDENTITY" + }, + { + "type": "hidden", + "index": 5, + "uuid": "h7", + "bias": 0, + "squash": "IDENTITY" + }, + { + "type": "hidden", + "index": 6, + "uuid": "h8", + "bias": 0, + "squash": "LOGISTIC" + }, + { + "type": "output", + "index": 7, + "uuid": "ed56a8a6-001-4a53-9eab-583c499d231b", + "bias": -0.0001, + "squash": "MINIMUM", + "tags": [ + { + "name": "CRISPR", + "value": "Sane Output" + } + ] + }, + { + "type": "output", + "index": 8, + "uuid": "ed56a8a6-002-4a53-9eab-583c499d231b", + "bias": 0, + "squash": "MEAN", + "tags": [ + { + "name": "CRISPR", + "value": "Sane Output" + } + ] + }, + { + "type": "output", + "index": 9, + "uuid": "ed56a8a6-003-4a53-9eab-583c499d231b", + "bias": 0.0001, + "squash": "MAXIMUM", + "tags": [ + { + "name": "CRISPR", + "value": "Sane Output" + } + ] + } + ], + "connections": [ + { + "weight": 0.1, + "from": 1, + "to": 3 + }, + { + "weight": 0.2, + "from": 2, + "to": 4 + }, + { + "weight": 0.4, + "from": 2, + "to": 6 + }, + { + "weight": 0.3, + "from": 3, + "to": 5 + }, + { + "weight": 1, + "from": 4, + "to": 7 + }, + { + "weight": 1, + "from": 4, + "to": 8 + }, + { + "weight": 1, + "from": 4, + "to": 9 + }, + { + "weight": 1, + "from": 5, + "to": 7 + }, + { + "weight": 1, + "from": 5, + "to": 8 + }, + { + "weight": 1, + "from": 5, + "to": 9 + }, + { + "weight": 1, + "from": 6, + "to": 7 + }, + { + "weight": 1, + "from": 6, + "to": 8 + }, + { + "weight": 1, + "from": 6, + "to": 9 + } + ], + "input": 3, + "output": 3 +}