PHP Classes

Legendary Mind: Emulate a brain using neural networking links

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 128 All time: 9,385 This week: 82Up
Version License PHP version Categories
legendary-mind 1.0.0Custom (specified...5PHP 5
Description 

Author

Emulate a brain using neural networking of neurons connected via links.

It provides a mind class that can manage a neuron class objects, a wrapper class that connects each neuron, and a layer class that represents layers of connected neurons.

Picture of Julian Finkler
  Performance   Level  
Name: Julian Finkler <contact>
Classes: 8 packages by
Country: Germany Germany
Age: 31
All time rank: 2916173 in Germany Germany
Week rank: 164 Up8 in Germany Germany Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Documentation

GitHub tag Packagist Travis Packagist

Legendary Mind

Legendary Mind is an easy to use Neural Network written in PHP - Wrapper Class For Handling The Network - Archive And Restore Neural Networks Serialized In Text-Files

Installation

composer require devtronic/legendary-mind

Usage

Standalone Network

<?php

use Devtronic\Layerless\Activator\TanHActivator;
use Devtronic\LegendaryMind\Mind;

require_once 'vendor/autoload.php';

// Create the topology for the net
$topology = [2, 3, 1];

// Set the activator
$activator = new TanHActivator();

// Instantiate the Mind
$mind = new Mind($topology, $activator);

// Setup XOR Lessons
$lessons = [
    [
        [0, 0], # Inputs
        [0]     # Outputs
    ],
    [
        [0, 1], # Inputs
        [1]     # Outputs
    ],
    [
        [1, 0], # Inputs
        [1]     # Outputs
    ],
    [
        [1, 1], # Inputs
        [0]     # Outputs
    ],
];

// Train the lessons
$mind->train($lessons);

// Setup the check lesson
$test = [1, 0];
$expected = [1];

// Propagate the check lesson
$mind->predict($test);

// Print the Output
print_r($mind->getOutput());

// Backpropagate
$mind->backPropagate($expected);

With Wrapper (recommended)

<?php

use Devtronic\Layerless\Activator\TanHActivator;
use Devtronic\LegendaryMind\Wrapper;

require_once 'vendor/autoload.php';

// Set the activator function
$activator = new TanHActivator();

$wrapper = new Wrapper($hiddenNeurons = 3, $hiddenLayers = 1);

// Possible input values
$properties = [
    'color' => ['red', 'pink', 'blue', 'green'],
    'hair_length' => ['short', 'long']
];

$outputs = [
    'gender' => ['male', 'female']
];

// Setup the wrapper
$wrapper->initialize($properties, $outputs, $activator);

// Setup the lessons
$lessons = [
    [
        'input' => [
            'color' => 'red',
            'hair_length' => 'long',
        ],
        'output' => [
            'gender' => 'female'
        ],
    ],
    [
        'input' => [
            'color' => 'blue',
            'hair_length' => 'short',
        ],
        'output' => [
            'gender' => 'male'
        ],
    ],
    [
        'input' => [
            'color' => 'red',
            'hair_length' => 'short',
        ],
        'output' => [
            'gender' => 'male'
        ],
    ],
];

// Train the lessons
$wrapper->train($lessons);

// Setup the check lesson
$test_lesson = [
    'input' => [
        'color' => ['pink', 'green'],
        'hair_length' => 'long',
    ],
    'output' => [
        'gender' => 'female'
    ]
];

// Propagate the check lesson
$wrapper->predict($test_lesson);

// Print the Output
print_r($wrapper->getResult());

// Backpropagate
$wrapper->backPropagate($test_lesson);

Archive and restore the network (only with wrapper, Line 16 and Line 67)

<?php

use Devtronic\Layerless\Activator\TanHActivator;
use Devtronic\LegendaryMind\Wrapper;

require_once 'vendor/autoload.php';

// Set the activation function
$activator = new TanHActivator();
$wrapper = new Wrapper($hiddenNeurons = 3, $hiddenLayers = 1);

$network_file = 'network.txt';

if (is_file($network_file)) {
    // Restore the Network
    $wrapper->restore($network_file);
} else {

    // Possible input values
    $properties = [
        'color' => ['red', 'pink', 'blue', 'green'],
        'hair_length' => ['short', 'long']
    ];

    $outputs = [
        'gender' => ['male', 'female']
    ];

    // Setup the wrapper
    $wrapper->initialize($properties, $outputs, $activator);

    // Setup the lessons
    $lessons = [
        [
            'input' => [
                'color' => 'red',
                'hair_length' => 'long',
            ],
            'output' => [
                'gender' => 'female'
            ],
        ],
        [
            'input' => [
                'color' => 'blue',
                'hair_length' => 'short',
            ],
            'output' => [
                'gender' => 'male'
            ],
        ],
        [
            'input' => [
                'color' => 'red',
                'hair_length' => 'short',
            ],
            'output' => [
                'gender' => 'male'
            ],
        ],
    ];

    // Train the lessons
    $wrapper->train($lessons);

    // Archive the Network
    $wrapper->archive($network_file);
}

// Setup the check lesson
$test_lesson = [
    'input' => [
        'color' => ['pink', 'green'],
        'hair_length' => 'long',
    ],
    'output' => [
        'gender' => 'female'
    ]
];

// Propagate the check lesson
$wrapper->predict($test_lesson);

// Print the Output
print_r($wrapper->getResult());

// Backpropagate
$wrapper->backPropagate($test_lesson);

  Files folder image Files (12)  
File Role Description
Files folder imagesrc (3 files)
Files folder imagetests (3 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.travis.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files (12)  /  src  
File Role Description
  Plain text file Layer.php Class Class source
  Plain text file Mind.php Class Class source
  Plain text file Wrapper.php Class Class source

  Files folder image Files (12)  /  tests  
File Role Description
  Accessible without login Plain text file autoload.php Aux. Auxiliary script
  Plain text file LayerTest.php Class Class source
  Plain text file MindTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:128
This week:0
All time:9,385
This week:82Up