Skip to content

Commit

Permalink
added from to UUID in CRISPR (#315)
Browse files Browse the repository at this point in the history
Co-authored-by: Nigel (MacBook) <nigel@laptop>
  • Loading branch information
nleck and Nigel (MacBook) authored Mar 17, 2024
1 parent 41d7788 commit 4ff081a
Show file tree
Hide file tree
Showing 87 changed files with 392 additions and 235 deletions.
30 changes: 17 additions & 13 deletions src/Creature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { yellow } from "https://deno.land/std@0.219.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.219.1/fmt/duration.ts";
import { emptyDirSync } from "https://deno.land/std@0.219.1/fs/empty_dir.ts";
import { yellow } from "https://deno.land/std@0.220.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.220.1/fmt/duration.ts";
import { emptyDirSync } from "https://deno.land/std@0.220.1/fs/empty_dir.ts";
import {
addTag,
getTag,
Expand Down Expand Up @@ -287,7 +287,7 @@ export class Creature implements CreatureInternal {
pos < compactCreature.neurons.length - compactCreature.output;
pos++
) {
const fromList = compactCreature.efferentConnections(pos).filter(
const fromList = compactCreature.outwardConnections(pos).filter(
(c: SynapseInternal) => {
return c.from !== c.to;
},
Expand All @@ -303,7 +303,7 @@ export class Creature implements CreatureInternal {
},
);
if (toList.length == 1) {
const fromList = compactCreature.efferentConnections(pos).filter(
const fromList = compactCreature.outwardConnections(pos).filter(
(c: SynapseInternal) => {
return c.from !== c.to;
},
Expand Down Expand Up @@ -552,7 +552,7 @@ export class Creature implements CreatureInternal {
`Node ${node.ID()} '${node.type}' has squash: ${node.squash}`,
);
}
const fromList = this.efferentConnections(indx);
const fromList = this.outwardConnections(indx);
if (fromList.length == 0) {
if (this.DEBUG) {
this.DEBUG = false;
Expand Down Expand Up @@ -581,7 +581,7 @@ export class Creature implements CreatureInternal {
"NO_INWARD_CONNECTIONS",
);
}
const fromList = this.efferentConnections(indx);
const fromList = this.outwardConnections(indx);
if (fromList.length == 0) {
if (this.DEBUG) {
this.DEBUG = false;
Expand Down Expand Up @@ -756,7 +756,7 @@ export class Creature implements CreatureInternal {
* @param fromIndx the connections from this neuron by index
* @returns the list of connections from the neuron.
*/
efferentConnections(fromIndx: number): Synapse[] {
outwardConnections(fromIndx: number): Synapse[] {
let results = this.cacheFrom.get(fromIndx);
if (results === undefined) {
results = [];
Expand Down Expand Up @@ -1527,7 +1527,7 @@ export class Creature implements CreatureInternal {
/** Each neuron must have at least one from/to connection */
if (
(
this.efferentConnections(conn.from).length > 1 ||
this.outwardConnections(conn.from).length > 1 ||
this.neurons[conn.from].type === "input"
) && this.inwardConnections(conn.to).length > 1
) {
Expand Down Expand Up @@ -1705,7 +1705,7 @@ export class Creature implements CreatureInternal {
if (this.inFocus(from, focusList)) {
if (
(
this.efferentConnections(from).length > 1 ||
this.outwardConnections(from).length > 1 ||
this.neurons[from].type === "input"
) && this.inwardConnections(to).length > 1
) {
Expand Down Expand Up @@ -1907,7 +1907,7 @@ export class Creature implements CreatureInternal {
) {
if (this.neurons[pos].type == "output") continue;
if (
this.efferentConnections(pos).filter((c) => {
this.outwardConnections(pos).filter((c) => {
return c.from !== c.to;
}).length == 0
) {
Expand Down Expand Up @@ -1966,7 +1966,7 @@ export class Creature implements CreatureInternal {
}

for (let i = this.synapses.length; i--;) {
const exportJSON = (this.synapses[i] as Synapse).exportJSON(
const exportJSON = this.synapses[i].exportJSON(
uuidMap,
);

Expand Down Expand Up @@ -2037,7 +2037,7 @@ export class Creature implements CreatureInternal {
}

for (let i = this.synapses.length; i--;) {
const internalJSON = (this.synapses[i] as Synapse).internalJSON();
const internalJSON = this.synapses[i].internalJSON();

json.synapses[i] = internalJSON;
}
Expand Down Expand Up @@ -2124,6 +2124,10 @@ export class Creature implements CreatureInternal {
synapse.type,
);

if (synapse.tags) {
connection.tags = synapse.tags.slice();
}

if ((synapse as SynapseTrace).trace) {
const cs = this.state.connection(connection.from, connection.to);
const trace = (synapse as SynapseTrace).trace;
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/CreatureUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generate as generateV5 } from "https://deno.land/std@0.219.1/uuid/v5.ts";
import { generate as generateV5 } from "https://deno.land/std@0.220.1/uuid/v5.ts";
import { Creature } from "../Creature.ts";

export class CreatureUtil {
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/ElitismUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
red,
white,
yellow,
} from "https://deno.land/std@0.219.1/fmt/colors.ts";
} from "https://deno.land/std@0.220.1/fmt/colors.ts";
import { getTag } from "https://deno.land/x/[email protected]/mod.ts";
import { Creature } from "../Creature.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/architecture/FineTune.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blue, bold, cyan } from "https://deno.land/std@0.219.1/fmt/colors.ts";
import { blue, bold, cyan } from "https://deno.land/std@0.220.1/fmt/colors.ts";
import { addTag, getTag } from "https://deno.land/x/[email protected]/mod.ts";
import { Creature } from "../Creature.ts";
import { CreatureUtil } from "./CreatureUtils.ts";
Expand Down
6 changes: 3 additions & 3 deletions src/architecture/Neat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { blue } from "https://deno.land/std@0.219.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.219.1/fmt/duration.ts";
import { ensureDirSync } from "https://deno.land/std@0.219.1/fs/ensure_dir.ts";
import { blue } from "https://deno.land/std@0.220.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.220.1/fmt/duration.ts";
import { ensureDirSync } from "https://deno.land/std@0.220.1/fs/ensure_dir.ts";
import {
addTag,
getTag,
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/Neuron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Neuron implements TagsInterface, NeuronInternal {
}

if (this.type == "hidden") {
const fromList = this.creature.efferentConnections(this.index);
const fromList = this.creature.outwardConnections(this.index);
if (fromList.length == 0) {
const targetIndx = Math.min(
1,
Expand Down
5 changes: 5 additions & 0 deletions src/architecture/Synapse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TagInterface } from "https://deno.land/x/[email protected]/mod.ts";
import { SynapseExport, SynapseInternal } from "./SynapseInterfaces.ts";

export class Synapse implements SynapseInternal {
Expand All @@ -6,6 +7,8 @@ export class Synapse implements SynapseInternal {
public type?: "positive" | "negative" | "condition";
public weight: number;

public tags?: TagInterface[];

public static randomWeight() {
return Math.random() * 0.2 - 0.1;
}
Expand Down Expand Up @@ -33,6 +36,7 @@ export class Synapse implements SynapseInternal {
fromUUID: fromUUID,
toUUID: toUUID,
type: this.type,
tags: this.tags ? this.tags.slice() : undefined,
};

return json;
Expand All @@ -44,6 +48,7 @@ export class Synapse implements SynapseInternal {
from: this.from,
to: this.to,
type: this.type,
tags: this.tags ? this.tags.slice() : undefined,
};

return json;
Expand Down
3 changes: 3 additions & 0 deletions src/architecture/SynapseInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { TagInterface } from "https://deno.land/x/[email protected]/mod.ts";
import { SynapseState } from "./CreatureState.ts";

interface SynapseCommon {
weight: number;
type?: "positive" | "negative" | "condition";

tags?: TagInterface[];
}

export interface SynapseInternal extends SynapseCommon {
Expand Down
6 changes: 3 additions & 3 deletions src/architecture/Training.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { blue, yellow } from "https://deno.land/std@0.219.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.219.1/fmt/duration.ts";
import { ensureDirSync } from "https://deno.land/std@0.219.1/fs/ensure_dir.ts";
import { blue, yellow } from "https://deno.land/std@0.220.1/fmt/colors.ts";
import { format } from "https://deno.land/std@0.220.1/fmt/duration.ts";
import { ensureDirSync } from "https://deno.land/std@0.220.1/fs/ensure_dir.ts";
import { Costs } from "../Costs.ts";
import { Creature } from "../Creature.ts";
import { TrainOptions } from "../config/TrainOptions.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/compact/CompactUnused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function removeNeuron(uuid: string, creature: Creature, activation: number) {
const neuron = creature.neurons.find((n) => n.uuid === uuid);
if (neuron?.index) {
let useConstant = false;
const fromList = creature.efferentConnections(neuron.index);
const fromList = creature.outwardConnections(neuron.index);

for (const synapse of fromList) {
const squash = creature.neurons[synapse.to].findSquash();
Expand Down
Loading

0 comments on commit 4ff081a

Please sign in to comment.