Skip to content

Commit

Permalink
Merge pull request #10
Browse files Browse the repository at this point in the history
next/release
  • Loading branch information
Bamdad Sabbagh authored Nov 15, 2021
2 parents e38078e + f82122c commit d00716a
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 84 deletions.
96 changes: 94 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ <h6>Novation Launch Control XL (Controller)</h6>
</div>
</dialog>

<!-- Neuron card -->
<div id="neuron-card">
<!-- Select Card -->
<div id="select-card" class="cool-card">
<div class="row header">
<span>Source</span>
<span>Weight</span>
Expand Down Expand Up @@ -910,6 +910,98 @@ <h6>Novation Launch Control XL (Controller)</h6>
</div>
</div>

<!-- Layer Card -->
<div id="layer-card" class="cool-card">
<div class="row header">
<span>Neuron</span>
<span>Bias</span>
<span>Learning rate</span>
<span>Activation</span>
<span>Regularization</span>
<span>Regul. rate</span>
</div>
<div class="row">
<span>#1</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#2</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#3</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#4</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#5</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#6</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#7</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
<div class="row">
<span>#8</span>
<label>
<input class="bias" step="0.1" type="number" />
</label>
<div class="learning-rate"></div>
<div class="activation"></div>
<div class="regularization"></div>
<div class="regularization-rate"></div>
</div>
</div>

<script src="bundle.js"></script>
<!-- Google analytics -->
<script src="analytics.js"></script>
Expand Down
170 changes: 151 additions & 19 deletions src/app/devices/controller.device.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { devicePrototype } from './device/device.prototype';
import { rangeMap } from '../utils/range-map';
import { playgroundFacade } from '../facades/playground.facade';
import { neuronCardUi } from '../ui/neuron-card.ui';
import { selectCardUi } from '../ui/select-card.ui';
import { networkState } from '../state/network.state';
import { mappingsState } from '../state/mappings.state';
import { mappingsUi } from '../ui/mappings.ui';
import { playgroundUi } from '../ui/playground.ui';
import { layerCardUi } from '../ui/layer-card.ui';

/**
* Controller is a unique device that controls the playground.
Expand Down Expand Up @@ -80,15 +81,22 @@ controllerDevice.drawLights = function () {
* Set the mode of the controller.
*/
controllerDevice.updateMode = function () {
if (!this.isInitialized) {
return;
}

this.removeListeners ();

if (this.isDefaultMode) {
if (networkState.isLayerMode) {
this.setLayerMode ();
}
else if (this.isDefaultMode) {
this.setDefaultMode ();
}
else if (this.isSingleMode) {
this.setSingleMode ();
}
else {
else if (this.isMultipleMode) {
this.setMultipleMode ();
}
};
Expand Down Expand Up @@ -250,7 +258,7 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void

// first row: learning rate
if (this.settings.rows.firstPots.indexOf (inputNote) !== -1) {
const index = inputNote - this.settings.rows.firstPots[0];
const index = this.settings.rows.firstPots.indexOf (inputNote);
if (typeof links[index]?.source === 'undefined') {
return;
}
Expand All @@ -264,21 +272,21 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
0,
127,
0,
neuronCardUi.options.learningRate.length - 1,
selectCardUi.options.learningRate.length - 1,
).toString (),
);

const learningRate = neuronCardUi.options.learningRate[learningRateOptionIndex];
const learningRate = selectCardUi.options.learningRate[learningRateOptionIndex];

if (learningRate !== links[index].source.learningRate) {
networkState.updateSourceLearningRate (index, learningRate);
neuronCardUi.setLearningRate (index, learningRate);
selectCardUi.setLearningRate (index, learningRate);
playgroundFacade.updateUI ();
}
}
// second row: activation
else if (this.settings.rows.secondPots.indexOf (inputNote) !== -1) {
const index = inputNote - this.settings.rows.secondPots[0];
const index = this.settings.rows.secondPots.indexOf (inputNote);
if (typeof links[index]?.source === 'undefined') {
return;
}
Expand All @@ -292,15 +300,15 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
0,
127,
0,
neuronCardUi.options.activation.length - 1,
selectCardUi.options.activation.length - 1,
).toString (),
);

const activation = neuronCardUi.options.activation[activationOptionIndex];
const activation = selectCardUi.options.activation[activationOptionIndex];

if (activation !== links[index].source.activation.name) {
networkState.updateSourceActivation (index, activation);
neuronCardUi.setActivation (index, activation);
selectCardUi.setActivation (index, activation);
playgroundFacade.updateUI ();
}
}
Expand All @@ -322,15 +330,15 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
0,
127,
0,
neuronCardUi.options.regularization.length - 1,
selectCardUi.options.regularization.length - 1,
).toString (),
);

const regularization = neuronCardUi.options.regularization[regularizationOptionIndex];
const regularization = selectCardUi.options.regularization[regularizationOptionIndex];

