Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limdu and Synaptic, Alpha. #41

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@ You can run the demos from this project: [limdu-demo](https://github.com/erelsgl

## Binary Classification

### Synaptic - architecture-free neural network library for node.js and the browser:

```js
var limdu = require('limdu');

var Options = [{ Inputs: 2, Hidden: 2, Outputs: 1 }]
//All options in https://github.com/cazala/synaptic/wiki/Trainer#options

var Classifier = new limdu.classifiers.Synaptic(Options);

var TrainingSet =
[
{ input: [0,0], output: [0] },
{ input: [0,1], output: [1] },
{ input: [1,0], output: [1] },
{ input: [1,1], output: [0] }
]

Classifier.trainBatch(TrainingSet);

console.log(Classifier.classify([1,0]));

/* Response
iterations 1000 error 0.7186739001361462 rate 0.1
iterations 2000 error 0.6491794090041461 rate 0.1
iterations 3000 error 0.5252686333641889 rate 0.1
iterations 4000 error 0.5120039035297583 rate 0.1
iterations 5000 error 0.5074936397380782 rate 0.1
iterations 6000 error 0.5006203011889089 rate 0.1
iterations 7000 error 0.028994141931717198 rate 0.1
iterations 8000 error 0.012387254089101019 rate 0.1
iterations 9000 error 0.00799815060929144 rate 0.1
iterations 10000 error 0.005932337534569962 rate 0.1
[ 0.9954244092543398 ]
```

Note: this example uses [Synaptic, by Juan Cazala](https://github.com/cazala/synaptic).

### Batch Learning - learn from an array of input-output pairs:

```js
Expand Down
7 changes: 4 additions & 3 deletions classifiers/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
module.exports = {
// basic classifiers:
//NeuralNetwork: require('./brain/lib/neuralnetwork').NeuralNetwork,
Synaptic: require('./synaptic/synaptic'),
NeuralNetwork: require('./neural/NeuralNetwork'),
Bayesian: require('./bayesian/bayesian'),

kNN: require('./kNN/kNN'),

SvmJs: require('./svm/SvmJs'),
SvmPerf: require('./svm/SvmPerf'),
SvmLinear: require('./svm/SvmLinear'),

//BayesClassifier: require('./apparatus/lib/apparatus/classifier/bayes_classifier'),
//LogisticRegressionClassifier: require('./apparatus/lib/apparatus/classifier/logistic_regression_classifier'),
Perceptron: require('./perceptron/PerceptronHash'),
Expand All @@ -18,7 +19,7 @@ module.exports = {
DecisionTree: require('./decisiontree/DecisionTree'),

multilabel: require('./multilabel'),

// meta classifier:
EnhancedClassifier: require('./EnhancedClassifier'),
}
Expand Down
54 changes: 54 additions & 0 deletions classifiers/synaptic/synaptic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* A wrapper for Synaptic: https://github.com/cazala/synaptic
*
* Author: Inder
*/

var Synaptic = require('synaptic');
var Neuron = Synaptic.Neuron;
var Layer = Synaptic.Layer;
var Network = Synaptic.Network;
var Trainer = Synaptic.Trainer;
var Architect = Synaptic.Architect;

var Wrapper = function(Options)
{
Options = Options || {};

this.Inputs = Options.Inputs || 2;
this.Hidden = Options.Hidden || 2;
this.Output = Options.Output || 1;

this.Rate = Options.Rate || .1;
this.Iterations = Options.Iterations || 20000;
this.Error = Options.Error || .005;
this.Shuffle = Options.Shuffle || true;
this.Log = Options.Log || 1000;
this.Cost = Options.Cost || Trainer.cost.CROSS_ENTROPY;
}

Wrapper.prototype.trainOnline = function () { throw new Error("Synaptic does not support online training YET"); };

Wrapper.prototype.trainBatch = function(DataSet)
{
this.DataSet = DataSet
this.Network = new Architect.Perceptron(this.Inputs, this.Hidden, this.Output)
this.Learn = new Trainer(this.Network)

this.Learn.train(this.DataSet,
{
rate: this.Rate,
iterations: this.Iterations,
error: this.Error,
shuffle: this.Shuffle,
log: this.Log,
cost: this.Cost
});
};

Wrapper.prototype.classify = function(DataSet)
{
return this.Network.activate(DataSet);
};

module.exports = Wrapper;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "limdu",
"description": "A machine learning framework for Node.js. Supports multi-level classification and online learning.",
"version": "0.8.0",
"version": "0.9.0",
"author": "Erel Segal-haLevi <erelsgl@gmail.com>",
"repository": {
"type": "git",
Expand All @@ -11,6 +11,7 @@
"node" : ">=0.12"
},
"dependencies": {
"synaptic": "latest",
"brain": "*",
"graph-paths": "latest",
"languagemodel": "latest",
Expand Down