https://github.com/petrbroz/simple-neural-network
Stupid simple implementation of a fully-connected artificial neural network for learning purposes.
https://github.com/petrbroz/simple-neural-network
Last synced: 3 months ago
JSON representation
Stupid simple implementation of a fully-connected artificial neural network for learning purposes.
- Host: GitHub
- URL: https://github.com/petrbroz/simple-neural-network
- Owner: petrbroz
- Created: 2024-05-21T10:38:28.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-21T10:39:14.000Z (over 1 year ago)
- Last Synced: 2025-05-16T00:18:44.402Z (5 months ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-neural-network
Stupid simple implementation of a fully-connected artificial neural network for learning purposes. Based on various online resources, incl. https://www.youtube.com/watch?v=sIX_9n-1UbM.
> Note however that there seems to be a small error in the YouTube video. Around the 3:58 time mark a derivative of the cost function $(\hat{a_1} - a_1^{(4)})^2$ is said to be $2(\hat{a_1} - a_1^{(4)})$ while it should be $2(a_1^{(4)} - \hat{a_1})$.
## Usage
```js
// Create neural network with specific number of layers and neurons,
// in this case with an input layer of 2 neurons, one hidden layer of 2 neurons, and an output layer of 1 neuron
const network = new NeuralNetwork([2, 2, 1]);// Repeatedly train the network with 0.25 learning rate
const trainingData = [
{ input: [0.0, 0.0], output: [1.0] },
{ input: [0.0, 1.0], output: [0.0] },
{ input: [1.0, 0.0], output: [0.0] },
{ input: [1.0, 1.0], output: [1.0] }
];
for (let i = 0; i < 1000; i++) {
network.train(trainingData, 0.25);
}// Test
for (let y = 0.0; y <= 1.0; y += 0.1) {
for (let x = 0.0; x <= 1.0; x += 0.1) {
console.log(network.predict([x, y]));
}
}
```