Skip to content

Commit

Permalink
A refreshment
Browse files Browse the repository at this point in the history
  • Loading branch information
WalkingBread committed May 1, 2019
1 parent 29d8f28 commit 2578278
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 385 deletions.
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
Multi layer neural network implemented in several languages.
# multi-layer-neural-network

This is a multi-layer neural network library created in pure JavaScript. (still in development)

## Usage:

### Layer creation:
```js
const layer = NeuralNetwork.createLayer({
nodes: 2,
activation: 'sigmoid'
});
```

### Neural Network initialization:
```js
const brain = NeuralNetwork.createNeuralNetwork({
inputNodes: 2,
layers: [
NeuralNetwork.createLayer({
nodes: 2,
activation: 'sigmoid'
}),
NeuralNetwork.createLayer({ // output layer
nodes: 1,
activation: 'sigmoid'
})
],
learningRate: 0.1,
});
```

### Training:
```js
const dataset = [
{
inputs: [0, 1],
targets: [1]
},
{
inputs: [1, 0],
targets: [1]
},
{
inputs: [1, 1],
targets: [0]
},
{
inputs: [0, 0],
targets: [0]
}
];

for(let i = 0; i < 10000; i++) { // how many times we want it to be trained
for(let data of dataset) {
brain.train(data.inputs, data.targets);
}
}
```

### Predicting:
```js
const output = brain.predict([0, 1]);
console.log(output);
```
65 changes: 0 additions & 65 deletions js/README.md

This file was deleted.

13 changes: 1 addition & 12 deletions js/neuralnetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ const NeuralNetwork = (function() {

train(inputArray, targetArray) {
const inputs = Matrix.from_arr(inputArray);

let prevLayerValues = inputs;

for(let layer of this.layers) {
layer.layerValues = Matrix.multiply(layer.weights, prevLayerValues);
layer.layerValues.add(layer.bias);
layer.layerValues.map(layer.activationFunction.func);

prevLayerValues = layer.layerValues;
}

const outputs = this.layers[this.layers.length - 1].layerValues;
const outputs = this.predict(inputArray);
const targets = Matrix.from_arr(targetArray);

let prevError = null;
Expand Down
Loading

0 comments on commit 2578278

Please sign in to comment.