Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Direct initialization" für Klassenvariablen verwenden #790

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ namespace boosting {
: AbstractIncrementalPredictor<FeatureMatrix, Model, DensePredictionMatrix<uint8>>(
predictor.featureMatrix_, predictor.model_, predictor.numThreads_, maxRules),
binaryTransformationPtr_(binaryTransformationPtr),
realMatrix_(DensePredictionMatrix<float64>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_,
binaryTransformationPtr_ != nullptr)),
predictionMatrix_(DensePredictionMatrix<uint8>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_,
binaryTransformationPtr_ == nullptr)) {}
realMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_,
binaryTransformationPtr_ != nullptr),
predictionMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_,
binaryTransformationPtr_ == nullptr) {}
};

class PredictionDelegate final
Expand Down Expand Up @@ -280,10 +278,9 @@ namespace boosting {
: AbstractIncrementalPredictor<FeatureMatrix, Model, BinarySparsePredictionMatrix>(
predictor.featureMatrix_, predictor.model_, predictor.numThreads_, maxRules),
binaryTransformationPtr_(binaryTransformationPtr),
realMatrix_(DensePredictionMatrix<float64>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_,
binaryTransformationPtr_ != nullptr)),
predictionMatrix_(BinaryLilMatrix(predictor.featureMatrix_.getNumRows())) {}
realMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_,
binaryTransformationPtr_ != nullptr),
predictionMatrix_(predictor.featureMatrix_.getNumRows()) {}
};

class PredictionDelegate final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ namespace boosting {
: AbstractIncrementalPredictor<FeatureMatrix, Model, DensePredictionMatrix<float64>>(
predictor.featureMatrix_, predictor.model_, predictor.numThreads_, maxRules),
probabilityTransformationPtr_(probabilityTransformationPtr),
scoreMatrix_(DensePredictionMatrix<float64>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_,
probabilityTransformationPtr_ != nullptr)),
predictionMatrix_(DensePredictionMatrix<float64>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_,
probabilityTransformationPtr_ == nullptr)) {}
scoreMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_,
probabilityTransformationPtr_ != nullptr),
predictionMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_,
probabilityTransformationPtr_ == nullptr) {}
};

const FeatureMatrix& featureMatrix_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ namespace boosting {
IncrementalPredictor(const ScorePredictor& predictor, uint32 maxRules)
: AbstractIncrementalPredictor<FeatureMatrix, Model, DensePredictionMatrix<float64>>(
predictor.featureMatrix_, predictor.model_, predictor.numThreads_, maxRules),
predictionMatrix_(DensePredictionMatrix<float64>(predictor.featureMatrix_.getNumRows(),
predictor.numLabels_, true)) {}
predictionMatrix_(predictor.featureMatrix_.getNumRows(), predictor.numLabels_, true) {}
};

const FeatureMatrix& featureMatrix_;
Expand Down
3 changes: 1 addition & 2 deletions cpp/subprojects/boosting/src/mlrl/boosting/learner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace boosting {
Blas::DdotFunction ddotFunction,
Blas::DspmvFunction dspmvFunction,
Lapack::DsysvFunction dsysvFunction)
: AbstractRuleLearner(config), config_(config), blas_(Blas(ddotFunction, dspmvFunction)),
lapack_(Lapack(dsysvFunction)) {}
: AbstractRuleLearner(config), config_(config), blas_(ddotFunction, dspmvFunction), lapack_(dsysvFunction) {}

std::unique_ptr<IStatisticsProviderFactory> AbstractBoostingRuleLearner::createStatisticsProviderFactory(
const IFeatureMatrix& featureMatrix, const IRowWiseLabelMatrix& labelMatrix) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ namespace boosting {
std::unique_ptr<ILabelBinning> binningPtr, const Blas& blas,
const Lapack& lapack)
: AbstractExampleWiseRuleEvaluation<DenseExampleWiseStatisticVector, IndexVector>(maxBins, lapack),
maxBins_(maxBins),
scoreVector_(DenseBinnedScoreVector<IndexVector>(labelIndices, maxBins + 1, indicesSorted)),
maxBins_(maxBins), scoreVector_(labelIndices, maxBins + 1, indicesSorted),
aggregatedGradients_(new float64[maxBins]),
aggregatedHessians_(new float64[triangularNumber(maxBins)]), binIndices_(new uint32[maxBins]),
numElementsPerBin_(new uint32[maxBins]), criteria_(new float64[labelIndices.getNumElements()]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ namespace boosting {
const Lapack& lapack)
: AbstractExampleWiseRuleEvaluation<DenseExampleWiseStatisticVector, IndexVector>(
labelIndices.getNumElements(), lapack),
scoreVector_(DenseScoreVector<IndexVector>(labelIndices, true)),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight),
blas_(blas), lapack_(lapack) {}
scoreVector_(labelIndices, true), l1RegularizationWeight_(l1RegularizationWeight),
l2RegularizationWeight_(l2RegularizationWeight), blas_(blas), lapack_(lapack) {}

/**
* @see `IRuleEvaluation::evaluate`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ namespace boosting {
const Lapack& lapack)
: AbstractExampleWiseRuleEvaluation<DenseExampleWiseStatisticVector, IndexVector>(
labelIndices.getNumElements(), lapack),
labelIndices_(labelIndices), indexVector_(PartialIndexVector(labelIndices.getNumElements())),
scoreVector_(DenseScoreVector<PartialIndexVector>(indexVector_, true)), threshold_(1.0 - threshold),
exponent_(exponent), l1RegularizationWeight_(l1RegularizationWeight),
l2RegularizationWeight_(l2RegularizationWeight), blas_(blas), lapack_(lapack) {}
labelIndices_(labelIndices), indexVector_(labelIndices.getNumElements()),
scoreVector_(indexVector_, true), threshold_(1.0 - threshold), exponent_(exponent),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight),
blas_(blas), lapack_(lapack) {}

/**
* @see `IRuleEvaluation::evaluate`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ namespace boosting {
const Blas& blas, const Lapack& lapack)
: AbstractExampleWiseRuleEvaluation<DenseExampleWiseStatisticVector, IndexVector>(numPredictions,
lapack),
labelIndices_(labelIndices), indexVector_(PartialIndexVector(numPredictions)),
scoreVector_(DenseScoreVector<PartialIndexVector>(indexVector_, false)),
labelIndices_(labelIndices), indexVector_(numPredictions), scoreVector_(indexVector_, false),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight),
blas_(blas), lapack_(lapack), tmpVector_(SparseArrayVector<float64>(labelIndices.getNumElements())) {}
blas_(blas), lapack_(lapack), tmpVector_(labelIndices.getNumElements()) {}

/**
* @see `IRuleEvaluation::evaluate`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace boosting {
*indexVectorPtr, false, maxBins, l1RegularizationWeight, l2RegularizationWeight,
std::move(binningPtr), blas, lapack),
labelIndices_(labelIndices), indexVectorPtr_(std::move(indexVectorPtr)),
tmpVector_(SparseArrayVector<float64>(labelIndices.getNumElements())) {}
tmpVector_(labelIndices.getNumElements()) {}
};

ExampleWiseFixedPartialBinnedRuleEvaluationFactory::ExampleWiseFixedPartialBinnedRuleEvaluationFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ namespace boosting {
float64 l1RegularizationWeight, float64 l2RegularizationWeight,
std::unique_ptr<ILabelBinning> binningPtr)
: maxBins_(binningPtr->getMaxBins(labelIndices.getNumElements())),
scoreVector_(DenseBinnedScoreVector<IndexVector>(labelIndices, maxBins_ + 1, indicesSorted)),
aggregatedStatisticVector_(DenseLabelWiseStatisticVector(maxBins_)),
scoreVector_(labelIndices, maxBins_ + 1, indicesSorted), aggregatedStatisticVector_(maxBins_),
numElementsPerBin_(new uint32[maxBins_]), criteria_(new float64[labelIndices.getNumElements()]),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight),
binningPtr_(std::move(binningPtr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace boosting {
*/
LabelWiseCompleteRuleEvaluation(const IndexVector& labelIndices, float64 l1RegularizationWeight,
float64 l2RegularizationWeight)
: scoreVector_(DenseScoreVector<IndexVector>(labelIndices, true)),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight) {}
: scoreVector_(labelIndices, true), l1RegularizationWeight_(l1RegularizationWeight),
l2RegularizationWeight_(l2RegularizationWeight) {}

const IScoreVector& calculateScores(StatisticVector& statisticVector) override {
uint32 numElements = statisticVector.getNumElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ namespace boosting {
*/
LabelWiseDynamicPartialRuleEvaluation(const IndexVector& labelIndices, float32 threshold, float32 exponent,
float64 l1RegularizationWeight, float64 l2RegularizationWeight)
: labelIndices_(labelIndices), indexVector_(PartialIndexVector(labelIndices.getNumElements())),
scoreVector_(DenseScoreVector<PartialIndexVector>(indexVector_, true)), threshold_(1.0 - threshold),
exponent_(exponent), l1RegularizationWeight_(l1RegularizationWeight),
l2RegularizationWeight_(l2RegularizationWeight) {}
: labelIndices_(labelIndices), indexVector_(labelIndices.getNumElements()),
scoreVector_(indexVector_, true), threshold_(1.0 - threshold), exponent_(exponent),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight) {}

const IScoreVector& calculateScores(StatisticVector& statisticVector) override {
uint32 numElements = statisticVector.getNumElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ namespace boosting {
*/
LabelWiseFixedPartialRuleEvaluation(const IndexVector& labelIndices, uint32 numPredictions,
float64 l1RegularizationWeight, float64 l2RegularizationWeight)
: labelIndices_(labelIndices), indexVector_(PartialIndexVector(numPredictions)),
scoreVector_(DenseScoreVector<PartialIndexVector>(indexVector_, false)),
: labelIndices_(labelIndices), indexVector_(numPredictions), scoreVector_(indexVector_, false),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight),
tmpVector_(SparseArrayVector<float64>(labelIndices.getNumElements())) {}
tmpVector_(labelIndices.getNumElements()) {}

const IScoreVector& calculateScores(StatisticVector& statisticVector) override {
uint32 numElements = statisticVector.getNumElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace boosting {
: AbstractLabelWiseBinnedRuleEvaluation<StatisticVector, PartialIndexVector>(
*indexVectorPtr, false, l1RegularizationWeight, l2RegularizationWeight, std::move(binningPtr)),
labelIndices_(labelIndices), indexVectorPtr_(std::move(indexVectorPtr)),
tmpVector_(SparseArrayVector<float64>(labelIndices.getNumElements())) {}
tmpVector_(labelIndices.getNumElements()) {}
};

LabelWiseFixedPartialBinnedRuleEvaluationFactory::LabelWiseFixedPartialBinnedRuleEvaluationFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace boosting {
*/
LabelWiseSingleLabelRuleEvaluation(const IndexVector& labelIndices, float64 l1RegularizationWeight,
float64 l2RegularizationWeight)
: labelIndices_(labelIndices), indexVector_(PartialIndexVector(1)),
scoreVector_(DenseScoreVector<PartialIndexVector>(indexVector_, true)),
: labelIndices_(labelIndices), indexVector_(1), scoreVector_(indexVector_, true),
l1RegularizationWeight_(l1RegularizationWeight), l2RegularizationWeight_(l2RegularizationWeight) {}

const IScoreVector& calculateScores(StatisticVector& statisticVector) override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace boosting {
ExampleWiseStatisticsSubset(const StatisticView& statisticView,
const RuleEvaluationFactory& ruleEvaluationFactory, const WeightVector& weights,
const IndexVector& labelIndices)
: sumVector_(StatisticVector(labelIndices.getNumElements(), true)), statisticView_(statisticView),
weights_(weights), labelIndices_(labelIndices),
: sumVector_(labelIndices.getNumElements(), true), statisticView_(statisticView), weights_(weights),
labelIndices_(labelIndices),
ruleEvaluationPtr_(ruleEvaluationFactory.create(sumVector_, labelIndices)) {}

/**
Expand Down Expand Up @@ -186,8 +186,7 @@ namespace boosting {
WeightVector, IndexVector>(statistics.statisticView_,
statistics.ruleEvaluationFactory_,
statistics.weights_, labelIndices),
tmpVector_(StatisticVector(labelIndices.getNumElements())), totalSumVector_(&totalSumVector) {
}
tmpVector_(labelIndices.getNumElements()), totalSumVector_(&totalSumVector) {}

/**
* @see `IWeightedStatisticsSubset::resetSubset`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ namespace boosting {
LabelWiseStatisticsSubset(const StatisticView& statisticView,
const RuleEvaluationFactory& ruleEvaluationFactory, const WeightVector& weights,
const IndexVector& labelIndices)
: sumVector_(StatisticVector(labelIndices.getNumElements(), true)), statisticView_(statisticView),
weights_(weights), labelIndices_(labelIndices),
: sumVector_(labelIndices.getNumElements(), true), statisticView_(statisticView), weights_(weights),
labelIndices_(labelIndices),
ruleEvaluationPtr_(ruleEvaluationFactory.create(sumVector_, labelIndices)) {}

/**
Expand Down Expand Up @@ -182,8 +182,7 @@ namespace boosting {
IndexVector>(statistics.statisticView_,
statistics.ruleEvaluationFactory_, statistics.weights_,
labelIndices),
tmpVector_(StatisticVector(labelIndices.getNumElements())), totalSumVector_(&totalSumVector) {
}
tmpVector_(labelIndices.getNumElements()), totalSumVector_(&totalSumVector) {}

/**
* @see `IWeightedStatisticsSubset::resetSubset`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "mlrl/common/statistics/statistics_weighted.hpp"

DenseBinIndexVector::DenseBinIndexVector(uint32 numElements) : vector_(DenseVector<uint32>(numElements)) {}
DenseBinIndexVector::DenseBinIndexVector(uint32 numElements) : vector_(numElements) {}

uint32 DenseBinIndexVector::getBinIndex(uint32 exampleIndex) const {
return vector_[exampleIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "mlrl/common/statistics/statistics_weighted.hpp"

DokBinIndexVector::DokBinIndexVector() : vector_(DokVector<uint32>(BIN_INDEX_SPARSE)) {}
DokBinIndexVector::DokBinIndexVector() : vector_(BIN_INDEX_SPARSE) {}

DokBinIndexVector::iterator DokBinIndexVector::begin() {
return vector_.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "mlrl/common/data/arrays.hpp"

BinWeightVector::BinWeightVector(uint32 numElements) : vector_(DenseVector<uint32>(numElements)) {}
BinWeightVector::BinWeightVector(uint32 numElements) : vector_(numElements) {}

void BinWeightVector::clear() {
setArrayToZeros(vector_.begin(), vector_.getNumElements());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ ThresholdVector::ThresholdVector(MissingFeatureVector& missingFeatureVector, uin
: ThresholdVector(missingFeatureVector, numElements, false) {}

ThresholdVector::ThresholdVector(MissingFeatureVector& missingFeatureVector, uint32 numElements, bool init)
: MissingFeatureVector(missingFeatureVector), vector_(DenseVector<float32>(numElements, init)),
sparseBinIndex_(numElements) {}
: MissingFeatureVector(missingFeatureVector), vector_(numElements, init), sparseBinIndex_(numElements) {}

ThresholdVector::iterator ThresholdVector::begin() {
return vector_.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void SparseSetMatrix<T>::Row::clear() {

template<typename T>
SparseSetMatrix<T>::SparseSetMatrix(uint32 numRows, uint32 numCols)
: lilMatrix_(LilMatrix<T>(numRows)), indexMatrix_(CContiguousMatrix<uint32>(numRows, numCols)) {
: lilMatrix_(numRows), indexMatrix_(numRows, numCols) {
setArrayToValue(indexMatrix_.values_begin(0), numRows * numCols, MAX_INDEX);
}

Expand Down
Loading
Loading