XOR training

This example shows how to train data for XOR function

Example #1 xor.data file

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

Example #2 Simple train

<?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($annFANN_SIGMOID_SYMMETRIC);
    
fann_set_activation_function_output($annFANN_SIGMOID_SYMMETRIC);

    
$filename dirname(__FILE__) . "/xor.data";
    if (
fann_train_on_file($ann$filename$max_epochs$epochs_between_reports$desired_error))
        
fann_save($anndirname(__FILE__) . "/xor_float.net");

    
fann_destroy($ann);
}
?>

This example shows how to read and run data for XOR function

Example #3 Simple test

<?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(-11);
$calc_out fann_run($ann$input);
printf("xor test (%f,%f) -> %f\n"$input[0], $input[1], $calc_out[0]);
fann_destroy($ann);
?>

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial