Skip to content

Commit

Permalink
renaming ALL_TO_ALL to ALL_TO_ALL_FORWARD
Browse files Browse the repository at this point in the history
  • Loading branch information
raimannma authored and christianechevarria committed Apr 12, 2020
1 parent c67094c commit 7fb8a0e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions src/architecture/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Group(size) {
* let A = new Group(4);
* let B = new Group(5);
*
* A.connect(B, methods.connection.ALL_TO_ALL); // specifying a method is optional
* A.connect(B, methods.connection.ALL_TO_ALL_FORWARD); // specifying a method is optional
*/
self.connect = function(target, method, weight) {
const self_targeted = target.nodes ? self.nodes == target.nodes : false;
Expand All @@ -147,8 +147,8 @@ function Group(size) {
if (config.warnings) console.warn('No group connection specified, using ONE_TO_ONE');
method = methods.connection.ONE_TO_ONE;
} else {
if (config.warnings) console.warn('No group connection specified, using ALL_TO_ALL');
method = methods.connection.ALL_TO_ALL;
if (config.warnings) console.warn('No group connection specified, using ALL_TO_ALL_FORWARD');
method = methods.connection.ALL_TO_ALL_FORWARD;
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ function Group(size) {
const connection = source_nodes[i].connect(target_nodes[i], weight);
new_connections.push(connection);
}
// else (ALL_TO_ELSE or ALL_TO_ALL)
// else (ALL_TO_ELSE or ALL_TO_ALL_FORWARD)
else {
for (let j = 0; j < source_nodes.length; j++) {
// create the connection
Expand Down
32 changes: 16 additions & 16 deletions src/architecture/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ class Layer extends Group {
});

// Set up internal connections
memory_cell.connect(input_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(forget_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(output_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(input_gate, methods.connection.ALL_TO_ALL_FORWARD);
memory_cell.connect(forget_gate, methods.connection.ALL_TO_ALL_FORWARD);
memory_cell.connect(output_gate, methods.connection.ALL_TO_ALL_FORWARD);
const forget_connections = memory_cell.connect(memory_cell, methods.connection.ONE_TO_ONE);
const output_connections = memory_cell.connect(output_block, methods.connection.ALL_TO_ALL);
const output_connections = memory_cell.connect(output_block, methods.connection.ALL_TO_ALL_FORWARD);

input_group.connect(memory_cell, methods.connection.ALL_TO_ALL);
input_group.connect(output_gate, methods.connection.ALL_TO_ALL),
input_group.connect(forget_gate, methods.connection.ALL_TO_ALL);
const input_gate_connections = input_group.connect(input_gate, methods.connection.ALL_TO_ALL);
input_group.connect(memory_cell, methods.connection.ALL_TO_ALL_FORWARD);
input_group.connect(output_gate, methods.connection.ALL_TO_ALL_FORWARD),
input_group.connect(forget_gate, methods.connection.ALL_TO_ALL_FORWARD);
const input_gate_connections = input_group.connect(input_gate, methods.connection.ALL_TO_ALL_FORWARD);


// Set up gates
Expand Down Expand Up @@ -186,27 +186,27 @@ class Layer extends Group {
});

// Initial input forwarding
input_group.connect(update_gate, methods.connection.ALL_TO_ALL),
input_group.connect(reset_gate, methods.connection.ALL_TO_ALL),
input_group.connect(memory_cell, methods.connection.ALL_TO_ALL);
input_group.connect(update_gate, methods.connection.ALL_TO_ALL_FORWARD),
input_group.connect(reset_gate, methods.connection.ALL_TO_ALL_FORWARD),
input_group.connect(memory_cell, methods.connection.ALL_TO_ALL_FORWARD);

// Update gate calculation
previous_output.connect(update_gate, methods.connection.ALL_TO_ALL);
previous_output.connect(update_gate, methods.connection.ALL_TO_ALL_FORWARD);

// Inverse update gate calculation
update_gate.connect(inverse_update_gate, methods.connection.ONE_TO_ONE, 1);

// Reset gate calculation
previous_output.connect(reset_gate, methods.connection.ALL_TO_ALL);
previous_output.connect(reset_gate, methods.connection.ALL_TO_ALL_FORWARD);

// Memory calculation
const reset = previous_output.connect(memory_cell, methods.connection.ALL_TO_ALL);
const reset = previous_output.connect(memory_cell, methods.connection.ALL_TO_ALL_FORWARD);

reset_gate.gate(reset, methods.gating.OUTPUT); // gate

// Output calculation
const update1 = previous_output.connect(output_group, methods.connection.ALL_TO_ALL);
const update2 = memory_cell.connect(output_group, methods.connection.ALL_TO_ALL);
const update1 = previous_output.connect(output_group, methods.connection.ALL_TO_ALL_FORWARD);
const update2 = memory_cell.connect(output_group, methods.connection.ALL_TO_ALL_FORWARD);

update_gate.gate(update1, methods.gating.OUTPUT);
inverse_update_gate.gate(update2, methods.gating.OUTPUT);
Expand Down
28 changes: 14 additions & 14 deletions src/architecture/layer.js.old
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function Layer() {
self.input = function(from, method, weight) {
if(from instanceof Layer) from = from.output;

method = method || methods.connection.ALL_TO_ALL;
method = method || methods.connection.ALL_TO_ALL_FORWARD;

return from.connect(block, method, weight);
};
Expand Down Expand Up @@ -230,7 +230,7 @@ Layer.Dense = function(size) {
layer.input = function(from, method, weight) {
if(from instanceof Layer) from = from.output;

method = method || methods.connection.ALL_TO_ALL;
method = method || methods.connection.ALL_TO_ALL_FORWARD;

let returned_connections = [];
// this if was added later because .from was being called
Expand Down Expand Up @@ -287,11 +287,11 @@ Layer.LSTM = function(size) {
});

// Set up internal connections
memory_cell.connect(input_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(forget_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(output_gate, methods.connection.ALL_TO_ALL);
memory_cell.connect(input_gate, methods.connection.ALL_TO_ALL_FORWARD);
memory_cell.connect(forget_gate, methods.connection.ALL_TO_ALL_FORWARD);
memory_cell.connect(output_gate, methods.connection.ALL_TO_ALL_FORWARD);
const forget = memory_cell.connect(memory_cell, methods.connection.ONE_TO_ONE);
const output = memory_cell.connect(output_block, methods.connection.ALL_TO_ALL);
const output = memory_cell.connect(output_block, methods.connection.ALL_TO_ALL_FORWARD);

// Set up gates
forget_gate.gate(forget, methods.gating.SELF);
Expand All @@ -305,7 +305,7 @@ Layer.LSTM = function(size) {

layer.input = function(from, method, weight) {
if(from instanceof Layer) from = from.output;
method = method || methods.connection.ALL_TO_ALL;
method = method || methods.connection.ALL_TO_ALL_FORWARD;

const input = from.connect(memory_cell, method, weight);

Expand Down Expand Up @@ -370,22 +370,22 @@ Layer.GRU = function(size) {
});

// Update gate calculation
previous_output.connect(update_gate, methods.connection.ALL_TO_ALL);
previous_output.connect(update_gate, methods.connection.ALL_TO_ALL_FORWARD);

// Inverse update gate calculation
update_gate.connect(inverse_update_gate, methods.connection.ONE_TO_ONE, 1);

// Reset gate calculation
previous_output.connect(reset_gate, methods.connection.ALL_TO_ALL);
previous_output.connect(reset_gate, methods.connection.ALL_TO_ALL_FORWARD);

// Memory calculation
const reset = previous_output.connect(memory_cell, methods.connection.ALL_TO_ALL);
const reset = previous_output.connect(memory_cell, methods.connection.ALL_TO_ALL_FORWARD);

reset_gate.gate(reset, methods.gating.OUTPUT); // gate

// Output calculation
const update1 = previous_output.connect(output, methods.connection.ALL_TO_ALL);
const update2 = memory_cell.connect(output, methods.connection.ALL_TO_ALL);
const update1 = previous_output.connect(output, methods.connection.ALL_TO_ALL_FORWARD);
const update2 = memory_cell.connect(output, methods.connection.ALL_TO_ALL_FORWARD);

update_gate.gate(update1, methods.gating.OUTPUT);
inverse_update_gate.gate(update2, methods.gating.OUTPUT);
Expand All @@ -401,7 +401,7 @@ Layer.GRU = function(size) {
layer.input = function(from, method, weight) {
if (from instanceof Layer) from = from.output;

method = method || methods.connection.ALL_TO_ALL;
method = method || methods.connection.ALL_TO_ALL_FORWARD;

const connections = [
from.connect(updateGate, method, weight),
Expand Down Expand Up @@ -464,7 +464,7 @@ Layer.Memory = function(size, memory) {

layer.input = function(from, method, weight) {
if (from instanceof Layer) from = from.output;
method = method || methods.connection.ALL_TO_ALL;
method = method || methods.connection.ALL_TO_ALL_FORWARD;

if (from.nodes.length !== layer.nodes[layer.nodes.length - 1].nodes.length) throw new Error('Previous layer size must be same as memory size');

Expand Down
8 changes: 4 additions & 4 deletions src/methods/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* let A = new Group(4);
* let B = new Group(5);
*
* A.connect(B, methods.connection.ALL_TO_ALL); // specifying a method is optional
* A.connect(B, methods.connection.ALL_TO_ALL_FORWARD); // specifying a method is optional
*
* @example <caption>Group connection with itself</caption>
* let { methods, Group } = require("@liquid-carrot/carrot");
*
* let A = new Group(4);
*
* A.connect(A, methods.connection.ALL_TO_ALL);
* A.connect(A, methods.connection.ALL_TO_ALL_FORWARD);
*/
const connection = {
/**
Expand All @@ -37,9 +37,9 @@ const connection = {
* let A = new Group(4);
* let B = new Group(5);
*
* A.connect(B, methods.connection.ALL_TO_ALL); // specifying a method is optional
* A.connect(B, methods.connection.ALL_TO_ALL_FORWARD); // specifying a method is optional
*/
ALL_TO_ALL: {
ALL_TO_ALL_FORWARD: {
name: 'OUTPUT',
},
/**
Expand Down
10 changes: 5 additions & 5 deletions test/units/architecture/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ describe("Group", function() {
// connect(target, methods.connection[any_method_here]), <- no weight
// connect(target, methods.connection.ONE_TO_ONE, weight),
// connect(target, methods.connection.ALL_TO_ELSE, weight),
// connect(target, methods.connection.ALL_TO_ALL, weight)
it("group.connect(target, methods.connection.ALL_TO_ALL) => {Connection[]}", function() {
// connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight)
it("group.connect(target, methods.connection.ALL_TO_ALL_FORWARD) => {Connection[]}", function() {
let { main_group, other_group } = createRandomGroups(true);
main_group.connect(other_group, methods.connection.ALL_TO_ALL);
main_group.connect(other_group, methods.connection.ALL_TO_ALL_FORWARD);

main_group.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_group.nodes.length);
});
})
it("group.connect(target, methods.connection.ALL_TO_ALL, weight) => {Connection[]}", function() {
it("group.connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight) => {Connection[]}", function() {
let { main_group, other_group } = createRandomGroups(true);
const weight = Math.random();
main_group.connect(other_group, methods.connection.ALL_TO_ALL, weight);
main_group.connect(other_group, methods.connection.ALL_TO_ALL_FORWARD, weight);

main_group.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_group.nodes.length);
Expand Down
14 changes: 7 additions & 7 deletions test/units/architecture/layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,19 @@ describe("Layer", function() {
// connect(target, methods.connection[any_method_here]), <- no weight
// connect(target, methods.connection.ONE_TO_ONE, weight),
// connect(target, methods.connection.ALL_TO_ELSE, weight),
// connect(target, methods.connection.ALL_TO_ALL, weight)
it("layer.connect(target, methods.connection.ALL_TO_ALL) => {Connection[]}", function() {
// connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight)
it("layer.connect(target, methods.connection.ALL_TO_ALL_FORWARD) => {Connection[]}", function() {
let { main_layer, other_layer } = createRandomLayers(true);

main_layer.connect(other_layer, methods.connection.ALL_TO_ALL);
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL_FORWARD);
main_layer.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_layer.nodes.length);
});
})
it("layer.connect(target, methods.connection.ALL_TO_ALL, weight) => {Connection[]}", function() {
it("layer.connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight) => {Connection[]}", function() {
let { main_layer, other_layer } = createRandomLayers(true);
const weight = Math.random();
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL, weight);
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL_FORWARD, weight);

main_layer.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_layer.nodes.length);
Expand Down Expand Up @@ -413,8 +413,8 @@ describe("Layer", function() {
const input_connections_weight = Math.random();
const output_connections_weight = Math.random();

group_for_input.connect(main_created_layer, methods.connection.ALL_TO_ALL, input_connections_weight);
main_created_layer.connect(group_for_output, methods.connection.ALL_TO_ALL, output_connections_weight);
group_for_input.connect(main_created_layer, methods.connection.ALL_TO_ALL_FORWARD, input_connections_weight);
main_created_layer.connect(group_for_output, methods.connection.ALL_TO_ALL_FORWARD, output_connections_weight);

const chain_input = Array(10).fill(0).map(() => Math.random());

Expand Down
10 changes: 5 additions & 5 deletions test/units/architecture/layer.test.js.old
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ describe("Layer", function() {
// connect(target, methods.connection[any_method_here]), <- no weight
// connect(target, methods.connection.ONE_TO_ONE, weight),
// connect(target, methods.connection.ALL_TO_ELSE, weight),
// connect(target, methods.connection.ALL_TO_ALL, weight)
it("layer.connect(target, methods.connection.ALL_TO_ALL) => {Connection[]}", function() {
// connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight)
it("layer.connect(target, methods.connection.ALL_TO_ALL_FORWARD) => {Connection[]}", function() {
let { main_layer, other_layer } = createRandomLayers(true);
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL);
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL_FORWARD);

main_layer.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_layer.nodes.length);
});
})
it("layer.connect(target, methods.connection.ALL_TO_ALL, weight) => {Connection[]}", function() {
it("layer.connect(target, methods.connection.ALL_TO_ALL_FORWARD, weight) => {Connection[]}", function() {
let { main_layer, other_layer } = createRandomLayers(true);
const weight = Math.random();
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL, weight);
main_layer.connect(other_layer, methods.connection.ALL_TO_ALL_FORWARD, weight);

main_layer.nodes.forEach(node => {
expect(node.outgoing.length).equal(other_layer.nodes.length);
Expand Down

0 comments on commit 7fb8a0e

Please sign in to comment.