Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

3net.js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3net.js - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

README.md

18

index.js

@@ -21,10 +21,18 @@ var math = require('mathjs');

neuralNetwork.prototype.train = function (input, label, learning_rate, iters) {
neuralNetwork.prototype.train = function (input, label, learning_rate, iters, regularization) {
if (!iters) iters = 500;
if (!learning_rate) learning_rate = 0.1;
if (!regularization) regularization = 1;
if (label.length !== this.layer3) return false;
if (input.length !== this.layer1) return false;
[this.theta1, this.theta2] = neuralMath.gradientDescent(this.backpropagation, this.theta1, this.theta2, this.theta1gradient, this.theta2gradient, iters, learning_rate);
return true;
}
neuralNetwork.prototype.backpropagation = function () {
//Forward
this.predict(input);
if (!this.a3) return false;
//Backwards
var d3 = math.subtract(this.a3, label);

@@ -34,8 +42,8 @@ var d2 = math.dotMultiply(math.multiply(math.transpose(this.theta2), d3), neuralMath.dSigmoid(math.concat([1], this.z2)));

//Get gradients
this.theta2gradient = math.add(this.theta2gradient, neuralMath.outerProduct(d3, this.a2));
this.theta1gradient = math.add(this.theta1gradient, neuralMath.outerProduct(d2, this.a1));
this.theta1 = neuralMath.gradientDescent(this.theta1, this.theta1gradient, iters, learning_rate);
this.theta2 = neuralMath.gradientDescent(this.theta2, this.theta2gradient, iters, learning_rate);
return true;
return [this.theta1gradient, this.theta2gradient];
}

@@ -42,0 +50,0 @@

@@ -11,9 +11,2 @@ var math = require('mathjs');

function gradientDescent(params, gradient, iters, learning_rate) {
for (var i = 0; i < iters; i += 1) {
params = math.subtract(params, math.dotMultiply(learning_rate, gradient));
}
return params;
}
function outerProduct(x, y) {

@@ -30,5 +23,15 @@ var z = math.zeros([math.size(x)[0], math.size(y)[0]]);

function getCost(pred, actual) {
if (pred.length !== actual.length) return false;
var cost = 0;
for (var i = 0; i < pred.length; i += 1) {
if (actual[i] === 0) cost += -math.log(1 - pred[i]);
if (actual[i] === 1) cost += -math.log(pred[i]);
}
return cost;
}
exports.sigmoid = sigmoid;
exports.dSigmoid = dSigmoid;
exports.gradientDescent = gradientDescent;
exports.outerProduct = outerProduct;
exports.outerProduct = outerProduct;
exports.getCost = getCost;
{
"name": "3net.js",
"version": "0.0.2",
"version": "0.0.3",
"description": "A simple library for implementing 3 layer neural networks",
"main": "index.js",
"keywords": [
"neural network",
"machine learning"
],
"neural", "network", "machine", "learning", "3netjs", "3net"
],
"repository": {
"type": "git",
"url": "https://github.com/muntashir/"
"url": "https://github.com/muntashir/3net.js/"
},

@@ -27,3 +26,2 @@ "scripts": {

"gitHead": "fd2f0bc5d74bb032e4365b5c6181557820921f8b",
"readme": "ERROR: No README data found!",
"_id": "3net.js@0.0.1",

@@ -30,0 +28,0 @@ "_shasum": "c594ad9cbdae82a140c5de8f1015e07219f07c35",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc