An open API service indexing awesome lists of open source software.

https://github.com/devtronic/legendary-mind

Easy to use neural network written in PHP
https://github.com/devtronic/legendary-mind

neural-network php wrapper

Last synced: about 1 year ago
JSON representation

Easy to use neural network written in PHP

Awesome Lists containing this project

README

          

[![GitHub tag](https://img.shields.io/packagist/v/Devtronic/legendary-mind.svg)](https://github.com/Devtronic/legendary-mind)
[![Packagist](https://img.shields.io/packagist/l/Devtronic/legendary-mind.svg)](https://github.com/Devtronic/legendary-mind/blob/master/LICENSE)
[![Travis](https://img.shields.io/travis/Devtronic/legendary-mind.svg)](https://travis-ci.org/Devtronic/legendary-mind/)
[![Packagist](https://img.shields.io/packagist/dt/Devtronic/legendary-mind.svg)](https://github.com/Devtronic/legendary-mind)

# 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
```bash
composer require devtronic/legendary-mind
```

### Usage
#### Standalone Network
```php
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
['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
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);
```