static TVector<TVector<double>> CalcShapValuesForDocumentBlock(const TFullModel& model, const TPool& pool, size_t start, size_t end, NPar::TLocalExecutor& localExecutor, int dimension) { CB_ENSURE(!HasComplexCtrs(model.ObliviousTrees), "Model uses complex Ctr features. This is not allowed for SHAP values calculation"); const TObliviousTrees& forest = model.ObliviousTrees; const size_t documentCount = end - start; TVector<ui8> allBinarizedFeatures = BinarizeFeatures(model, pool, start, end); TVector<TVector<ui8>> binarizedFeaturesByDocument = TransposeBinarizedFeatures(allBinarizedFeatures, documentCount); allBinarizedFeatures.clear(); const int flatFeatureCount = pool.Docs.GetFactorsCount(); TVector<int> binFeaturesMapping = MapFeatures(forest); TVector<TVector<double>> shapValues(documentCount, TVector<double>(flatFeatureCount + 1, 0.0)); NPar::TLocalExecutor::TExecRangeParams blockParams(0, documentCount); localExecutor.ExecRange([&] (int documentIdx) { const size_t treeCount = forest.GetTreeCount(); for (size_t treeIdx = 0; treeIdx < treeCount; ++treeIdx) { TVector<TVector<size_t>> subtreeSizes = CalcSubtreeSizesForTree(forest, treeIdx); TVector<TFeaturePathElement> initialFeaturePath; CalcShapValuesRecursive(forest, binFeaturesMapping, binarizedFeaturesByDocument[documentIdx], treeIdx, /*depth*/ 0, subtreeSizes, dimension, /*nodeIdx*/ 0, initialFeaturePath, /*zeroPathFraction*/ 1, /*onePathFraction*/ 1, /*feature*/ -1, &shapValues[documentIdx]); shapValues[documentIdx][flatFeatureCount] += CalcMeanValueForTree(forest, subtreeSizes, treeIdx, dimension); } }, blockParams, NPar::TLocalExecutor::WAIT_COMPLETE); return shapValues; }
void TestDriveUnlimited(){ { TVector<A> uber; A a; A b(a); uber.resize(18); uber.push_back(a); uber.reserve(32); uber.resize(4); uber.push_back(b); uber.pop_back(); uber.clear(); } cout << ((A::creat==0)?"All fine":"Red alert") << endl; system("pause"); }
int main() { TVector<int> A; A.PrintStat(); for (int i = 0; i < 35; ++i) A.push_back(i); A.PrintStat(); for (int i = 0; i < 5; ++i) cout << " Pop: " << A.pop_back(); cout << endl; A.PrintStat(); A.swap(5,6); A.PrintStat(); TVector<int> B = A; B.PrintStat(); A.clear(); A.PrintStat(); return 0; }
void clear() final { m_vector.clear(); m_vector.shrink_to_fit(); }
void clear() override final { m_vector.clear(); m_vector.shrink_to_fit(); }