-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e707683
commit c5934c3
Showing
5 changed files
with
132 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const NeuralNetwork = require("neural-network-node"); | ||
|
||
let nn = new NeuralNetwork(2, 4, 1); | ||
|
||
let training_data = [ | ||
{ | ||
inputs: [0, 0], | ||
outputs: [0], | ||
}, | ||
{ | ||
inputs: [0, 1], | ||
outputs: [1], | ||
}, | ||
{ | ||
inputs: [1, 0], | ||
outputs: [1], | ||
}, | ||
{ | ||
inputs: [1, 1], | ||
outputs: [0], | ||
}, | ||
]; | ||
|
||
for (let i = 0; i < 1000; i++) { | ||
let data = random(training_data); | ||
nn.train(data.inputs, data.outputs); | ||
} | ||
|
||
const output = nn.predict([0, 1]); //The more you train the model, the closer this gets to one | ||
console.log(output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const NeuralNetwork = require("neural-network-node"); | ||
|
||
let nn = new NeuralNetwork(1, 2, 1); | ||
|
||
function generatedata() { | ||
let input = Math.random() * 2 * Math.PI; | ||
let output = Math.sin(input); | ||
|
||
return { | ||
input: [input], | ||
output: [output], | ||
}; | ||
} | ||
|
||
for (let i = 0; i < 10000; i++) { | ||
var data = generatedata(); | ||
nn.train(data.input, data.output); | ||
} | ||
|
||
console.log("Finished training"); | ||
|
||
const output = nn.predict(Math.PI); //The more you train the model, the closer this gets to zero | ||
console.log(output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters