public function initialize(array &$docs)
    {
        $doc_keys = range(0,count($docs)-1);
        $topic_keys = range(0,$this->ntopics-1);

        // initialize the arrays
        $this->words_in_doc = array_fill_keys(
            $doc_keys,
            0
        );
        $this->words_in_topic = array_fill_keys(
            $topic_keys,
            0
        );
        $this->count_docs_topics = array_fill_keys(
            $doc_keys,
            array_fill_keys(
                $topic_keys,
                0
            )
        );
        $this->count_topics_words = array_fill_keys(
            $topic_keys,
            array()
        );
        $this->word_doc_assigned_topic = array_fill_keys(
            $doc_keys,
            array()
        );
        $this->voc = array();

        foreach ($docs as $i=>$doc) {
            $this->words_in_doc[$i] = count($doc);
            foreach ($doc as $idx=>$w) {
                // choose a topic randomly to assign this word to
                $topic = (int) ($this->mt->generate()*$this->ntopics);

                //$this->words_in_doc[$i]++;
                $this->words_in_topic[$topic]++;
                $this->count_docs_topics[$i][$topic]++;

                if (!isset($this->count_topics_words[$topic][$w]))
                    $this->count_topics_words[$topic][$w]=0;
                $this->count_topics_words[$topic][$w]++;

                $this->word_doc_assigned_topic[$i][$idx] = $topic;

                $this->voc[$w] = 1;
            }
        }
        $this->voccnt = count($this->voc);
        $this->voc = array_keys($this->voc);
    }
public function initialize(array &$docs)
    {
        $doc_keys = range(0,count($docs)-1);
        $topic_keys = range(0,$this->ntopics-1);

        // initialize the arrays
        $this->words_in_doc = array_fill_keys(
            $doc_keys,
            0
        );
        $this->words_in_topic = array_fill_keys(
            $topic_keys,
            0
        );
        $this->count_docs_topics = array_fill_keys(
            $doc_keys,
            array_fill_keys(
                $topic_keys,
                0
            )
        );
        $this->count_topics_words = array_fill_keys(
            $topic_keys,
            array()
        );
        $this->word_doc_assigned_topic = array_fill_keys(
            $doc_keys,
            array()
        );
        $this->voc = array();

        foreach ($docs as $i=>$doc) {
            $this->words_in_doc[$i] = count($doc);
            foreach ($doc as $idx=>$w) {
                // choose a topic randomly to assign this word to
                $topic = (int) ($this->mt->generate()*$this->ntopics);

                //$this->words_in_doc[$i]++;
                $this->words_in_topic[$topic]++;
                $this->count_docs_topics[$i][$topic]++;

                if (!isset($this->count_topics_words[$topic][$w]))
                    $this->count_topics_words[$topic][$w]=0;
                $this->count_topics_words[$topic][$w]++;

                $this->word_doc_assigned_topic[$i][$idx] = $topic;

                $this->voc[$w] = 1;
            }
        }
        $this->voccnt = count($this->voc);
        $this->voc = array_keys($this->voc);
    }
public function initialize ( array & $ docs ) { $ doc_keys = range ( 0 , count ( $ docs ) - 1 ) ; $ topic_keys = range ( 0 , $ this -> ntopics - 1 ) ; // initialize the arrays $ this -> words_in_doc = array_fill_keys ( $ doc_keys , 0 ) ; $ this -> words_in_topic = array_fill_keys ( $ topic_keys , 0 ) ; $ this -> count_docs_topics = array_fill_keys ( $ doc_keys , array_fill_keys ( $ topic_keys , 0 ) ) ; $ this -> count_topics_words = array_fill_keys ( $ topic_keys , array ( ) ) ; $ this -> word_doc_assigned_topic = array_fill_keys ( $ doc_keys , array ( ) ) ; $ this -> voc = array ( ) ; foreach ( $ docs as $ i => $ doc ) { $ this -> words_in_doc [ $ i ] = count ( $ doc ) ; foreach ( $ doc as $ idx => $ w ) { // choose a topic randomly to assign this word to $ topic = ( int ) ( $ this -> mt -> generate ( ) * $ this -> ntopics ) ; //$this->words_in_doc[$i]++; $ this -> words_in_topic [ $ topic ] ++ ; $ this -> count_docs_topics [ $ i ] [ $ topic ] ++ ; if ( ! isset ( $ this -> count_topics_words [ $ topic ] [ $ w ] ) ) $ this -> count_topics_words [ $ topic ] [ $ w ] = 0 ; $ this -> count_topics_words [ $ topic ] [ $ w ] ++ ; $ this -> word_doc_assigned_topic [ $ i ] [ $ idx ] = $ topic ; $ this -> voc [ $ w ] = 1 ; } } $ this -> voccnt = count ( $ this -> voc ) ; $ this -> voc = array_keys ( $ this -> voc ) ; }
Count initially the co-occurences of documents,topics and
topics,words and cache them to run Gibbs sampling faster

@param array $docs The docs that we will use to generate the sample
Count initially the co - occurences of documents topics and topics words and cache them to run Gibbs sampling faster