Example #1
0
 protected function createData()
 {
     $dir = new Dirichlet(1, count($this->topics));
     for ($i = 0; $i < 500; $i++) {
         $d = $this->createDocument($this->topics, $dir->sample(), 100);
         $this->createImage($d, "{$this->path}/data/{$i}");
     }
 }
Example #2
0
<?php

include '../vendor/autoload.php';
use NlpTools\Random\Distributions\Dirichlet;
$dir = new Dirichlet(1, 10);
$sample = $dir->sample();
var_dump($sample, array_sum($sample));
Example #3
0
$topics = array_map(function ($topic) {
    return array_map(function ($row) {
        return array_map(function ($pixel) {
            return (int) (255 * $pixel);
        }, $row);
    }, $topic);
}, $topics);
if (!file_exists('topics')) {
    mkdir('topics');
}
array_walk($topics, function ($topic, $key) {
    create_image($topic, "topics/topic-{$key}");
});
$flat_topics = array_map(function ($topic) {
    $t = call_user_func_array('array_merge', $topic);
    $total = array_sum($t);
    return array_map(function ($ti) use($total) {
        return $ti / $total;
    }, $t);
}, $topics);
$dir = new Dirichlet(1, count($flat_topics));
if (!file_exists('data')) {
    mkdir('data');
}
for ($i = 0; $i < 500; $i++) {
    $doc = create_document($flat_topics, $dir->sample(), 100);
    create_image($doc, "data/{$i}");
}
if (!file_exists('results')) {
    mkdir('results');
}