PHP code example of 24hoursmedia / php-fann-topology-core

1. Go to this page and download the library: Download 24hoursmedia/php-fann-topology-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

24hoursmedia / php-fann-topology-core example snippets



use T4\Fann\Topology\Core\Topology;
$ann = fann_create_standard(4, 2, 2, 5, 1);
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
$filename = dirname(__FILE__) . "/xor.data";
fann_train_on_file($ann, $filename, 100000, 0, 0.0001);

$topology = Topology::createFromFann($ann);
$inputLayer = $topology->getLayers()[0];
$firstInputNeuron = $inputLayer->getNeurons()[0];
$connections = $firstInputNeuron->getConnections();
foreach ($connections as $conn) {
    echo 'neuron ' . $conn->getFromNeuron()->getIndex() . ' is connected to neuron ' .
        $conn->getToNeuron()->getIndex() . ' with weight ' . $conn->getWeight() .
        PHP_EOL;
}