Update the fitting of the transformer.

@param \Rubix\ML\Datasets\Dataset $dataset
358402
public function update(Dataset $dataset) : void
    {
        if ($this->maxabs === null) {
            $this->fit($dataset);
            
            return;
        }

        foreach ($this->maxabs as $column => $oldMax) {
            $values = $dataset->column($column);

            $max = max(array_map('abs', $values));

            $max = max($oldMax, $max);

            $this->maxabs[$column] = $max ?: EPSILON;
        }
    }
253570
protected function processDataSet(DataSet $dataSet)
    {
        if ($dataSet->getPattern() === File::HEADER_PATTERN) {
            $this->processHeader($dataSet);
        } else {
            $this->processBrowserData($dataSet);
        }
    }
487786
public function train(Dataset $dataset) : void
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This estimator requires a'
                . ' labeled training set.');
        }

        $this->strategy->fit($dataset->labels());

        $this->trained = true;
    }
626779
public function train(Dataset $dataset) : void
    {
        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        [$m, $n] = $dataset->shape();

        $this->r = Matrix::gaussian($n, $this->estimators);

        if ($n >= self::MIN_SPARSE_DIMENSIONS) {
            $mask = Matrix::rand($n, $this->estimators)
                ->less(sqrt($n) / $n);

            $this->r = $this->r->multiply($mask);
        }

        $z = Matrix::quick($dataset->samples())
            ->matmul($this->r)
            ->transpose();

        foreach ($z as $values) {
            $min = min($values) - EPSILON;
            $max = max($values) + EPSILON;

            $edges = Vector::linspace($min, $max, $this->bins + 1)->asArray();

            $edges[] = INF;

            $counts = array_fill(0, $this->bins + 2, 0);

            $interior = array_slice($edges, 1, $this->bins);

            foreach ($values as $value) {
                foreach ($interior as $k => $edge) {
                    if ($value < $edge) {
                        $counts[$k]++;

                        continue 2;
                    }
                }

                $counts[$this->bins]++;
            }

            $densities = [];

            foreach ($counts as $count) {
                $densities[] = $count > 0
                    ? -log($count / $m)
                    : -LOG_EPSILON;
            }

            $this->histograms[] = [$edges, $counts, $densities];
        }

        $this->n = $m;
    }
817008
public function train(Dataset $dataset) : void
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This estimator requires a'
                . ' labeled training set.');
        }

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

        if ($this->logger) {
            $this->logger->info('Learner init ' . Params::stringify([
                'booster' => $this->booster,
                'rate' => $this->rate,
                'estimators' => $this->estimators,
                'ratio' => $this->ratio,
                'min_change' => $this->minChange,
                'tolerance' => $this->tolerance,
                'base' => $this->base,
            ]));
        }

        $n = $dataset->numRows();
        $p = (int) round($this->ratio * $n);

        if ($this->logger) {
            $this->logger->info('Training '
                . Params::shortName($this->base) . ' base estimator');
        }

        $this->base->train($dataset);

        $predictions = $this->base->predict($dataset);

        $yHat = [];

        foreach ($predictions as $i => $prediction) {
            $yHat[] = $dataset->label($i) - $prediction;
        }

        $residual = Labeled::quick($dataset->samples(), $yHat);

        if ($this->logger) {
            $this->logger->info("Boosting with $this->estimators "
                . Params::shortName($this->booster)
                . ($this->estimators > 1 ? 's' : ''));
        }

        $this->ensemble = $this->steps = [];

        $previous = INF;

        for ($epoch = 1; $epoch <= $this->estimators; $epoch++) {
            $booster = clone $this->booster;

            $subset = $residual->randomize()->head($p);

            $booster->train($subset);

            $predictions = $booster->predict($residual);

            $labels = $residual->labels();

            $loss = 0.;

            foreach ($predictions as $i => $prediction) {
                $label = $labels[$i];

                $loss += ($label - $prediction) ** 2;
                $yHat[$i] = $label - ($this->rate * $prediction);
            }

            $loss /= $n;

            $this->ensemble[] = $booster;
            $this->steps[] = $loss;

            if ($this->logger) {
                $this->logger->info("Epoch $epoch complete, loss=$loss");
            }

            if (is_nan($loss)) {
                break 1;
            }

            if (abs($previous - $loss) < $this->minChange) {
                break 1;
            }

            if ($loss < $this->tolerance) {
                break 1;
            }

            $residual = Labeled::quick($residual->samples(), $yHat);

            $previous = $loss;
        }

        if ($this->logger) {
            $this->logger->info('Training complete');
        }
    }
1152365
public function predict(Dataset $dataset) : array
    {
        if ($this->bare()) {
            throw new RuntimeException('Estimator has not been trained.');
        }

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

        $predictions = [];

        foreach ($dataset as $sample) {
            $node = $this->search($sample);

            $predictions[] = $node instanceof Average
                ? $node->outcome()
                : null;
        }

        return $predictions;
    }
281042
public function train(Dataset $dataset) : void
    {
        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        $columns = $dataset->columns();

        $this->medians = $this->mads = [];

        foreach ($columns as $column => $values) {
            [$median, $mad] = Stats::medMad($values);

            $this->medians[$column] = $median;
            $this->mads[$column] = $mad;
        }
    }
141583
public function execute(DataSetInterface $dataSet): void
    {
        if (!$dataSet[MerchantRelationshipDataSetInterface::COMPANY_BUSINESS_UNIT_ASSIGNEE_KEYS]) {
            $dataSet[MerchantRelationshipDataSetInterface::ID_COMPANY_BUSINESS_UNIT_ASSIGNEE_COLLECTION] = [];

            return;
        }

        $companyBusinessUnitKeys = explode(
            $this->getAssigneeDelimiter(),
            $dataSet[MerchantRelationshipDataSetInterface::COMPANY_BUSINESS_UNIT_ASSIGNEE_KEYS]
        );

        $companyBusinessUnitAssignee = [];
        foreach ($companyBusinessUnitKeys as $companyBusinessUnitKey) {
            $companyBusinessUnitAssignee[] = $this->findIdCompanyBusinessUnit($companyBusinessUnitKey);
        }

        $dataSet[MerchantRelationshipDataSetInterface::ID_COMPANY_BUSINESS_UNIT_ASSIGNEE_COLLECTION] = $companyBusinessUnitAssignee;
    }
355953
public function execute(DataSetInterface $dataSet): void
    {
        if (empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ABSTRACT_SKU]) && empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::CONCRETE_SKU])) {
            throw new DataKeyNotFoundInDataSetException(sprintf(
                'One of "%s" or "%s" must be in the data set. Given: "%s"',
                PriceProductMerchantRelationshipDataSetInterface::ABSTRACT_SKU,
                PriceProductMerchantRelationshipDataSetInterface::CONCRETE_SKU,
                implode(', ', array_keys($dataSet->getArrayCopy()))
            ));
        }

        $productAbstractSku = $dataSet[PriceProductMerchantRelationshipDataSetInterface::ABSTRACT_SKU];
        if (!empty($productAbstractSku)) {
            $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT] = $this->resolveIdProductByAbstractSku($productAbstractSku);
        }

        $productConcreteSku = $dataSet[PriceProductMerchantRelationshipDataSetInterface::CONCRETE_SKU];
        if (!empty($productConcreteSku)) {
            $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE] = $this->resolveIdProductByConcreteSku($productConcreteSku);
        }
    }
442803
public function predict(Dataset $dataset) : array
    {
        if (empty($this->ensemble) or empty($this->influences)) {
            throw new RuntimeException('The learner has not'
                . ' been trained.');
        }
        
        return array_map('Rubix\ML\argmax', $this->score($dataset));
    }
901036
public function fit(Dataset $dataset) : void
    {
        $columns = $dataset->columnsByType(DataType::CONTINUOUS);

        $this->selected = [];

        foreach ($columns as $column => $values) {
            if (Stats::variance($values) <= $this->threshold) {
                continue 1;
            }

            $this->selected[$column] = true;
        }
    }
