static public function tmi(array $ngram, int $totalNgrams) : float
    {
        $var = self::setStatVariables($ngram, $totalNgrams);


        $tmi3 = 0;

        if($var['jointFrequency']) {
            $tmi3 += $var['jointFrequency']/$totalNgrams * self::computePMI( $var['jointFrequency'], $var['e111'] )/ log(2);
        }

        if($var['n112']) {
            $tmi3 += $var['n112']/$totalNgrams * self::computePMI( $var['n112'], $var['e112'] )/ log(2);
        }

        if($var['n121']) {
            $tmi3 += $var['n121']/$totalNgrams * self::computePMI( $var['n121'], $var['e121'] )/ log(2);
        }


        if($var['n122']) {
            $tmi3 += $var['n122']/$totalNgrams * self::computePMI( $var['n122'], $var['e122'] )/ log(2);
        }

        if($var['n211']) {
            $tmi3 += $var['n211']/$totalNgrams * self::computePMI( $var['n211'], $var['e211'] )/ log(2);
        }

        if($var['n212']) {
            $tmi3 += $var['n212']/$totalNgrams * self::computePMI( $var['n212'], $var['e212'] )/ log(2);
        }

        if($var['n221']) {
            $tmi3 += $var['n221']/$totalNgrams * self::computePMI( $var['n221'], $var['e221'] )/ log(2);
        }

        if($var['n222']) {
            $tmi3 += $var['n222']/$totalNgrams * self::computePMI( $var['n222'], $var['e222'] )/ log(2);
        }

        return $tmi3;
    }
static public function tmi(array $ngram, int $totalNgrams) : float
    {
        $var = self::setStatVariables($ngram, $totalNgrams);


        $tmi3 = 0;

        if($var['jointFrequency']) {
            $tmi3 += $var['jointFrequency']/$totalNgrams * self::computePMI( $var['jointFrequency'], $var['e111'] )/ log(2);
        }

        if($var['n112']) {
            $tmi3 += $var['n112']/$totalNgrams * self::computePMI( $var['n112'], $var['e112'] )/ log(2);
        }

        if($var['n121']) {
            $tmi3 += $var['n121']/$totalNgrams * self::computePMI( $var['n121'], $var['e121'] )/ log(2);
        }


        if($var['n122']) {
            $tmi3 += $var['n122']/$totalNgrams * self::computePMI( $var['n122'], $var['e122'] )/ log(2);
        }

        if($var['n211']) {
            $tmi3 += $var['n211']/$totalNgrams * self::computePMI( $var['n211'], $var['e211'] )/ log(2);
        }

        if($var['n212']) {
            $tmi3 += $var['n212']/$totalNgrams * self::computePMI( $var['n212'], $var['e212'] )/ log(2);
        }

        if($var['n221']) {
            $tmi3 += $var['n221']/$totalNgrams * self::computePMI( $var['n221'], $var['e221'] )/ log(2);
        }

        if($var['n222']) {
            $tmi3 += $var['n222']/$totalNgrams * self::computePMI( $var['n222'], $var['e222'] )/ log(2);
        }

        return $tmi3;
    }
static public function tmi ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ tmi3 = 0 ; if ( $ var [ 'jointFrequency' ] ) { $ tmi3 += $ var [ 'jointFrequency' ] / $ totalNgrams * self :: computePMI ( $ var [ 'jointFrequency' ] , $ var [ 'e111' ] ) / log ( 2 ) ; } if ( $ var [ 'n112' ] ) { $ tmi3 += $ var [ 'n112' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n112' ] , $ var [ 'e112' ] ) / log ( 2 ) ; } if ( $ var [ 'n121' ] ) { $ tmi3 += $ var [ 'n121' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n121' ] , $ var [ 'e121' ] ) / log ( 2 ) ; } if ( $ var [ 'n122' ] ) { $ tmi3 += $ var [ 'n122' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n122' ] , $ var [ 'e122' ] ) / log ( 2 ) ; } if ( $ var [ 'n211' ] ) { $ tmi3 += $ var [ 'n211' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n211' ] , $ var [ 'e211' ] ) / log ( 2 ) ; } if ( $ var [ 'n212' ] ) { $ tmi3 += $ var [ 'n212' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n212' ] , $ var [ 'e212' ] ) / log ( 2 ) ; } if ( $ var [ 'n221' ] ) { $ tmi3 += $ var [ 'n221' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n221' ] , $ var [ 'e221' ] ) / log ( 2 ) ; } if ( $ var [ 'n222' ] ) { $ tmi3 += $ var [ 'n222' ] / $ totalNgrams * self :: computePMI ( $ var [ 'n222' ] , $ var [ 'e222' ] ) / log ( 2 ) ; } return $ tmi3 ; }
Calculate the true mutual information value for trigrams
@param array $ngram Array of ngrams with frequencies
@return float Return the calculated value
Calculate the true mutual information value for trigrams