Skip to content

Commit

Permalink
Merge pull request #17 from CooLearning/next/release
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamdad Sabbagh authored Nov 17, 2021
2 parents e24a224 + 4c2b36d commit 7990b03
Show file tree
Hide file tree
Showing 7 changed files with 485 additions and 177 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ <h1 class="l--page">Tinker With a
<label for="learningRate">Learning rate</label>
<div class="select">
<select id="learningRate">
<option value="0">0</option>
<option value="0.00001">0.00001</option>
<option value="0.0001">0.0001</option>
<option value="0.001">0.001</option>
Expand Down
92 changes: 50 additions & 42 deletions src/app/devices/controller.device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,23 @@ controllerDevice.attachButtonsDefault = function () {
}

const note = parseInt (e.note.number);
const { isLearning, learningParameter } = mappingsState;

// learning a new mapping
const { isLearning, learningParameter } = mappingsState;
if (isLearning && learningParameter) {
mappingsUi.learn ({
parameter: learningParameter,
control: note,
type: 'button',
});
}

// update targets of already mapped parameters
const mappedParameters = mappingsState.getParametersByControl (note);
mappedParameters.forEach ((parameter) => {
playgroundUi.updateParameter (parameter, 1);
});
else {
const mappedParameters = mappingsState.getParametersByControl (note);
mappedParameters.forEach ((parameter) => {
playgroundUi.updateParameter (parameter, 1);
});
}

// draw feedback lights
this.playNote ({
Expand Down Expand Up @@ -280,9 +281,9 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void

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

if (learningRate !== links[index].source.learningRate) {
networkState.updateSourceLearningRate (index, learningRate);
selectCardUi.setLearningRate (index, learningRate);
const hasChanged = networkState.setSourceLearningRate (index, learningRate);
if (hasChanged) {
selectCardUi.updateSourceLearningRate (index, learningRate);
playgroundFacade.updateUI ();
}
}
Expand All @@ -308,9 +309,9 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void

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

if (activation !== links[index].source.activation.name) {
networkState.updateSourceActivation (index, activation);
selectCardUi.setActivation (index, activation);
const hasChanged = networkState.setSourceActivation (index, activation);
if (hasChanged) {
selectCardUi.updateSourceActivation (index, activation);
playgroundFacade.updateUI ();
}
}
Expand All @@ -337,10 +338,9 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
);

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

if (regularization !== links[index].source.regularization.name) {
networkState.updateSourceRegularization (index, regularization);
selectCardUi.setRegularization (index, regularization);
const hasChanged = networkState.setSourceRegularizationType (index, regularization);
if (hasChanged) {
selectCardUi.updateSourceRegularizationType (index, regularization);
playgroundFacade.updateUI ();
}
}
Expand All @@ -358,9 +358,9 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void

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

if (regularizationRate !== links[index].source.regularizationRate) {
networkState.updateSourceRegularizationRate (index, regularizationRate);
selectCardUi.setRegularizationRate (index, regularizationRate);
const hasChanged = networkState.setSourceRegularizationRate (index, regularizationRate);
if (hasChanged) {
selectCardUi.updateSourceRegularizationRate (index, regularizationRate);
playgroundFacade.updateUI ();
}
}
Expand Down Expand Up @@ -403,9 +403,11 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
}