if (regularization !== links[index].source.regularization.name) {
networkState.updateSourceRegularization (index, regularization);
neuronCardUi.setRegularization (index, regularization);
selectCardUi.setRegularization (index, regularization);
playgroundFacade.updateUI ();
}
}
Expand All @@ -342,15 +350,15 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
0,
127,
0,
neuronCardUi.options.regularizationRate.length - 1,
selectCardUi.options.regularizationRate.length - 1,
).toString (),
);

const regularizationRate = neuronCardUi.options.regularizationRate[regularizationRateOptionIndex];
const regularizationRate = selectCardUi.options.regularizationRate[regularizationRateOptionIndex];

if (regularizationRate !== links[index].source.regularizationRate) {
networkState.updateSourceRegularizationRate (index, regularizationRate);
neuronCardUi.setRegularizationRate (index, regularizationRate);
selectCardUi.setRegularizationRate (index, regularizationRate);
playgroundFacade.updateUI ();
}
}
Expand Down Expand Up @@ -394,7 +402,7 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void

if (links[index].hasSnapped) {
networkState.setWeight (index, value);
neuronCardUi.setWeight (index, value);
selectCardUi.setWeight (index, value);
playgroundFacade.updateWeightsUI ();
this.playNote ({
note: this.settings.outputByInput[inputNote],
Expand All @@ -413,7 +421,7 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
const value = rangeMap (e.value, 0, 127, -1, 1);
if (value.toFixed (2) !== links[index].source.bias.toFixed (2)) {
links[index].source.bias = value;
neuronCardUi.setBias (index, value);
selectCardUi.setBias (index, value);
playgroundFacade.updateBiasesUI ();
}
}
Expand All @@ -438,3 +446,127 @@ Object.defineProperty (controllerDevice, 'isMultipleMode', {
return playgroundFacade.selectedNodes.length > 1;
},
});

controllerDevice.setLayerMode = function () {
this.attachButtonsToNeuron ();
this.attachControlsToLayer ();
};

controllerDevice.attachControlsToLayer = function (): void {
const neurons = networkState.neurons[networkState.selectedLayerIndex];

this.playNotes ({
firstNote: this.settings.lights.first,
lastNote: this.settings.lights.last,
color: this.settings.colors.yellow,
});

this.addControlListener ((e) => {
const inputNote = e.controller.number;

// first row: learning rate
if (this.settings.rows.firstPots.indexOf (inputNote) !== -1) {
const index = this.settings.rows.firstPots.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
return;
}

const learningRateOptionIndex = parseInt (
rangeMap (
e.value,
0,
127,
0,
selectCardUi.options.learningRate.length - 1,
).toString (),
);

const learningRate = selectCardUi.options.learningRate[learningRateOptionIndex];

if (learningRate !== neurons[index].learningRate) {
networkState.setLearningRate (parseInt (neurons[index].id), learningRate);
layerCardUi.setLearningRate (index, learningRate);
}
}
else if (this.settings.rows.secondPots.indexOf (inputNote) !== -1) {
const index = this.settings.rows.secondPots.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
return;
}

const activationOptionIndex = parseInt (
rangeMap (
e.value,
0,
127,
0,
selectCardUi.options.activation.length - 1,
).toString (),
);

const activation = selectCardUi.options.activation[activationOptionIndex];

if (activation !== neurons[index].activation.name) {
networkState.setActivation (parseInt (neurons[index].id), activation);
layerCardUi.setActivation (index, activation);
}
}
else if (this.settings.rows.thirdPots.indexOf (inputNote) !== -1) {
const index = this.settings.rows.thirdPots.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
return;
}

// regularization (shifted)
if (this.shifted[index] === true) {
const regularizationOptionIndex = parseInt (
rangeMap (
e.value,
0,
127,
0,
selectCardUi.options.regularization.length - 1,
).toString (),
);

const regularization = selectCardUi.options.regularization[regularizationOptionIndex];

if (regularization !== neurons[index].regularization.name) {
networkState.setRegularization (parseInt (neurons[index].id), regularization);
layerCardUi.setRegularization (index, regularization);
}
}
// regularization rate
else {
const regularizationRateOptionIndex = parseInt (
rangeMap (
e.value,
0,
127,
0,
selectCardUi.options.regularizationRate.length - 1,
).toString (),
);

const regularizationRate = selectCardUi.options.regularizationRate[regularizationRateOptionIndex];

if (regularizationRate !== neurons[index].regularizationRate) {
networkState.setRegularizationRate (parseInt (neurons[index].id), regularizationRate);
layerCardUi.setRegularizationRate (index, regularizationRate);
}
}
}
else if (this.settings.rows.faders.indexOf (inputNote) !== -1) {
const index = this.settings.rows.faders.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
return;
}
const value = rangeMap (e.value, 0, 127, -1, 1);
if (value.toFixed (2) !== neurons[index].bias.toFixed (2)) {
neurons[index].bias = value;
layerCardUi.setBias (index, value);
playgroundFacade.updateBiasesUI ();
}
}
});
};
Loading

0 comments on commit d00716a

Please sign in to comment.