| 136 | } |
| 137 | |
| 138 | TVector<double> EvalMetricsForUtils( |
| 139 | TConstArrayRef<TVector<float>> label, // [dimensionIdx][objectIdx] |
| 140 | const TVector<TVector<double>>& approx, // [dimensionIdx][objectIdx] |
| 141 | const TString& metricName, |
| 142 | const TVector<float>& weight, |
| 143 | const TVector<TGroupId>& groupId, |
| 144 | const TVector<float>& groupWeight, |
| 145 | const TVector<TSubgroupId>& subgroupId, |
| 146 | const TVector<TPair>& pairs, |
| 147 | int threadCount |
| 148 | ) { |
| 149 | auto objectCount = label[0].size(); |
| 150 | CB_ENSURE(objectCount > 0, "Cannot evaluate metric on empty data"); |
| 151 | |
| 152 | CB_ENSURE(!IsGroupwiseMetric(metricName) || !groupId.empty(), "Metric \"" << metricName << "\" requires group data"); |
| 153 | |
| 154 | NPar::TLocalExecutor executor; |
| 155 | executor.RunAdditionalThreads(threadCount - 1); |
| 156 | const int approxDimension = approx.ysize(); |
| 157 | TVector<THolder<IMetric>> metrics = CreateMetricsFromDescription({metricName}, approxDimension); |
| 158 | if (!weight.empty()) { |
| 159 | for (auto& metric : metrics) { |
| 160 | metric->UseWeights.SetDefaultValue(true); |
| 161 | } |
| 162 | } |
| 163 | NCB::TObjectsGrouping objectGrouping = NCB::CreateObjectsGroupingFromGroupIds<TGroupId>( |
| 164 | objectCount, |
| 165 | groupId.empty() ? Nothing() : NCB::TMaybeData<TConstArrayRef<TGroupId>>(groupId) |
| 166 | ); |
| 167 | if (!pairs.empty()) { |
| 168 | NCB::CheckPairs(pairs, objectGrouping); |
| 169 | } |
| 170 | TVector<TQueryInfo> queriesInfo; |
| 171 | if (!groupId.empty()) { |
| 172 | queriesInfo = *NCB::MakeGroupInfos( |
| 173 | objectGrouping, |
| 174 | subgroupId.empty() ? Nothing() : NCB::TMaybeData<TConstArrayRef<TSubgroupId>>(subgroupId), |
| 175 | groupWeight.empty() ? NCB::TWeights(groupId.size()) : NCB::TWeights(TVector<float>(groupWeight)), |
| 176 | TConstArrayRef<TPair>(pairs) |
| 177 | ).Get(); |
| 178 | } |
| 179 | TVector<double> metricResults; |
| 180 | metricResults.reserve(metrics.size()); |
| 181 | |
| 182 | TVector<const IMetric*> metricPtrs; |
| 183 | metricPtrs.reserve(metrics.size()); |
| 184 | for (const auto& metric : metrics) { |
| 185 | metricPtrs.push_back(metric.Get()); |
| 186 | } |
| 187 | |
| 188 | auto stats = EvalErrorsWithCaching( |
| 189 | approx, |
| 190 | /*approxDelts*/{}, |
| 191 | /*isExpApprox*/false, |
| 192 | To2DConstArrayRef<float>(label), |
| 193 | weight, |
| 194 | queriesInfo, |
| 195 | metricPtrs, |
nothing calls this directly
no test coverage detected