Answers for "neural network"

5

how does a neural network work

HOW A NEURAL NET WORKS STEP BY STEP:

There is a matrix of nodes like this:

0 0 0
0 0 0
0 0 0

Inputs are fed in from the left. like this:

(.1) 0 0
(.24) 0 0		(inputs in parenthesis)
(0) 0 0

the next nodes data is calculated by multiplying A weight to each node 
in the layer before and then adding bias. And then putting in an 
activation function. Like this:

.1  ----(weight: 1)--> .1
.24 ----(weight: .5)--> .12  ----> .1 + .12 + 0 = .22 + bias
0   ----(weight: 2)-->  0


Each node has a bias, for this node lets say its .3

.22 + .3(bias) = .52

After all that you put it in an activation function.

tanh(.52) ---> data for the next node

Everything i showed above was just the caclulation for the 
first node in the second layer though so the matrix
would look like this
after all that.

.1 tanh(.52) 0
.24 0 0
0 0 0

Then you keep doing that for each layer until you reach the end.

Hope this helped?

(Q A)

Does each node have a weight?

No. Each connection has a weight. Or i guess you could say each node
has lots of weights each corresponding to a node in the last layer.


Does each node have a bias?
Yes each node has only one bias.
Posted by: Guest on June-22-2021
1

neural network

// npm i @death_raider/neural-network

const NeuralNetwork = require('@death_raider/neural-network').NeuralNetwork
//creates ANN with 2 input nodes, 1 hidden layers with 2 hidden nodes and 1 output node
let network = new NeuralNetwork({
  input_nodes : 2,
  layer_count : [2],
  output_nodes :1,
  weight_bias_initilization_range : [-1,1]
});
//format for activation function = [ function ,  derivative of function ]
network.Activation.hidden = [(x)=>1/(1+Math.exp(-x)),(x)=>x*(1-x)] //sets activation for hidden layers as sigmoid function
function xor(){
  let inp = [Math.floor(Math.random()*2),Math.floor(Math.random()*2)]; //random inputs 0 or 1 per cell
  let out = (inp.reduce((a,b)=>a+b)%2 == 0)?[0]:[1]; //if even number of 1's in input then 0 else 1 as output
  return [inp,out]; //train or validation functions should have [input,output] format
}
network.train({
  TotalTrain : 1e+6, //total data for training (not epochs)
  batch_train : 1, //batch size for training
  trainFunc : xor, //training function to get data
  TotalVal : 1000, //total data for validation (not epochs)
  batch_val : 1, //batch size for validation
  validationFunc : xor, //validation function to get data
  learning_rate : 0.1 //learning rate (default = 0.0000001)
});
console.log("Average Validation Loss ->",network.Loss.Validation_Loss.reduce((a,b)=>a+b)/network.Loss.Validation_Loss.length);
// Result after running it a few times
// Average Validation Loss -> 0.00004760326022482792
// Average Validation Loss -> 0.000024864418333478723
// Average Validation Loss -> 0.000026908106414283446
Posted by: Guest on April-18-2021
-2

how to work neural network

You can watch sentdex videos on Youtube
Posted by: Guest on April-25-2020

Code answers related to "neural network"

Code answers related to "Javascript"

Browse Popular Code Answers by Language