<?php

/*
 * Problem: We have few things, with 3 properties (normalized, from 0 to 1), and 2 boxes for this things.
 * How to distribute things?
 */
define('DIVIDER', 50);
use Neural\KohonenNetwork;
require_once '../vendor/autoload.php';
//Our things:
$control['Thing A'] = [1, 0.5, 0];
$control['Thing B'] = [0, 0.4, 1];
//Spoiler: this thing should be in different boxes with "Thing A"
$control['Thing C'] = [0, 0.7, 0.9];
//Spoiler: this thing should be in one box with "Thing B"
$p = new KohonenNetwork([3, 2]);
$p->generateSynapses();
//Firstly, learn our network on random things
$learningData = [];
for ($i = 0; $i < 1000; $i++) {
    $randomProperty1 = round(rand(0, DIVIDER) / DIVIDER, 2);
    //random value from 0 to 1
    $randomProperty2 = round(rand(0, DIVIDER) / DIVIDER, 2);
    //random value from 0 to 1
    $randomProperty3 = round(rand(0, DIVIDER) / DIVIDER, 2);
    //random value from 0 to 1
    $learningData[] = [$randomProperty1, $randomProperty2, $randomProperty3];
}
for ($i = 0; $i < 100; $i++) {
    foreach ($learningData as $set) {
        $p->learn($set);
<?php

use Neural\KohonenNetwork;
require_once '../vendor/autoload.php';
$start = microtime(true);
$n = new KohonenNetwork([5, 3]);
$n->generateSynapses();
$forTraining = [];
for ($i = 0; $i < 75; $i++) {
    $forTraining[] = [rand(80, 100) / 100, rand(80, 100) / 100, rand(80, 100) / 100, rand(80, 100) / 100, rand(80, 100) / 100];
    $forTraining[] = [rand(5, 50) / 100, rand(5, 50) / 100, rand(5, 50) / 100, rand(5, 50) / 100, rand(5, 50) / 100];
    $forTraining[] = [rand(5, 100) / 100, rand(5, 100) / 100, rand(5, 100) / 100, rand(5, 100) / 100, rand(5, 100) / 100];
}
$students = ['Arya' => [0.8, 0.6, 0.3, 0.75, 0.7], 'Sansa' => [1, 0.9, 0.93, 0.91, 0.95], 'John' => [0.3, 0.2, 0.35, 0.4, 0.23], 'Rob' => [0.55, 0.7, 0.8, 0.5, 0.75], 'Bran' => [0.8, 0.9, 1, 0.9399999999999999, 0.8]];
for ($i = 0; $i <= 100; $i++) {
    foreach ($forTraining as $student) {
        $n->learn($student);
    }
}
foreach ($students as $name => $student) {
    echo $name . ': ' . array_search(1, $n->input($student)->output()) . PHP_EOL;
}
echo PHP_EOL . 'Time: ' . round(microtime(true) - $start, 3);