public function partial(Dataset $dataset) : void
    {
        if (empty($this->weights) or empty($this->means) or empty($this->variances)) {
            $this->train($dataset);

            return;
        }

        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This Estimator requires a'
                . ' Labeled training set.');
        }

        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        foreach ($dataset->stratify() as $class => $stratum) {
            $means = $this->means[$class];
            $variances = $this->variances[$class];

            $oldWeight = $this->weights[$class];
            $oldMeans = $this->means[$class];
            $oldVariances = $this->variances[$class];

            $n = $stratum->numRows();

            foreach ($stratum->columns() as $column => $values) {
                [$mean, $variance] = Stats::meanVar($values);

                $means[$column] = (($n * $mean)
                    + ($oldWeight * $oldMeans[$column]))
                    / ($oldWeight + $n);

                $vHat = ($oldWeight
                    * $oldVariances[$column] + ($n * $variance)
                    + ($oldWeight / ($n * ($oldWeight + $n)))
                    * ($n * $oldMeans[$column] - $n * $mean) ** 2)
                    / ($oldWeight + $n);

                $variances[$column] = $vHat ?: EPSILON;
            }

            $this->means[$class] = $means;
            $this->variances[$class] = $variances;
            
            $this->weights[$class] += $n;
        }

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

            foreach ($this->weights as $class => $weight) {
                $this->priors[$class] = log($weight / $total);
            }
        }
    }
public function partial(Dataset $dataset) : void
    {
        if (empty($this->weights) or empty($this->means) or empty($this->variances)) {
            $this->train($dataset);

            return;
        }

        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This Estimator requires a'
                . ' Labeled training set.');
        }

        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        foreach ($dataset->stratify() as $class => $stratum) {
            $means = $this->means[$class];
            $variances = $this->variances[$class];

            $oldWeight = $this->weights[$class];
            $oldMeans = $this->means[$class];
            $oldVariances = $this->variances[$class];

            $n = $stratum->numRows();

            foreach ($stratum->columns() as $column => $values) {
                [$mean, $variance] = Stats::meanVar($values);

                $means[$column] = (($n * $mean)
                    + ($oldWeight * $oldMeans[$column]))
                    / ($oldWeight + $n);

                $vHat = ($oldWeight
                    * $oldVariances[$column] + ($n * $variance)
                    + ($oldWeight / ($n * ($oldWeight + $n)))
                    * ($n * $oldMeans[$column] - $n * $mean) ** 2)
                    / ($oldWeight + $n);

                $variances[$column] = $vHat ?: EPSILON;
            }

            $this->means[$class] = $means;
            $this->variances[$class] = $variances;
            
            $this->weights[$class] += $n;
        }

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

            foreach ($this->weights as $class => $weight) {
                $this->priors[$class] = log($weight / $total);
            }
        }
    }
public function partial ( Dataset $ dataset ) : void { if ( empty ( $ this -> weights ) or empty ( $ this -> means ) or empty ( $ this -> variances ) ) { $ this -> train ( $ dataset ) ; return ; } if ( ! $ dataset instanceof Labeled ) { throw new InvalidArgumentException ( 'This Estimator requires a' . ' Labeled training set.' ) ; } DatasetIsCompatibleWithEstimator :: check ( $ dataset , $ this ) ; foreach ( $ dataset -> stratify ( ) as $ class => $ stratum ) { $ means = $ this -> means [ $ class ] ; $ variances = $ this -> variances [ $ class ] ; $ oldWeight = $ this -> weights [ $ class ] ; $ oldMeans = $ this -> means [ $ class ] ; $ oldVariances = $ this -> variances [ $ class ] ; $ n = $ stratum -> numRows ( ) ; foreach ( $ stratum -> columns ( ) as $ column => $ values ) { [ $ mean , $ variance ] = Stats :: meanVar ( $ values ) ; $ means [ $ column ] = ( ( $ n * $ mean ) + ( $ oldWeight * $ oldMeans [ $ column ] ) ) / ( $ oldWeight + $ n ) ; $ vHat = ( $ oldWeight * $ oldVariances [ $ column ] + ( $ n * $ variance ) + ( $ oldWeight / ( $ n * ( $ oldWeight + $ n ) ) ) * ( $ n * $ oldMeans [ $ column ] - $ n * $ mean ) ** 2 ) / ( $ oldWeight + $ n ) ; $ variances [ $ column ] = $ vHat ? : EPSILON ; } $ this -> means [ $ class ] = $ means ; $ this -> variances [ $ class ] = $ variances ; $ this -> weights [ $ class ] += $ n ; } if ( $ this -> fitPriors ) { $ total = array_sum ( $ this -> weights ) ? : EPSILON ; foreach ( $ this -> weights as $ class => $ weight ) { $ this -> priors [ $ class ] = log ( $ weight / $ total ) ; } } }
Uupdate the rolling means and variances of each feature column using an
online updating algorithm.

@param \Rubix\ML\Datasets\Dataset $dataset
@throws \InvalidArgumentException
Uupdate the rolling means and variances of each feature column using an online updating algorithm .