本文整理汇总了C++中TIntFltKdV::Sort方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntFltKdV::Sort方法的具体用法?C++ TIntFltKdV::Sort怎么用?C++ TIntFltKdV::Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntFltKdV
的用法示例。
在下文中一共展示了TIntFltKdV::Sort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddFtr
void TMultinomial::AddFtr(const TStrV& StrV, const TFltV& FltV, TIntFltKdV& SpV) const {
// make sure we either do not have explicit values, or their dimension matches with string keys
EAssertR(FltV.Empty() || (StrV.Len() == FltV.Len()), "TMultinomial::AddFtr:: String and double values not aligned");
// generate internal feature vector
SpV.Gen(StrV.Len(), 0);
for (int StrN = 0; StrN < StrV.Len(); StrN++) {
const int FtrId = FtrGen.GetFtr(StrV[StrN]);
// only use features we've seen during updates
if (FtrId != -1) {
const double Val = FltV.Empty() ? 1.0 : FltV[StrN].Val;
if (Val > 1e-16) { SpV.Add(TIntFltKd(FtrId, Val)); }
}
}
SpV.Sort();
// merge elements with the same id
int GoodSpN = 0;
for (int SpN = 1; SpN < SpV.Len(); SpN++) {
if (SpV[GoodSpN].Key == SpV[SpN].Key) {
// repetition of previous id, sum counts
SpV[GoodSpN].Dat += SpV[SpN].Dat;
} else {
// increase the pointer to the next good position
GoodSpN++;
// and move the new value down to the good position
SpV[GoodSpN] = SpV[SpN];
}
}
// truncate the vector
SpV.Trunc(GoodSpN + 1);
// replace values with 1 if needed
if (IsBinary()) { for (TIntFltKd& Sp : SpV) { Sp.Dat = 1.0; } }
// final normalization, if needed
if (IsNormalize()) { TLinAlg::Normalize(SpV); }
}
示例2: GetArrNumSpV
void TJsonVal::GetArrNumSpV(TIntFltKdV& NumSpV) const {
EAssert(IsArr());
for (int ElN = 0; ElN < GetArrVals(); ElN++) {
PJsonVal ArrVal = GetArrVal(ElN);
EAssert(ArrVal->IsArr());
EAssert(ArrVal->GetArrVals() == 2);
int Idx = ArrVal->GetArrVal(0)->GetInt();
double Val = ArrVal->GetArrVal(1)->GetNum();
NumSpV.Add(TIntFltKd(Idx, Val));
}
NumSpV.Sort();
}
示例3: FromAddStr
void TStrFeatureSpace::FromAddStr(const TStr& Serialized, TIntFltKdV& Vec, char Sep) {
TStrV Toks;
Serialized.SplitOnAllCh(Sep, Toks, true);
Vec.Gen(Toks.Len());
for (int i = 0; i < Toks.Len(); i++) {
TStr Key, Value;
Toks[i].SplitOnCh(Key, ':', Value);
int FeatureId = GetAddId(Key);
double FeatureWgt;
if (Value.IsFlt(FeatureWgt)) {
Vec[i].Key = FeatureId;
Vec[i].Dat = FeatureWgt;
} else {
EFailR((Value + TStr(" is not a valid floating point number.")).CStr());
}
}
Vec.Sort();
}
示例4: FromStr
void TStrFeatureSpace::FromStr(const TStr& Serialized, TIntFltKdV& Vec, char Sep) const {
TStrV Toks;
Serialized.SplitOnAllCh(Sep, Toks, true);
Vec.Gen(Toks.Len(),0);
for (int i = 0; i < Toks.Len(); i++) {
TStr Key, Value;
Toks[i].SplitOnCh(Key, ':', Value);
TStrFSSize FeatureId;
if (GetIfExistsId(Key, FeatureId)) {
double FeatureWgt;
if (Value.IsFlt(FeatureWgt)) {
TIntFltKd& Kv = Vec[Vec.Add()];
Kv.Key = FeatureId;
Kv.Dat = FeatureWgt;
} else {
EFailR((Value + TStr(" is not a valid floating point number.")).CStr());
}
}
}
Vec.Sort();
}