当前位置: 首页>>代码示例>>C++>>正文


C++ TIntFltKdV类代码示例

本文整理汇总了C++中TIntFltKdV的典型用法代码示例。如果您正苦于以下问题:C++ TIntFltKdV类的具体用法?C++ TIntFltKdV怎么用?C++ TIntFltKdV使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TIntFltKdV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddPlot

int TGnuPlot::AddPlot(const TIntFltKdV& XYValV, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style) {
  TFltKdV XYFltValV(XYValV.Len(), 0);
  for (int i = 0; i < XYValV.Len(); i++) {
    XYFltValV.Add(TFltKd(TFlt(XYValV[i].Key), TFlt(XYValV[i].Dat)));
  }
  return AddPlot(XYFltValV, SeriesTy, Label, Style);
}
开发者ID:mkrnc,项目名称:snap,代码行数:7,代码来源:gnuplot.cpp

示例2: 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); }    
}
开发者ID:joaopitacosta,项目名称:qminer,代码行数:34,代码来源:ftrgen.cpp

示例3: ToStr

void TStrFeatureSpace::ToStr(const TIntFltKdV& FeatureIds, TChA& ChA, int k, char Sep) const {
	TIntSet TakenIndexes(k);
	int Len = TMath::Mn(FeatureIds.Len(), k);
	for (int i = 0; i < Len; i++) {
		double MxVal = TFlt::Mn;
		int MxIndex = 0;
		for (int j = 0; j < FeatureIds.Len(); j++) {
			const TIntFltKd& Feature = FeatureIds[j];
			if (Feature.Dat > MxVal) {
				if (!TakenIndexes.IsKey(Feature.Key)) {
					MxVal = Feature.Dat;
					MxIndex = Feature.Key;
				}
			}
		}
		TakenIndexes.AddKey(MxIndex);

		ChA += ISpace.KeyFromOfs(Space[MxIndex]);
		ChA += ':';
		ChA += TFlt::GetStr(MxVal, "%2.6f");
		if (i < Len) {
			ChA += Sep;
		}
	}
}
开发者ID:simp1eton,项目名称:snap-social,代码行数:25,代码来源:strftrspace.cpp

示例4: Normalize

void TGUtil::Normalize(TIntFltKdV& PdfV) {
  double Sum = 0.0;
  for (int i = 0; i < PdfV.Len(); i++) {
    Sum += PdfV[i].Dat; }
  if (Sum <= 0.0) { return; }
  for (int i = 0; i < PdfV.Len(); i++) {
    PdfV[i].Dat /= Sum; }
}
开发者ID:hmipakchi,项目名称:FinalYearProject,代码行数:8,代码来源:util.cpp

示例5: Explain

PJsonVal TNearestNeighbor::Explain(const TIntFltKdV& Vec) const {
    // if not initialized, return null (JSON)
    if (!IsInit()) { return TJsonVal::NewNull(); }
    // find nearest neighbor
    double NearDist = TFlt::Mx; int NearColN = -1;
    for (int ColN = 0; ColN < Mat.Len(); ColN++) {
        const double Dist = TLinAlg::Norm2(Vec) - 2 * TLinAlg::DotProduct(Vec, Mat[ColN]) + TLinAlg::Norm2(Mat[ColN]);
        if (Dist < NearDist) { NearDist = Dist; NearColN = ColN; }
    }
    const TIntFltKdV& NearVec = Mat[NearColN];
    // generate JSon explanations
    PJsonVal ResVal = TJsonVal::NewObj();
    // id of the nearest element
    ResVal->AddToObj("nearestDat", DatV[NearColN]);
    ResVal->AddToObj("distance", NearDist);
    // element-wise difference
    PJsonVal DiffVal = TJsonVal::NewArr();
    int NearEltN = 0, EltN = 0;
    while (NearEltN < NearVec.Len() || EltN < Vec.Len()) {
        // get the feature ID
        const int VecFtrId = EltN < Vec.Len() ? Vec[EltN].Key.Val : TInt::Mx;
        const int NearFtrId = NearEltN < NearVec.Len() ? NearVec[NearEltN].Key.Val : TInt::Mx;
        const int FtrId = NearFtrId < VecFtrId ? NearFtrId : VecFtrId;
        // get values
        const double VecVal = FtrId < VecFtrId ? 0.0 : Vec[EltN].Dat.Val;
        const double NearVal = FtrId < NearFtrId ? 0.0 : NearVec[NearEltN].Dat.Val;
        // get diff
        const double Diff = TMath::Sqr(NearVal - VecVal) / NearDist;
        // add to json result
        PJsonVal FtrVal = TJsonVal::NewObj();
        //avoid unnecessary fields in the explanation
        if (Diff > 1e-8) {
            FtrVal->AddToObj("id", FtrId);
            FtrVal->AddToObj("val", VecVal);
            FtrVal->AddToObj("nearVal", NearVal);
            FtrVal->AddToObj("contribution", Diff);
            DiffVal->AddToArr(FtrVal);
        }
        // move to the next feature
        if (VecFtrId <= NearFtrId) {
            EltN++;
        }
        if (NearFtrId <= VecFtrId) {
            NearEltN++;
        }
    }
    ResVal->AddToObj("features", DiffVal);
    // first and last record in the buffer
    ResVal->AddToObj("oldestDat", DatV[NextCol]);
    int CurCol = NextCol > 0 ? NextCol - 1 : WindowSize - 1;
    ResVal->AddToObj("newestDat", DatV[CurCol]);
    return ResVal;
}
开发者ID:gregorleban,项目名称:Qminer,代码行数:53,代码来源:anomaly.cpp

示例6: GenFtrV

void TFtrGenBs::AddBowDoc(const PBowDocBs& BowDocBs,
		const TStr& DocNm, const TStrV& FtrValV) const {

    TIntFltKdV FtrSpV; GenFtrV(FtrValV, FtrSpV);
    // make KdV to PrV
    const int WIds = FtrSpV.Len(); TIntFltPrV WIdWgtPrV(WIds, 0);
    for (int WIdN = 0; WIdN < WIds; WIdN++) {
        WIdWgtPrV.Add(TIntFltPr(FtrSpV[WIdN].Key, FtrSpV[WIdN].Dat));
    }
    // add the feature vector to trainsets
    BowDocBs->AddDoc(DocNm, TStrV(), WIdWgtPrV);
}
开发者ID:mkarlovc,项目名称:gcentralization,代码行数:12,代码来源:ftrgen.cpp

示例7: 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();
}
开发者ID:lstopar,项目名称:qminer,代码行数:12,代码来源:json.cpp

示例8: TokenStrV

void TBagOfWords::AddFtr(const TStr& Val, TIntFltKdV& SpV, int& Offset) const {
    // tokenize
    TStrV TokenStrV(Val.Len() / 5, 0); GetFtr(Val, TokenStrV);
    // create sparse vector
    TIntFltKdV ValSpV; AddFtr(TokenStrV, ValSpV);
    // add to the full feature vector and increase offset count
    for (int ValSpN = 0; ValSpN < ValSpV.Len(); ValSpN++) {
        const TIntFltKd& ValSp = ValSpV[ValSpN];
        SpV.Add(TIntFltKd(Offset + ValSp.Key, ValSp.Dat));
    }    
    // increase the offset by the dimension
    Offset += GetDim();
}
开发者ID:joaopitacosta,项目名称:qminer,代码行数:13,代码来源:ftrgen.cpp

示例9: CalcEffDiam

