2017 © Pedro Peláez
 

library legendary-mind

Easy to use neural network written in PHP

image

devtronic/legendary-mind

Easy to use neural network written in PHP

  • Sunday, November 26, 2017
  • by Devtronic
  • Repository
  • 4 Watchers
  • 9 Stars
  • 40 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 11 Versions
  • 8 % Grown

The README.md

GitHub tag Packagist Travis Packagist, (*1)

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, (*2)

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);
<?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);

The Versions

26/11 2017

dev-master

9999999-dev

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Julian Finkler

11/06 2017

v2.1

2.1.0.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Julian Finkler

11/06 2017

2.x-dev

2.9999999.9999999.9999999-dev

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Julian Finkler

01/12 2016

1.1.x-dev

1.1.9999999.9999999-dev

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.6.0

 

The Development Requires

by Julian Finkler

01/12 2016

1.1.1

1.1.1.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.6.0

 

The Development Requires

by Julian Finkler

01/12 2016

1.1.0.x-dev

1.1.0.9999999-dev

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

The Development Requires

by Julian Finkler

01/12 2016

1.1.0

1.1.0.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

The Development Requires

by Julian Finkler

28/11 2016

1.0.3

1.0.3.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

by Julian Finkler

18/10 2016

1.0.2

1.0.2.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

by Julian Finkler

18/10 2016

1.0.1

1.0.1.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

by Julian Finkler

24/09 2016

1.0.0

1.0.0.0

Easy to use neural network written in PHP

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4.0

 

by Julian Finkler