if (links[index].hasSnapped) {
networkState.setWeight (index, value);
selectCardUi.setWeight (index, value);
playgroundFacade.updateWeightsUI ();
const hasChanged = networkState.setSourceWeight (index, value);
if (hasChanged) {
selectCardUi.updateSourceWeight (index, value);
playgroundFacade.updateWeightsUI ();
}
this.playNote ({
note: this.settings.outputByInput[inputNote],
color: this.settings.colorByState.snap,
Expand All @@ -421,9 +423,9 @@ controllerDevice.attachControlsToNeuron = function (selectedNode: number): void
// biases
else {
const value = rangeMap (e.value, 0, 127, -1, 1);
if (value.toFixed (2) !== links[index].source.bias.toFixed (2)) {
links[index].source.bias = value;
selectCardUi.setBias (index, value);
const hasChanged = networkState.setSourceBias (index, value);
if (hasChanged) {
selectCardUi.updateSourceBias (index, value);
playgroundFacade.updateBiasesUI ();
}
}
Expand Down Expand Up @@ -514,7 +516,7 @@ controllerDevice.attachControlsToLayer = function (): void {
this.addControlListener ((e) => {
const inputNote = e.controller.number;

// first row: learning rate
// learning rate
if (this.settings.rows.firstPots.indexOf (inputNote) !== -1) {
const index = this.settings.rows.firstPots.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
Expand All @@ -533,11 +535,13 @@ controllerDevice.attachControlsToLayer = function (): void {

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

if (learningRate !== neurons[index].learningRate) {
networkState.setLearningRate (parseInt (neurons[index].id), learningRate);
layerCardUi.setLearningRate (index, learningRate);
const hasChanged = networkState.setLearningRate (index, learningRate);
if (hasChanged) {
layerCardUi.updateLearningRate (index, learningRate);
playgroundFacade.updateUI ();
}
}
// activation
else if (this.settings.rows.secondPots.indexOf (inputNote) !== -1) {
const index = this.settings.rows.secondPots.indexOf (inputNote);
if (neurons[index].isEnabled === false) {
Expand All @@ -556,9 +560,10 @@ controllerDevice.attachControlsToLayer = function (): void {

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

if (activation !== neurons[index].activation.name) {
networkState.setActivation (parseInt (neurons[index].id), activation);
layerCardUi.setActivation (index, activation);
const hasChanged = networkState.setActivation (index, activation);
if (hasChanged) {
layerCardUi.updateActivation (index);
playgroundFacade.updateUI ();
}
}
else if (this.settings.rows.thirdPots.indexOf (inputNote) !== -1) {
Expand All @@ -567,7 +572,7 @@ controllerDevice.attachControlsToLayer = function (): void {
return;
}

// regularization (shifted)
// regularization type (shifted)
if (this.shifted[index] === true) {
const regularizationOptionIndex = parseInt (
rangeMap (
Expand All @@ -581,9 +586,10 @@ controllerDevice.attachControlsToLayer = function (): void {

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

if (regularization !== neurons[index].regularization.name) {
networkState.setRegularization (parseInt (neurons[index].id), regularization);
layerCardUi.setRegularization (index, regularization);
const hasChanged = networkState.setRegularizationType (index, regularization);
if (hasChanged) {
layerCardUi.updateRegularizationType (index);
playgroundFacade.updateUI ();
}
}
// regularization rate
Expand All @@ -600,21 +606,23 @@ controllerDevice.attachControlsToLayer = function (): void {

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

if (regularizationRate !== neurons[index].regularizationRate) {
networkState.setRegularizationRate (parseInt (neurons[index].id), regularizationRate);
layerCardUi.setRegularizationRate (index, regularizationRate);
const hasChanged = networkState.setRegularizationRate (index, regularizationRate);
if (hasChanged) {
layerCardUi.updateRegularizationRate (index);
playgroundFacade.updateUI ();
}
}
}
// bias
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);
const hasChanged = networkState.setBias (index, value);
if (hasChanged) {
layerCardUi.updateBias (index);
playgroundFacade.updateBiasesUI ();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/devices/known-devices/novation-launchpad-mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const novationLaunchpadMini: Selector = {
[7, 23, 39, 55, 71, 87, 103, 119],
],
functionKeys: {
firstRow: [91, 92, 93, 94, 95, 96, 97, 98], // not available
firstRow: [104, 105, 106, 107, 108, 109, 110, 111],
lastColumn: [8, 24, 40, 56, 72, 88, 104, 120],
},
colors: {
Expand Down
Loading

0 comments on commit 7990b03

Please sign in to comment.