CakeFest 2024: The Official CakePHP Conference

Entrenamiento XOR

Este ejemplo muestra cómo entrenar datos para una función XOR

Ejemplo #1 Fichero xor.data

4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
-1

Ejemplo #2 Entrenamiento sencillo

<?php
$num_entradas
= 2;
$num_salidas = 1;
$num_capas = 3;
$num_neuronas_ocultas = 3;
$error_deseado = 0.001;
$máx_épocas = 500000;
$épocas_entre_informes = 1000;

$rna = fann_create_standard($num_capas, $num_entradas, $num_neuronas_ocultas, $num_salidas);

if (
$rna) {
fann_set_activation_function_hidden($rna, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($rna, FANN_SIGMOID_SYMMETRIC);

$nombre_fichero = dirname(__FILE__) . "/xor.data";
if (
fann_train_on_file($rna, $nombre_fichero, $máx_épocas, $épocas_entre_informes, $error_deseado))
fann_save($rna, dirname(__FILE__) . "/xor_float.net");

fann_destroy($rna);
}
?>

Este ejemplo muestra cómo leer y ejecutar datos para una función XOR

Ejemplo #3 Prueba sencilla

<?php
$fichero_entrenamiento
= (dirname(__FILE__) . "/xor_float.net");
if (!
is_file($fichero_entrenamiento))
die(
"El fichero xor_float.net no ha sido creado. Ejecute simple_train.php para generarlo");

$rna = fann_create_from_file($fichero_entrenamiento);
if (!
$rna)
die(
"No se pudo crear ANN");

$entrada = array(-1, 1);
$calc_out = fann_run($rna, $entrada);
printf("xor test (%f,%f) -> %f\n", $entrada[0], $entrada[1], $calc_out[0]);
fann_destroy($rna);
?>

add a note

User Contributed Notes 3 notes

up
66
Aurelien Marchand
8 years ago
Here is an explanation for the input file for training, as it might be obvious to everyone and you must understand it to write your own:

4 2 1 <- header file saying there are 4 sets to read, with 2 inputs and 1 output
-1 -1 <- the 2 inputs for the 1st group
-1 <- the 1 output for the 1st group
-1 1 <- the 2 inputs for the 2nd group
1 <- the 1 output for the 2nd group
1 -1 <- the 2 inputs for the 3rd group
1 <- the 1 output for the 3rd group
1 1 <- the 2 inputs for the 4th group
-1 <- the 1 output for the 4th group
up
6
Ray.Paseur sometimes uses Gmail
7 years ago
A helpful reference for FANN is available here:
http://leenissen.dk/fann/html/files2/theory-txt.html
up
1
ithirzty
4 years ago
If you wan't your result to be saved after the time limit, you will need to add this to your code.
<?php
function shutdown()
{
global
$ann;
fann_save($ann, dirname(__FILE__) . "/result.net");
fann_destroy($ann);
}

register_shutdown_function('shutdown');
?>
where $ann is your neural network var and 'result.net' your neural network config file.
To Top