Train a neural network with your data & save its trained state!
Demo • Installation • Documentation • Contribute • Discord • License
<scriptsrc="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.0/build/dann.min.js"></script>npm i dannjs
Object types from the library can be imported like this
const{ Dann }=require('dannjs');Setting up a small (4,6,6,2) neural network.
constnn=newDann(4,2);nn.addHiddenLayer(6,'leakyReLU');nn.addHiddenLayer(6,'leakyReLU');nn.outputActivation('tanH');nn.makeWeights();nn.lr=0.0001;nn.log({details:true});Training with a dataset.
//XOR 2 inputs, 1 outputconstdataset=[{input: [0,0],output: [0]},{input: [1,0],output: [1]},{input: [0,1],output: [1]},{input: [1,1],output: [0]}];//train 1 epochfor(dataofdataset){nn.backpropagate(data.input,data.output);console.log(nn.loss);}For neuroevolution simulations. Works best with small models & large population size.
constpopulationSize=1000;letnewGeneration=[];for(leti=0;i<populationSize;i++){// parentNN would be the best nn from past generation.constchildNN=parentNN;childNN.mutateRandom(0.01,0.65);newGeneration.push(childNN);}Convert a Neural Network to a JS function that can output predictions without the library.
letstrfunc=nn.toFunction();console.log(strfunc);letjson=nn.toJSON();console.log(json);AI predicts San-francisco Housing prices.
more examples & demos here
Matias Vazquez-Levi 💻📖 | Francesco Ciulla 📢 | Labnan 🐛💻 | sharkAce 💻 | Hasnain Iqbal 💻 | EL Ramos 🐛 | viabhinav ✅ |
Any contributions are welcome! See CONTRIBUTING.md.
MIT
