-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathexamples.xml
85 lines (76 loc) · 2.07 KB
/
examples.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: c2aeb63e3d8b50f83d5adeffea4209db45705c76 Maintainer: duanxiaoqiang Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="fann.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="fann.examples-1">
<title>XOR (异或)训练</title>
<para>
以下例子展示了怎么训练数据来实现 XOR (异或)功能。
<example>
<title>xor.data file</title>
<programlisting role="txt">
<![CDATA[
4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
-1
]]>
</programlisting>
</example>
<example>
<title>一般训练</title>
<programlisting role="php">
<![CDATA[
<?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;
$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__) . "/xor.data";
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error))
fann_save($ann, dirname(__FILE__) . "/xor_float.net");
fann_destroy($ann);
}
?>
]]>
</programlisting>
</example>
</para>
<para>
这个例子展示怎么读取神经网络并且使用 XOR (异或)功能来运行数据。
<example>
<title>一般测试</title>
<programlisting role="php">
<![CDATA[
<?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");
$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);
?>
]]>
</programlisting>
</example>
</para>
</section>
</chapter>