Witam,
Zainteresowałem się biblioteką FANN i korzystając z przykładu stworzyłem prostą sieć do wykrywania czy dana figura jest kwadratem korzystając z trzech warunków, tz jest kwadratem jeśli
- Ma cztery boki
- Ma wszystkie kąty proste
- Wszystkie boki są równe
Zbiór uczący
4 3 1
1 1 1
1
0 1 1
0
1 0 1
0
1 1 0
0
train.php
<?php
$num_input = 3;
$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__) . "/kwadrat.data";
if (fann_train_on_file($ann, $filename, $max_epochs, $epochs_between_reports, $desired_error))
fann_save($ann, dirname(__FILE__) . "/kwadrat_float.net");
fann_destroy($ann);
}
?>
test.php
Wyniki testów:<br />
<?php
$train_file = (dirname(__FILE__) . "/kwadrat_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,1);
$input2 = array(1,0,1);
$input3 = array(0,0,0);
$input4 = array(0,1,1);
$calc_out = fann_run($ann, $input);
$calc_out2 = fann_run($ann,$input2);
$calc_out3 = fann_run($ann,$input3);
$calc_out4 = fann_run($ann,$input4);
printf("#1 (%f,%f,%f) -> %f<br>", $input[0], $input[1],$input[2], $calc_out[0]);
printf("#2 (%f,%f,%f) -> %f<br>", $input2[0], $input2[1],$input2[2], $calc_out2[0]);
printf("#3 (%f,%f,%f) -> %f<br>", $input3[0], $input3[1],$input3[2], $calc_out3[0]);
printf("#4 (%f,%f,%f) -> %f<br>", $input4[0], $input4[1],$input4[2], $calc_out4[0]);
fann_destroy($ann);
?>
Wyniki testów
Wyniki testów:
#1 (1.000000,1.000000,1.000000) -> 0.972579
#2 (1.000000,0.000000,1.000000) -> -0.015160
#3 (0.000000,0.000000,0.000000) -> -0.999144
#4 (0.000000,1.000000,1.000000) -> 0.076887
Zastanawia mnie czy wyniki dla podanych wartości są prawidłowe, jak nie co zrobiłem źle? Proszę nie hejtować, bardzo mnie zainteresował ten temat i chcę się jakoś w tym kierunku rozwinąć ;)