Skip to content

Commit cf886d6

Browse files
authored
Merge pull request #1 from bukka/master
Pull Request
2 parents 5cb6375 + ff88ddb commit cf886d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1009
-36
lines changed

README.md

Lines changed: 35 additions & 33 deletions

examples/logic_gates/and.data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 2 1
2+
-1 -1
3+
-1
4+
-1 1
5+
-1
6+
1 -1
7+
-1
8+
1 1
9+
1

examples/logic_gates/nand.data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 2 1
2+
-1 -1
3+
1
4+
-1 1
5+
1
6+
1 -1
7+
1
8+
1 1
9+
-1

examples/logic_gates/nor.data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 2 1
2+
-1 -1
3+
1
4+
-1 1
5+
-1
6+
1 -1
7+
-1
8+
1 1
9+
-1

examples/logic_gates/not.data

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2 1 1
2+
-1
3+
1
4+
1
5+
-1

examples/logic_gates/or.data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 2 1
2+
-1 -1
3+
-1
4+
-1 1
5+
1
6+
1 -1
7+
1
8+
1 1
9+
1
File renamed without changes.

examples/simple_train.php renamed to examples/logic_gates/simple_train.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
$filename = dirname(__FILE__) . "/xor.data";
1818
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error))
19-
fann_save($ann, dirname(__FILE__) . "/xor_float.net");
19+
print('xor trained.<br>' . PHP_EOL);
20+
21+
if (fann_save($ann, dirname(__FILE__) . "/xor_float.net"))
22+
print('xor_float.net saved.<br><a href="simple_test.php">Test</a>' . PHP_EOL);
2023

2124
fann_destroy($ann);
2225
}

examples/logic_gates/test_all.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
function test($ann, $test_data) {
4+
$train_file = (dirname(__FILE__) . '/' . $ann . '_float.net');
5+
if (!is_file($train_file)) {
6+
print('The file ' . $ann . '_float.net has not been created! Please run train_all.php to generate it.<br>' . PHP_EOL);
7+
} else{
8+
$ann = fann_create_from_file($train_file);
9+
if ($ann) {
10+
$calc_out = fann_run($ann, $test_data);
11+
12+
$num_inputs = count($test_data);
13+
$num_outputs = count($calc_out);
14+
15+
$test_result = $ann . ' test (';
16+
for($i = 0; $i < $num_inputs; $i++) {
17+
$test_result .= $test_data[$i];
18+
19+
if ($i < $num_inputs - 1) {
20+
$test_result .= ', ';
21+
}
22+
}
23+
$test_result .= ') -> ';
24+
for($i = 0; $i < $num_outputs; $i++) {
25+
$test_result .= $calc_out[$i];
26+
27+
if ($i < $num_outputs - 1) {
28+
$test_result .= ', ';
29+
}
30+
}
31+
print($test_result . '<br>' . PHP_EOL);
32+
33+
fann_destroy($ann);
34+
} else {
35+
die("Invalid file format" . PHP_EOL);
36+
}
37+
}
38+
}
39+
40+
test('and', array(1, 1));
41+
test('nand', array(-1, -1));
42+
test('nor', array(-1, -1));
43+
test('not', array(-1));
44+
test('or', array(1, -1));
45+
test('xnor', array(-1, -1));
46+
test('xor', array(-1, 1));
47+
48+
?>

examples/logic_gates/train_all.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
function train($data, $num_input, $num_output, $num_layers, $num_neurons_hidden, $desired_error, $max_epochs, $epochs_between_reports){
4+
5+
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
6+
7+
if ($ann) {
8+
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
9+
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
10+
11+
$filename = dirname(__FILE__) . '/' . $data . '.data';
12+
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error)) {
13+
print($data . ' trained.<br>' . PHP_EOL);
14+
}
15+
16+
if (fann_save($ann, dirname(__FILE__) . '/' . $data . '_float.net')) {
17+
print($data . '_float.net saved.<br>' . PHP_EOL);
18+
}
19+
20+
fann_destroy($ann);
21+
}
22+
}
23+
24+
train('and', 2, 1, 3, 3, 0.001, 500000, 1000);
25+
train('nand', 2, 1, 3, 3, 0.001, 500000, 1000);
26+
train('nor', 2, 1, 3, 3, 0.001, 500000, 1000);
27+
train('not', 1, 1, 3, 3, 0.001, 500000, 1000);
28+
train('or', 2, 1, 3, 3, 0.001, 500000, 1000);
29+
train('xnor', 2, 1, 3, 3, 0.001, 500000, 1000);
30+
train('xor', 2, 1, 3, 3, 0.001, 500000, 1000);
31+
32+
33+
print("<a href='test_all.php'>Test All</a>");
34+
35+
?>

0 commit comments

Comments
 (0)