16 Commits

Autor SHA1 Mensagem Data
Jakub Zelenka ff88ddbb2d Fix error simple train example 2016-08-28 13:32:39 +01:00
Jakub Zelenka 666a9782e9 Merge pull request #27 from geekgirljoy/master
Adding New Examples
2016-08-28 13:29:23 +01:00
Joy Harvel cbceac3277 Update package.xml
Added new examples
2016-08-18 10:41:30 -07:00
Joy Harvel df0d3efa40 Update test_all.php 2016-08-18 03:10:48 -07:00
Joy Harvel dea7be11e1 Update test_all.php 2016-08-18 03:05:47 -07:00
Joy Harvel 31aa82d04e Update README.md 2016-08-18 03:03:15 -07:00
Joy Harvel 9752d4c3b9 Update README.md 2016-08-18 02:56:49 -07:00
Joy Harvel 684fd7efa5 Update README.md 2016-08-18 02:53:06 -07:00
Joy Harvel 318449e9f7 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	examples/logic_gates/test_all.php
2016-08-18 02:51:12 -07:00
Joy Harvel 18a9742978 Adding Examples
Added AND, NAND, NOR, NOT, OR, XNOR example training data. Added OCR
Example. Added Pathfinder Example. Updated README.md to reflect
additional examples.
2016-08-18 02:49:18 -07:00
Jakub Zelenka 456f5d75ac Update README about re-installing libfann 2016-08-14 15:21:29 +01:00
Joy Harvel 34f60ecc33 Update test_all.php 2016-08-02 16:16:07 -07:00
Joy Harvel 6c97ba9124 Fixing test_all.php
Removed extra comma on inputs display
2016-07-29 00:31:33 -07:00
Joy Harvel bdf74eb008 Added examples
Added train_all.php and test_all.php
2016-07-29 00:25:24 -07:00
Joy Harvel bbe05abdc6 Added logic gate example training data
Added: and.data, nand.data, nor.data, not.data, or.data, xnor.data
2016-07-27 21:21:55 -07:00
Joy Harvel 64b4a588fa Added output to simple_train.php
Added output to simple_train.php so that the page acknowledges that the training was completed and that the network was saved. Additionally a link to the test script was added.
2016-07-25 22:51:44 -07:00
113 arquivos alterados com 1009 adições e 36 exclusões
+35 -33
Ver Arquivo
@@ -20,6 +20,8 @@ $ sudo apt-get install libfann-dev
```
Fann installation can be skipped if an RPM for Fedora is used (`libfann` is in the package dependencies).
If the library is re-installed manually, then all old library file should be removed before re-installing otherwise the old library version could be linked.
#### Fedora
The RPM package for PHP FANN is available in Remi's repository: http://rpms.famillecollet.com/
@@ -70,46 +72,46 @@ Precompiled binary `dll` libraries for php-fann and libfann are available on [th
## Examples
These are just two basic examples for simple training and running supplied data on the trained network.
There are three example projects: [Logic Gates](examples/logic_gates/), [OCR](examples/ocr/) & [Pathfinder](examples/pathfinder/).
### `simple_train.php`
#### Logic Gates
```php
$num_input = 2;
$num_output = 1;
$num_layers = 3;
$num_neurons_hidden = 3;
$desired_error = 0.001;
$max_epochs = 500000;
$epochs_between_reports = 1000;
###### Simple
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
The Simple example trains a single neural network to perform the XOR operation.
if ($ann) {
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
[simple_train.php](examples/logic_gates/simple_train.php)
$filename = dirname(__FILE__) . "/xor.data";
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error))
fann_save($ann, dirname(__FILE__) . "/xor_float.net");
[simple_test.php](examples/logic_gates/simple_test.php)
fann_destroy($ann);
}
```
### `simple_test.php`
```php
$train_file = (dirname(__FILE__) . "/xor_float.net");
if (!is_file($train_file))
die("The file xor_float.net has not been created! Please run simple_train.php to generate it");
###### All
The All example trains 7 seperate neural networks to perform the AND, NAND, NOR, NOT, OR, XNOR & XOR operations.
[train_all.php](examples/logic_gates/train_all.php)
[test_all.php](examples/logic_gates/test_all.php)
#### OCR
OCR is a practical example of Optical Character Recognition using FANN. While this example is limited and does make mistakes, the concepts illustrated by OCR can be applied to a more robust stacked network that uses feature extraction and convolution layers to recognize text of any font in any size image.
[train_ocr.php](examples/ocr/train_ocr.php)
[test_ocr.php](examples/ocr/test_ocr.php)
#### Pathfinder
Pathfinder is an example of a neural network that is capable of plotting an 8 direction step path from a starting position in a 5x5 grid to an ending position in that grid. To keep the Pathfinder example simple it is not trained to deal with walls or non-traversable terrain however it would be very easy to add that by adding additional training.
[pathfinder_train.php](examples/pathfinder/pathfinder_train.php)
[pathfinder_test.php](examples/pathfinder/pathfinder_test.php)
$ann = fann_create_from_file($train_file);
if (!$ann)
die("ANN could not be created");
$input = array(-1, 1);
$calc_out = fann_run($ann, $input);
printf("xor test (%f,%f) -> %f\n", $input[0], $input[1], $calc_out[0]);
fann_destroy($ann);
```
+9
Ver Arquivo
@@ -0,0 +1,9 @@
4 2 1
-1 -1
-1
-1 1
-1
1 -1
-1
1 1
1
+9
Ver Arquivo
@@ -0,0 +1,9 @@
4 2 1
-1 -1
1
-1 1
1
1 -1
1
1 1
-1
+9
Ver Arquivo
@@ -0,0 +1,9 @@
4 2 1
-1 -1
1
-1 1
-1
1 -1
-1
1 1
-1
+5
Ver Arquivo
@@ -0,0 +1,5 @@
2 1 1
-1
1
1
-1
+9
Ver Arquivo
@@ -0,0 +1,9 @@
4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
1
@@ -16,7 +16,10 @@ if ($ann) {
$filename = dirname(__FILE__) . "/xor.data";
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error))
fann_save($ann, dirname(__FILE__) . "/xor_float.net");
print('xor trained.<br>' . PHP_EOL);
if (fann_save($ann, dirname(__FILE__) . "/xor_float.net"))
print('xor_float.net saved.<br><a href="simple_test.php">Test</a>' . PHP_EOL);
fann_destroy($ann);
}
+48
Ver Arquivo
@@ -0,0 +1,48 @@
<?php
function test($ann, $test_data) {
$train_file = (dirname(__FILE__) . '/' . $ann . '_float.net');
if (!is_file($train_file)) {
print('The file ' . $ann . '_float.net has not been created! Please run train_all.php to generate it.<br>' . PHP_EOL);
} else{
$ann = fann_create_from_file($train_file);
if ($ann) {
$calc_out = fann_run($ann, $test_data);
$num_inputs = count($test_data);
$num_outputs = count($calc_out);
$test_result = $ann . ' test (';
for($i = 0; $i < $num_inputs; $i++) {
$test_result .= $test_data[$i];
if ($i < $num_inputs - 1) {
$test_result .= ', ';
}
}
$test_result .= ') -> ';
for($i = 0; $i < $num_outputs; $i++) {
$test_result .= $calc_out[$i];
if ($i < $num_outputs - 1) {
$test_result .= ', ';
}
}
print($test_result . '<br>' . PHP_EOL);
fann_destroy($ann);
} else {
die("Invalid file format" . PHP_EOL);
}
}
}
test('and', array(1, 1));
test('nand', array(-1, -1));
test('nor', array(-1, -1));
test('not', array(-1));
test('or', array(1, -1));
test('xnor', array(-1, -1));
test('xor', array(-1, 1));
?>
+35
Ver Arquivo
@@ -0,0 +1,35 @@
<?php
function train($data, $num_input, $num_output, $num_layers, $num_neurons_hidden, $desired_error, $max_epochs, $epochs_between_reports){
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
if ($ann) {
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
$filename = dirname(__FILE__) . '/' . $data . '.data';
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error)) {
print($data . ' trained.<br>' . PHP_EOL);
}
if (fann_save($ann, dirname(__FILE__) . '/' . $data . '_float.net')) {
print($data . '_float.net saved.<br>' . PHP_EOL);
}
fann_destroy($ann);
}
}
train('and', 2, 1, 3, 3, 0.001, 500000, 1000);
train('nand', 2, 1, 3, 3, 0.001, 500000, 1000);
train('nor', 2, 1, 3, 3, 0.001, 500000, 1000);
train('not', 1, 1, 3, 3, 0.001, 500000, 1000);
train('or', 2, 1, 3, 3, 0.001, 500000, 1000);
train('xnor', 2, 1, 3, 3, 0.001, 500000, 1000);
train('xor', 2, 1, 3, 3, 0.001, 500000, 1000);
print("<a href='test_all.php'>Test All</a>");
?>
+9
Ver Arquivo
@@ -0,0 +1,9 @@
4 2 1
-1 -1
1
-1 1
-1
1 -1
-1
1 1
1
Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 114 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 111 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 115 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 116 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 112 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 115 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 129 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 127 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 122 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 138 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 130 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 132 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 114 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 132 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 132 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 132 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 122 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 134 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 115 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 122 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 129 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 113 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 129 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 133 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 130 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 135 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 122 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 128 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 118 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 130 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 117 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 123 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 129 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 114 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 123 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 127 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 128 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 126 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 133 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 128 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 115 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 118 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 131 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 117 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 128 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 113 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 117 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 111 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 113 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 129 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 124 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 124 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 128 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 124 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 130 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 119 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 117 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 115 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 118 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 121 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 124 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 125 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 124 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 118 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 123 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 118 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 120 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 119 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 123 B

Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 123 B

Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais