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

Function ReadGroupWeights

catboost/libs/data/loader.cpp:88–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86 }
87
88 static TVector<float> ReadGroupWeights(
89 const TPathWithScheme& filePath,
90 TConstArrayRef<TGroupId> groupIds,
91 ui64 docCount,
92 TDatasetSubset loadSubset
93 ) {
94 Y_UNUSED(loadSubset);
95 CB_ENSURE(groupIds.size() == docCount, "GroupId count should correspond to object count.");
96 THolder<ILineDataReader> reader = GetLineDataReader(filePath);
97 TString line;
98 THashMap<TGroupId, float> groupWeightsByGroupId;
99 for (size_t lineNumber = 0; reader->ReadLine(&line); lineNumber++) {
100 try {
101 TVector<TString> tokens = StringSplitter(line).Split('\t');
102 CB_ENSURE(tokens.size() == 2,
103 "Each line should have two columns. This line has " << tokens.size()
104 );
105 const TGroupId groupId = CalcGroupIdFor(tokens[0]);
106 float groupWeight = 1.0f;
107 CB_ENSURE(
108 TryFromString(tokens[1], groupWeight),
109 "Invalid group weight: cannot parse as float (" << tokens[1] << ')'
110 );
111 CB_ENSURE(!groupWeightsByGroupId.contains(groupId), "GroupId at line " << lineNumber << " is repeated in group weights file");
112 groupWeightsByGroupId[groupId] = groupWeight;
113 } catch (const TCatBoostException& e) {
114 throw TCatBoostException() << "Incorrect file with group weights. Invalid line number #"
115 << lineNumber << ": " << e.what();
116 }
117 }
118 TVector<float> groupWeights;
119 groupWeights.reserve(docCount);
120 for (auto rowIdx : xrange(groupIds.size())) {
121 CB_ENSURE(groupWeightsByGroupId.contains(groupIds[rowIdx]), "GroupId from row " << rowIdx << " in dataset is not found in group weights file");
122 groupWeights.emplace_back(groupWeightsByGroupId.at(groupIds[rowIdx]));
123 }
124
125 return groupWeights;
126 }
127
128 static TVector<ui64> ReadGroupTimestamps(
129 const TPathWithScheme& filePath,

Callers 1

SetGroupWeightsFunction · 0.85

Calls 15

Y_UNUSEDFunction · 0.85
GetLineDataReaderFunction · 0.85
StringSplitterFunction · 0.85
CalcGroupIdForFunction · 0.85
TryFromStringFunction · 0.85
TCatBoostExceptionClass · 0.85
xrangeFunction · 0.85
sizeMethod · 0.45
ReadLineMethod · 0.45
SplitMethod · 0.45
containsMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected