Skip to content

Commit

Permalink
Add docs for neural network
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Aug 14, 2016
1 parent b1978cf commit 3599367
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![PHP-ML - Machine Learning library for PHP](docs/assets/php-ml-logo.png)

Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Preprocessing, Feature Extraction and much more in one library.
Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library.

PHP-ML requires PHP >= 7.0.

Expand Down Expand Up @@ -62,6 +62,9 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples](
* [Classification Report](http://php-ml.readthedocs.io/en/latest/machine-learning/metric/classification-report/)
* Workflow
* [Pipeline](http://php-ml.readthedocs.io/en/latest/machine-learning/workflow/pipeline)
* Neural Network
* [Multilayer Perceptron](http://php-ml.readthedocs.io/en/latest/machine-learning/neural-network/multilayer-perceptron/)
* [Backpropagation training](http://php-ml.readthedocs.io/en/latest/machine-learning/neural-network/backpropagation/)
* Cross Validation
* [Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/random-split/)
* [Stratified Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/stratified-random-split/)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"description": "PHP-ML - Machine Learning library for PHP",
"license": "MIT",
"keywords": ["machine learning","pattern recognition","computational learning theory","artificial intelligence"],
"keywords": ["machine learning","pattern recognition","neural network","computational learning theory","artificial intelligence"],
"homepage": "https://github.com/php-ai/php-ml",
"authors": [
{
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples](
* [Classification Report](machine-learning/metric/classification-report/)
* Workflow
* [Pipeline](machine-learning/workflow/pipeline)
* Neural Network
* [Multilayer Perceptron](machine-learning/neural-network/multilayer-perceptron/)
* [Backpropagation training](machine-learning/neural-network/backpropagation/)
* Cross Validation
* [Random Split](machine-learning/cross-validation/random-split/)
* [Stratified Random Split](machine-learning/cross-validation/stratified-random-split/)
Expand Down
6 changes: 3 additions & 3 deletions docs/machine-learning/classification/k-nearest-neighbors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Classifier implementing the k-nearest neighbors algorithm.

### Constructor Parameters
## Constructor Parameters

* $k - number of nearest neighbors to scan (default: 3)
* $distanceMetric - Distance object, default Euclidean (see [distance documentation](math/distance/))
Expand All @@ -12,7 +12,7 @@ $classifier = new KNearestNeighbors($k=4);
$classifier = new KNearestNeighbors($k=3, new Minkowski($lambda=4));
```

### Train
## Train

To train a classifier simply provide train samples and labels (as `array`). Example:

Expand All @@ -24,7 +24,7 @@ $classifier = new KNearestNeighbors();
$classifier->train($samples, $labels);
```

### Predict
## Predict

To predict sample label use `predict` method. You can provide one sample or array of samples:

Expand Down
29 changes: 29 additions & 0 deletions docs/machine-learning/neural-network/backpropagation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Backpropagation

Backpropagation, an abbreviation for "backward propagation of errors", is a common method of training artificial neural networks used in conjunction with an optimization method such as gradient descent.

## Constructor Parameters

* $network (Network) - network to train (for example MultilayerPerceptron instance)
* $theta (int) - network theta parameter

```
use Phpml\NeuralNetwork\Network\MultilayerPerceptron;
use Phpml\NeuralNetwork\Training\Backpropagation;
$network = new MultilayerPerceptron([2, 2, 1]);
$training = new Backpropagation($network);
```

## Training

Example of XOR training:

```
$training->train(
$samples = [[1, 0], [0, 1], [1, 1], [0, 0]],
$targets = [[1], [1], [0], [0]],
$desiredError = 0.2,
$maxIteraions = 30000
);
```
29 changes: 29 additions & 0 deletions docs/machine-learning/neural-network/multilayer-perceptron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# MultilayerPerceptron

A multilayer perceptron (MLP) is a feedforward artificial neural network model that maps sets of input data onto a set of appropriate outputs.

## Constructor Parameters

* $layers (array) - array with layers configuration, each value represent number of neurons in each layers
* $activationFunction (ActivationFunction) - neuron activation function

```
use Phpml\NeuralNetwork\Network\MultilayerPerceptron;
$mlp = new MultilayerPerceptron([2, 2, 1]);
// 2 nodes in input layer, 2 nodes in first hidden layer and 1 node in output layer
```

## Methods

* setInput(array $input)
* getOutput()
* getLayers()
* addLayer(Layer $layer)

## Activation Functions

* BinaryStep
* Gaussian
* HyperbolicTangent
* Sigmoid (default)
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pages:
- Classification Report: machine-learning/metric/classification-report.md
- Workflow:
- Pipeline: machine-learning/workflow/pipeline.md
- Neural Network:
- Multilayer Perceptron: machine-learning/neural-network/multilayer-perceptron.md
- Backpropagation training: machine-learning/neural-network/backpropagation.md
- Cross Validation:
- RandomSplit: machine-learning/cross-validation/random-split.md
- Stratified Random Split: machine-learning/cross-validation/stratified-random-split.md
Expand Down

0 comments on commit 3599367

Please sign in to comment.