Javascript Neural Networks - Activation Functions

Overview

Adding an Activation Function

Any layer in the neural network model must be implemented as a Javascript object with two functions on it.



function relu(){ let layer = { type:'relu', evaluate:function(input){ let result = []; for(let row of input){ let val = row[0]; if(val >0) result.push([val]); else result.push([0]); } return result; }, inputGradient:function(input){ let result = []; for(let i=0;i<input.length;i++){ let row = input[i]; let val = row[0]; let row2 = input.map(p=>0); if(val > 0) row2[i] = 1; result.push(row2); } return result; } }; return layer; }