PHP Classes

Legendary Mind: Emulate a brain using neural networking links

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 126 All time: 9,382 This week: 110Up
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: 30
All time rank: 2921172 in Germany Germany
Week rank: 312 Up18 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  
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  /  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  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:126
This week:0
All time:9,382
This week:110Up