public function partial(Dataset $dataset) : void
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This Estimator requires a'
                . ' Labeled training set.');
        }

        if (!$dataset->homogeneous() or $dataset->columnType(0) !== DataType::CATEGORICAL) {
            throw new InvalidArgumentException('This estimator only works'
                . ' with categorical features.');
        }

        if (empty($this->weights) or empty($this->counts) or empty($this->probs)) {
            $this->train($dataset);
            return;
        }

        foreach ($dataset->stratify() as $class => $stratum) {
            $classCounts = $this->counts[$class];
            $classProbs = $this->probs[$class];

            foreach ($stratum->columns() as $column => $values) {
                $columnCounts = $classCounts[$column];

                $counts = array_count_values($values);

                foreach ($counts as $category => $count) {
                    if (isset($columnCounts[$category])) {
                        $columnCounts[$category] += $count;
                    } else {
                        $columnCounts[$category] = $count;
                    }
                }

                $total = (array_sum($columnCounts)
                    + (count($columnCounts) * $this->alpha))
                    ?: EPSILON;

                $probs = [];

                foreach ($columnCounts as $category => $count) {
                    $probs[$category] = log(($count + $this->alpha) / $total);
                }

                $classCounts[$column] = $columnCounts;
                $classProbs[$column] = $probs;
            }

            $this->counts[$class] = $classCounts;
            $this->probs[$class] = $classProbs;

            $this->weights[$class] += $stratum->numRows();
        }

        if ($this->fitPriors) {
            $total = (array_sum($this->weights)
                + (count($this->weights) * $this->alpha))
                ?: EPSILON;

            foreach ($this->weights as $class => $weight) {
                $this->priors[$class] = log(($weight + $this->alpha) / $total);
            }
        }
    }
public function partial(Dataset $dataset) : void
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This Estimator requires a'
                . ' Labeled training set.');
        }

        if (!$dataset->homogeneous() or $dataset->columnType(0) !== DataType::CATEGORICAL) {
            throw new InvalidArgumentException('This estimator only works'
                . ' with categorical features.');
        }

        if (empty($this->weights) or empty($this->counts) or empty($this->probs)) {
            $this->train($dataset);
            return;
        }

        foreach ($dataset->stratify() as $class => $stratum) {
            $classCounts = $this->counts[$class];
            $classProbs = $this->probs[$class];

            foreach ($stratum->columns() as $column => $values) {
                $columnCounts = $classCounts[$column];

                $counts = array_count_values($values);

                foreach ($counts as $category => $count) {
                    if (isset($columnCounts[$category])) {
                        $columnCounts[$category] += $count;
                    } else {
                        $columnCounts[$category] = $count;
                    }
                }

                $total = (array_sum($columnCounts)
                    + (count($columnCounts) * $this->alpha))
                    ?: EPSILON;

                $probs = [];

                foreach ($columnCounts as $category => $count) {
                    $probs[$category] = log(($count + $this->alpha) / $total);
                }

                $classCounts[$column] = $columnCounts;
                $classProbs[$column] = $probs;
            }

            $this->counts[$class] = $classCounts;
            $this->probs[$class] = $classProbs;

            $this->weights[$class] += $stratum->numRows();
        }

        if ($this->fitPriors) {
            $total = (array_sum($this->weights)
                + (count($this->weights) * $this->alpha))
                ?: EPSILON;

            foreach ($this->weights as $class => $weight) {
                $this->priors[$class] = log(($weight + $this->alpha) / $total);
            }
        }
    }
public function partial ( Dataset $ dataset ) : void { if ( ! $ dataset instanceof Labeled ) { throw new InvalidArgumentException ( 'This Estimator requires a' . ' Labeled training set.' ) ; } if ( ! $ dataset -> homogeneous ( ) or $ dataset -> columnType ( 0 ) !== DataType :: CATEGORICAL ) { throw new InvalidArgumentException ( 'This estimator only works' . ' with categorical features.' ) ; } if ( empty ( $ this -> weights ) or empty ( $ this -> counts ) or empty ( $ this -> probs ) ) { $ this -> train ( $ dataset ) ; return ; } foreach ( $ dataset -> stratify ( ) as $ class => $ stratum ) { $ classCounts = $ this -> counts [ $ class ] ; $ classProbs = $ this -> probs [ $ class ] ; foreach ( $ stratum -> columns ( ) as $ column => $ values ) { $ columnCounts = $ classCounts [ $ column ] ; $ counts = array_count_values ( $ values ) ; foreach ( $ counts as $ category => $ count ) { if ( isset ( $ columnCounts [ $ category ] ) ) { $ columnCounts [ $ category ] += $ count ; } else { $ columnCounts [ $ category ] = $ count ; } } $ total = ( array_sum ( $ columnCounts ) + ( count ( $ columnCounts ) * $ this -> alpha ) ) ? : EPSILON ; $ probs = [ ] ; foreach ( $ columnCounts as $ category => $ count ) { $ probs [ $ category ] = log ( ( $ count + $ this -> alpha ) / $ total ) ; } $ classCounts [ $ column ] = $ columnCounts ; $ classProbs [ $ column ] = $ probs ; } $ this -> counts [ $ class ] = $ classCounts ; $ this -> probs [ $ class ] = $ classProbs ; $ this -> weights [ $ class ] += $ stratum -> numRows ( ) ; } if ( $ this -> fitPriors ) { $ total = ( array_sum ( $ this -> weights ) + ( count ( $ this -> weights ) * $ this -> alpha ) ) ? : EPSILON ; foreach ( $ this -> weights as $ class => $ weight ) { $ this -> priors [ $ class ] = log ( ( $ weight + $ this -> alpha ) / $ total ) ; } } }
Compute the rolling counts and conditional probabilities.

@param \Rubix\ML\Datasets\Dataset $dataset
@throws \InvalidArgumentException
Compute the rolling counts and conditional probabilities .