Download the PHP package blondie101010/brain without Composer

On this page you can find all versions of the php package blondie101010/brain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package brain

BRAIN

Binary Reasoning Artificial Intelligence Network - A self-enclosed prediction / extrapolation system.

This document is a simple introduction to the system. For more details, consult the BRAIN manual.

Installation

BRAIN is now in Packagist, so it can be installed with composer as:

composer require blondie101010/brain

Usage

Instanciation

$brain = new \Blondie101010\Brain\Brain($name, $site, $brainPath = "./data");

Parameters:

The BRAIN's file name will be $brainPath/Brain-$name.dat.

Learning

Individual record

You can learn an individual record with the following:

$brain->getAnswer(array $dataRecord, float $result = null);

Parameters:

Note that the result can also be included in the $dataRecord['_result'] special field which is treated exactly as the $result parameter, but $result takes precedence if present and not null.

Batch processing with the Feeder class

Here is a simple script to Feed a data file to the BRAIN:

require "vendor/autoload.php";

use \Blondie101010\Brain\Common;
use \Blondie101010\Brain\Brain;
use \Blondie101010\Brain\Feeder;

Common::$debug = Common::DEBUG_INFO;  // make useful messages visible to see how it progresses

$inputFile = "demo.dat";
$brainName = "demoBrain";
$site = "A";  // site identifier, for future use
$brainPath = "./data";
$skip = 0;
$sample = false;
$batchSize = 25000;

$brain = new Brain($brainName, $site, $brainPath);
$feeder = new Feeder($brain, Feeder::MODE_TEST_AND_LEARN, $skip, $batchSize, $sample);

echo "Processing $inputFile.  Send SIGTERM to end cleanly (and therefore store new learnings).\n";
$feeder->processFile($inputFile);

In order to demonstrate how the BRAIN works and provide a sample script, here is the code to use to generate test data:

$outputFile = "demo.dat";

/*
 * Data set builder for a simple potential murderer profiler.
 *
 * In order to validate the BRAIN's operations, we need to make sure the criteria used can not be misleading,
 * so we'll make rules to define a potential murderer: green race with (blue eyes or big ears) and >= 15 years old
 *
 * The result will be based on the most intensive crime they did which is on a scale of 1-10 where 5 is a fairly small
 * misdemeanor and 7 is a severe agression which could be fatal.
 *
 * Note that we DO NOT believe that the race or ear size have any impact on the criminality level, and some green guys are really nice.
 */

// Use ridiculous criteria to evaluate the risk of someone being a murderer in order to test the learning algorithm in a   consistant fashion.
function rateCriminality(array $person) {
    $result = rand(1, 2);  // base crime level

    if ($person['race'] == 2 && ($person['eyeColor'] == 1 || $person['earSize'] >= 6) && $person['age'] >= 15) {
       $result += rand(6, 7);
    }
    elseif ($person['race'] == 3 && $person['earSize'] > 4) {  // arbitrary rules to fill the middle result (close to 0)
       $result = 5.0;
    }

    // adjust result to be between -1 and +1 for the Brain
    return $result * 0.2 - 1;
}

$colors = ['red', 'blue', 'green', 'purple'];
$data = "";

for ($i = 0; $i < 50000; $i ++) {
   $result = 0;

   $person= ['race' => array_rand($colors), 'eyeColor' => array_rand($colors),
             'earSize' => rand(3, 9), 'age' => rand(1, 60)];

   $person['_result'] = rateCriminality($person);

   $data .= serialize($person) . "\n";
}

file_put_contents($outputFile, $data);

So to test the BRAIN's demo, you basically run the data generator, and then the feeding script on that data file. The above code will use ./demo.dat for the demo input data file (to which the data generator writes).

When you run the feeding script, you'll notice a lot of traces that indicate how it is processing the data. It basically runs a pass on the batch size requested, then it works on the records which were not learned correctly until it reaches a certain level, retests the whole batch (B test), and if the result is acceptable, it moves to the next batch. The demo does batches of 25K records while there are 50K records in the data file, so it does two batches when you run it.

As you'll see, the more it progresses the higher and more stable are the different test results.

Getting the answer

The answer is obtained exactly the same way as it is learned. To get the answer from a data record, you simply don't provide the actual result. So you call getAnswer() with no second parameter and the $dataRecord doesn't contain a '_result' field.

$answer = $brain->getAnswer($dataRecord);

Support

There isn't yet a defined support channel other than github here, but we plan on opening a support channel on IRC if there is a demand for it. Those interested may be able to reach me on FreeNode IRC under the nickname blondie101010 or on Gitter.

If you notice any issues or have a suggestion, be assured that all constructive comments are welcome.

Commercial development and support arrangements are possible on demand.


All versions of brain with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package blondie101010/brain contains the following files

Loading the files please wait ....