394850
public function execute(DataSetInterface $dataSet): void
    {
        $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT_STORE] = $this->getIdPriceProductStoreEntity($dataSet);
    }
873963
private function buildMean(Dataset $dataset): self
    {
        $this->mean = mean(...$dataset->ordinates());

        return $this;
    }
1310688
public function execute(DataSetInterface $dataSet): void
    {
        $this->assertHaveProductMeasurementSalesUnit($dataSet[ProductPackagingUnitDataSetInterface::COLUMN_CONCRETE_SKU]);
        $dataSet = $this->normalizeDataSet($dataSet);
        $productPackagingUnitTypeId = $this->getIdProductPackagingUnitTypeByName($dataSet[ProductPackagingUnitDataSetInterface::COLUMN_TYPE_NAME]);
        $productConcreteId = $this->getIdProductBySku($dataSet[ProductPackagingUnitDataSetInterface::COLUMN_CONCRETE_SKU]);

        $productPackagingUnitEntity = $this->getProductPackagingUnitQuery()
            ->filterByFkProduct($productConcreteId)
            ->findOneOrCreate();

        $this->persistLeadProduct($dataSet, $productConcreteId);

        $productPackagingUnitEntity
            ->setHasLeadProduct($dataSet[ProductPackagingUnitDataSetInterface::COLUMN_HAS_LEAD_PRODUCT])
            ->setFkProductPackagingUnitType($productPackagingUnitTypeId);

        $productPackagingUnitEntity->save();

        if ($this->hasAmount($dataSet)) {
            $this->persistAmount($dataSet, $productPackagingUnitEntity);
        }

        $this->addPublishEvents(ProductPackagingUnitEvents::PRODUCT_ABSTRACT_PACKAGING_PUBLISH, $this->getIdProductAbstractByProductSku($dataSet[ProductPackagingUnitDataSetInterface::COLUMN_CONCRETE_SKU]));
    }
332600
public function execute(DataSetInterface $dataSet): void
    {
        if (!$dataSet[ProductAlternativeDataSetInterface::KEY_COLUMN_ALTERNATIVE_PRODUCT_ABSTRACT_SKU]) {
            return;
        }

        $this->addAlternativeProductAbstractId($dataSet);
    }
979828
public function partial(Dataset $dataset) : void
    {
        if ($this->elastic) {
            $this->update($dataset);
        }

        if ($this->estimator instanceof Online) {
            $this->estimator->partial($dataset);
        }
    }
1217154
public function train(Dataset $dataset) : void
    {
        if ($this->type === self::CLASSIFIER or $this->type === self::REGRESSOR) {
            if (!$dataset instanceof Labeled) {
                throw new InvalidArgumentException('This estimator requires a'
                    . ' labeled training set.');
            }
        }

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

        if ($this->logger) {
            $this->logger->info('Learner init ' . Params::stringify([
                'experts' => $this->experts,
                'influences' => $this->influences,
                'workers' => $this->workers,
            ]));
        }

        Loop::run(function () use ($dataset) {
            $pool = new DefaultPool($this->workers);

            $coroutines = [];

            foreach ($this->experts as $index => $estimator) {
                $task = new CallableTask(
                    [$this, '_train'],
                    [$estimator, $dataset]
                );

                $coroutines[] = call(function () use ($pool, $task, $index) {
                    $estimator = yield $pool->enqueue($task);

                    if ($this->logger) {
                        $this->logger->info(Params::stringify([
                            $index => $estimator,
                        ]) . ' finished training');
                    }

                    return $estimator;
                });
            }

            $this->experts = yield all($coroutines);
            
            return yield $pool->shutdown();
        });

        if ($this->type === self::CLASSIFIER and $dataset instanceof Labeled) {
            $this->classes = $dataset->possibleOutcomes();
        }

        if ($this->logger) {
            $this->logger->info('Training complete');
        }
    }