protected function conditionalDistribution($i,$w)
     {
         $p = array_fill_keys(range(0,$this->ntopics-1),0);
         for ($topic=0;$topic<$this->ntopics;$topic++) {
            if (isset($this->count_topics_words[$topic][$w]))
                $numerator = $this->count_topics_words[$topic][$w]+$this->b;
            else
                $numerator = $this->b;

            $numerator *= $this->count_docs_topics[$i][$topic]+$this->a;

            $denominator = $this->words_in_topic[$topic]+$this->voccnt*$this->b;
            $denominator *= $this->words_in_doc[$i]+$this->ntopics*$this->a;

            $p[$topic] = $numerator/$denominator;
         }

         // divide by sum to obtain probabilities
         $sum = array_sum($p);

         return array_map(
            function ($p) use ($sum) {
                return $p/$sum;
            },
            $p
         );
     }
protected function conditionalDistribution($i,$w)
     {
         $p = array_fill_keys(range(0,$this->ntopics-1),0);
         for ($topic=0;$topic<$this->ntopics;$topic++) {
            if (isset($this->count_topics_words[$topic][$w]))
                $numerator = $this->count_topics_words[$topic][$w]+$this->b;
            else
                $numerator = $this->b;

            $numerator *= $this->count_docs_topics[$i][$topic]+$this->a;

            $denominator = $this->words_in_topic[$topic]+$this->voccnt*$this->b;
            $denominator *= $this->words_in_doc[$i]+$this->ntopics*$this->a;

            $p[$topic] = $numerator/$denominator;
         }

         // divide by sum to obtain probabilities
         $sum = array_sum($p);

         return array_map(
            function ($p) use ($sum) {
                return $p/$sum;
            },
            $p
         );
     }
protected function conditionalDistribution ( $ i , $ w ) { $ p = array_fill_keys ( range ( 0 , $ this -> ntopics - 1 ) , 0 ) ; for ( $ topic = 0 ; $ topic < $ this -> ntopics ; $ topic ++ ) { if ( isset ( $ this -> count_topics_words [ $ topic ] [ $ w ] ) ) $ numerator = $ this -> count_topics_words [ $ topic ] [ $ w ] + $ this -> b ; else $ numerator = $ this -> b ; $ numerator *= $ this -> count_docs_topics [ $ i ] [ $ topic ] + $ this -> a ; $ denominator = $ this -> words_in_topic [ $ topic ] + $ this -> voccnt * $ this -> b ; $ denominator *= $ this -> words_in_doc [ $ i ] + $ this -> ntopics * $ this -> a ; $ p [ $ topic ] = $ numerator / $ denominator ; } // divide by sum to obtain probabilities $ sum = array_sum ( $ p ) ; return array_map ( function ( $ p ) use ( $ sum ) { return $ p / $ sum ; } , $ p ) ; }
This is the implementation of the equation number 5 in the paper
by Griffiths and Steyvers.

@return array The vector of probabilites for all topics as computed by the equation 5
This is the implementation of the equation number 5 in the paper by Griffiths and Steyvers .