Saltar al contenido

crear redes neuronales con ejemplo de código javascript

Te damos la solución a esta cuestión, al menos eso pensamos. Si continuas con interrogantes compártelo en un comentario, que para nosotros será un placer responderte

Ejemplo: red neuronal js

// npm i @death_raider/neural-networkconstNeuralNetwork=require('@death_raider/neural-network').NeuralNetwork//creates ANN with 2 input nodes, 1 hidden layers with 2 hidden nodes and 1 output nodelet network =newNeuralNetwork(
  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 functionfunctionxor()let inp =[Math.floor(Math.random()*2),Math.floor(Math.random()*2)];//random inputs 0 or 1 per celllet out =(inp.reduce((a,b)=>a+b)%2==0)?[0]:[1];//if even number of 1's in input then 0 else 1 as outputreturn[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 dataTotalVal: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

Comentarios y valoraciones del artículo

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *