ComputeStats for Logloss and CrossEntropy correctly
@@ -83,19 +83,21 @@ namespace NCatboostCuda {
using TParent::GetTarget;
using TParent::GetTotalWeight;
- TAdditiveStatistic ComputeStats(const TConstVec& point, double alpha) const {
- TVector<float> result;
+ TAdditiveStatistic ComputeStats(const TConstVec& point,
+ const TMap<TString, TString>& params) const {
auto tmp = TVec::Create(point.GetMapping().RepeatOnAllDevices(1));
- ApproximatePointwise(GetTarget().GetTargets(),
+ Approximate(GetTarget().GetTargets(),
GetTarget().GetWeights(),
point,
- Type,
- alpha,
+ NCatboostOptions::GetAlpha(params),
+ UseBorder(),
+ GetBorder(),
&tmp,
- (TVec*)nullptr,
- (TVec*)nullptr);
-
+ /*der*/nullptr,
+ /*der2Row*/0,
+ /*der2*/nullptr);
+ TVector<float> result;
NCudaLib::TCudaBufferReader<TVec>(tmp)
.SetFactorSlice(TSlice(0, 1))
.SetReadSlice(TSlice(0, 1))
@@ -107,15 +109,6 @@ namespace NCatboostCuda {
return MakeSimpleAdditiveStatistic(result[0] * multiplier, weight);
}
- TAdditiveStatistic ComputeStats(const TConstVec& point) const {
- return ComputeStats(point, Alpha);
- }
-
- TAdditiveStatistic ComputeStats(const TConstVec& point,
- const TMap<TString, TString>& params) const {
- return ComputeStats(point, NCatboostOptions::GetAlpha(params));
- }
-
void GradientAt(const TConstVec& point,
TVec& weightedDer,
TVec& weightedDer2,
@@ -153,35 +146,18 @@ namespace NCatboostCuda {
ui32 der2Row,
TVec* der2,
ui32 stream = 0) const {
- CB_ENSURE(der2Row == 0);
-
- switch (Type) {
- case ELossFunction::CrossEntropy:
- case ELossFunction::Logloss: {
- ApproximateCrossEntropy(target,
+ Approximate(
+ target,
weights,
point,
- value,
- der,
- der2,
+ GetAlpha(),
UseBorder(),
GetBorder(),
- stream);
- break;
- }
- default: {
- ApproximatePointwise(target,
- weights,
- point,
- Type,
- Alpha,
value,
der,
+ der2Row,
der2,
stream);
- break;
- }
- }
}
void StochasticDer(const TConstVec& point,
@@ -306,6 +282,48 @@ namespace NCatboostCuda {
return Type == ELossFunction::Logloss;
}
+ void Approximate(const TConstVec& target,
+ const TConstVec& weights,
+ const TConstVec& point,
+ double alpha,
+ bool useBorder,
+ double border,
+ TVec* value,
+ TVec* der,
+ ui32 der2Row,
+ TVec* der2,
+ ui32 stream = 0) const {
+ CB_ENSURE(der2Row == 0);
+
+ switch (Type) {
+ case ELossFunction::CrossEntropy:
+ case ELossFunction::Logloss: {
+ ApproximateCrossEntropy(target,
+ weights,
+ point,
+ value,
+ der,
+ der2,
+ useBorder,
+ border,
+ stream);
+ break;
+ }
+ default: {
+ ApproximatePointwise(target,
+ weights,
+ point,
+ Type,
+ alpha,
+ value,
+ der,
+ der2,
+ stream);
+ break;
+ }
+ }
+ }
+
private:
ELossFunction Type = ELossFunction::PythonUserDefinedPerObject;
double Alpha = 0;