// interpolate effective diameter
double CalcEffDiam(const TIntFltKdV& DistNbrsCdfV, const double& Percentile) {
  const double EffPairs = Percentile * DistNbrsCdfV.Last().Dat;
  int ValN;
  for (ValN = 0; ValN < DistNbrsCdfV.Len(); ValN++) {
    if (DistNbrsCdfV[ValN].Dat() > EffPairs) {  break; }
  }
  if (ValN >= DistNbrsCdfV.Len()) return DistNbrsCdfV.Last().Key;
  if (ValN == 0) return 1;
  // interpolate
  const double DeltaNbrs = DistNbrsCdfV[ValN].Dat - DistNbrsCdfV[ValN-1].Dat;
  if (DeltaNbrs == 0) return DistNbrsCdfV[ValN].Key;
  return DistNbrsCdfV[ValN-1].Key + (EffPairs - DistNbrsCdfV[ValN-1].Dat)/DeltaNbrs;
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:14,代码来源:anf.cpp

示例10: GetTokenV

void TFtrGenToken::Add(const TStr& Val, TIntFltKdV& SpV, int& Offset) const {
    // step (1): tokenize
    TStrV TokenStrV; GetTokenV(Val, TokenStrV);
    // step (2): aggregate token counts
    TIntH TokenFqH;
    for (int TokenStrN = 0; TokenStrN < TokenStrV.Len(); TokenStrN++) {
        const TStr& TokenStr = TokenStrV[TokenStrN];
        if (TokenH.IsKey(TokenStr)) { 
            const int TokenId = TokenH.GetKeyId(TokenStr);
            TokenFqH.AddDat(TokenId)++;
        }
    }
    // step (3): make a sparse vector out of it
    TIntFltKdV ValSpV(TokenFqH.Len(), 0);
    int KeyId = TokenFqH.FFirstKeyId();
    while (TokenFqH.FNextKeyId(KeyId)) {
        const int TokenId = TokenFqH.GetKey(KeyId);
        const int TokenFq = TokenFqH[KeyId];
        const int TokenDocFq = TokenH[TokenId];
        const double IDF = log(double(Docs) / double(TokenDocFq));
        ValSpV.Add(TIntFltKd(TokenId, double(TokenFq) * IDF));
    }
    ValSpV.Sort(); TLinAlg::NormalizeL1(ValSpV);
    // step (4): add the sparse vector to the final feature vector  
    for (int ValSpN = 0; ValSpN < ValSpV.Len(); ValSpN++) {
        const int Key = ValSpV[ValSpN].Key + Offset;
        const double Dat = ValSpV[ValSpN].Dat;
        SpV.Add(TIntFltKd(Key, Dat));
    }
    Offset += TokenH.Len(); 
}
开发者ID:mkarlovc,项目名称:gcentralization,代码行数:31,代码来源:ftrgen.cpp

示例11: Add

void TFtrGenNumeric::Add(
        const TStr& Val, TIntFltKdV& SpV, int& Offset) const {

    double Flt = GetFlt(Val);
    SpV.Add(TIntFltKd(Offset, Trans(Flt))); 
    Offset++; 
}
开发者ID:mkarlovc,项目名称:gcentralization,代码行数:7,代码来源:ftrgen.cpp

示例12: SaveTs

void TGnuPlot::SaveTs(const TIntFltKdV& KdV, const TStr& FNm, const TStr& HeadLn) {
  FILE *F = fopen(FNm.CStr(), "wt");
  EAssert(F);
  if (! HeadLn.Empty()) fprintf(F, "# %s\n", HeadLn.CStr());
  for (int i = 0; i < KdV.Len(); i++)
    fprintf(F, "%d\t%g\n", KdV[i].Key(), KdV[i].Dat());
  fclose(F);
}
开发者ID:mkrnc,项目名称:snap,代码行数:8,代码来源:gnuplot.cpp

示例13: CalcAvgDiamPdf

double CalcAvgDiamPdf(const TIntFltKdV& DistNbrsPdfV) {
  double Paths=0, SumLen=0;
  for (int i = 0; i < DistNbrsPdfV.Len(); i++) {
    SumLen += DistNbrsPdfV[i].Key * DistNbrsPdfV[i].Dat;
    Paths += DistNbrsPdfV[i].Dat;
  }
  return SumLen/Paths;
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:8,代码来源:anf.cpp

示例14: 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();
}
开发者ID:simp1eton,项目名称:snap-social,代码行数:18,代码来源:strftrspace.cpp

示例15: GetCfy

///////////////////////////////////////////////////////////////////////
// Logistic-Regression-Model
double TLogRegMd::GetCfy(const TIntFltKdV& AttrV) {
    int len = AttrV.Len();
    double res = bb.Last();
    for (int i = 0; i < len; i++) {
        if (AttrV[i].Key < bb.Len())
            res += AttrV[i].Dat * bb[AttrV[i].Key];
    }
    double mu = 1/(1 + exp(-res));
    return mu;
}
开发者ID:Accio,项目名称:snap,代码行数:12,代码来源:logreg.cpp


注:本文中的TIntFltKdV类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。