MCPcopy Create free account
hub / github.com/catboost/catboost / EstimateGroupSize

Method EstimateGroupSize

catboost/private/libs/quantized_pool/serialization.cpp:806–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

804}
805
806void NCB::EstimateGroupSize(
807 const TStringBuf path,
808 double* groupSize,
809 double* sqrGroupSize,
810 size_t* maxGroupSize
811) {
812 const auto file = TBlob::FromFile(TString(path));
813 const TConstArrayRef<ui8> blob(file.AsUnsignedCharPtr(), file.Size());
814
815 TPoolMetainfo poolMetainfo;
816 auto parseMetainfo = [&] (TConstArrayRef<ui8> bytes) {
817 const auto poolMetainfoParsed = poolMetainfo.ParseFromArray(bytes.data(), bytes.size());
818 CB_ENSURE(poolMetainfoParsed);
819 };
820 auto onColumn = [&] (ui32 columnIndex) -> bool {
821 const auto hasType = poolMetainfo.GetColumnIndexToType().count(columnIndex);
822 return hasType && poolMetainfo.GetColumnIndexToType().at(columnIndex) == NCB::NIdl::CT_GROUP_ID;
823 };
824 ui64 groupCount = 0;
825 ui64 sumSqrGroupSize = 0;
826 size_t thisGroupSize = 1;
827 ui64 docCount = 0;
828 *maxGroupSize = 1;
829 auto onChunk = [&] (TConstArrayRef<ui8> bytes, ui32 docOffset, ui32 docsInChunkCount) {
830 if (docOffset > 0) {
831 return;
832 }
833 const auto* const chunk = flatbuffers::GetRoot<NCB::NIdl::TQuantizedFeatureChunk>(bytes.data());
834 CB_ENSURE(chunk->BitsPerDocument() == sizeof(ui64) * 8, "Group ids should be 64-bits");
835 const ui64* groupIds = reinterpret_cast<const ui64*>(chunk->Quants()->data());
836 for (auto idx : xrange((ui32)1, docsInChunkCount)) {
837 thisGroupSize += 1;
838 if (groupIds[idx - 1] != groupIds[idx]) {
839 groupCount += 1;
840 sumSqrGroupSize += Sqr(thisGroupSize);
841 *maxGroupSize = Max(*maxGroupSize, thisGroupSize);
842 thisGroupSize = 1;
843 }
844 }
845 docCount += docsInChunkCount;
846 };
847 ParseQuantizedPool(
848 parseMetainfo,
849 /*parseSchema*/ Nothing(),
850 onColumn,
851 onChunk,
852 blob);
853 *groupSize = groupCount ? static_cast<double>(docCount) / groupCount : 1;
854 *sqrGroupSize = groupCount ? static_cast<double>(sumSqrGroupSize) / groupCount : 1;
855}
856
857NCB::NIdl::TPoolMetainfo NCB::LoadPoolMetainfo(const TStringBuf path) {
858 const auto file = TBlob::FromFile(TString(path));

Callers

nothing calls this directly

Calls 12

xrangeFunction · 0.85
ParseQuantizedPoolFunction · 0.85
NothingFunction · 0.85
AsUnsignedCharPtrMethod · 0.80
SqrFunction · 0.50
MaxFunction · 0.50
SizeMethod · 0.45
ParseFromArrayMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected