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


C++ TIntFltKdV::Add方法代码示例

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


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

示例1: Add

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

示例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: 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

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

示例5: Update

void TEmaSpVec::Update(const TIntFltKdV& Val, const uint64& NewTmMSecs) {
	double TmInterval1;
	// EMA(first_point) = first_point (no smoothing is possible)
	if (InitMinMSecs == 0) {
		if (LastVal.Empty()) { 
			LastVal = Val; 
			Ema = Val; 
			TmMSecs = NewTmMSecs; 
			InitP = true;  
			return; 
		}
	}
	if (NewTmMSecs == TmMSecs) {
		TmInterval1 = 1.0;
	} else {
		TmInterval1 = (double)(NewTmMSecs - TmMSecs);
	}
	if (InitP) {
		// compute parameters for EMA
		double Alpha = TmInterval1 / TmInterval;
		const double Mi = exp(-Alpha);
		const double Ni = GetNi(Alpha, Mi);
		// compute new ema
		//Ema = Mi*Ema + (Ni - Mi)*LastVal + (1.0 - Ni)*Val;
		TIntFltKdV Tmp;
		TLinAlg::LinComb(Mi, Ema, Ni - Mi, LastVal, Tmp);		
		TLinAlg::LinComb(1, Tmp, 1.0 - Ni, Val, Ema);
	} else {
		// update buffers
		InitValV.Add(Val);
		InitMSecsV.Add(NewTmMSecs);
		// initialize when enough data
		const uint64 StartInitMSecs = InitMSecsV[0] + InitMinMSecs;
		if (StartInitMSecs < NewTmMSecs) {
			// Initialize using "buildup time interval",
			//TODO: check how interpolation type influences this code
			const int Vals = InitMSecsV.Len();
			// compute weights for each value in buffer
			TFltV WeightV(Vals, 0);
			for (int ValN = 0; ValN < Vals; ValN++) {
				const double Alpha = (double)(TmInterval1);
				WeightV.Add(exp(-Alpha));
			}
			// normalize weights so they sum to 1.0
			TLinAlg::NormalizeL1(WeightV);
			// compute initial value of EMA as weighted sum
			//Ema = TLinAlg::DotProduct(WeightV, InitValV);
			TIntFltKdV Tmp;
			for (int i = 0; i < WeightV.Len(); i++) {
				TIntFltKdV Tmp2;
				TLinAlg::LinComb(1, Tmp, WeightV[i], InitValV[i], Tmp2);
				Tmp = Tmp2;
			}
			Ema = Tmp;

			// mark that we are done and clean up after us
			InitP = true; 
			InitValV.Clr();
			InitMSecsV.Clr();
		}
	}
	// remove dimensions bellow cutoff
	TIntFltKdV TmpEma;
	//printf("cutoff %f\n", Cutoff.Val);
	for (int i = 0; i < Ema.Len(); i++) {
		if (TFlt::Abs(Ema[i].Dat.Val) >= Cutoff) {
			TmpEma.Add(Ema[i]);
		}
	}
	Ema = TmpEma;

	// update last value
	LastVal = Val;
	// update current time
	TmMSecs = NewTmMSecs;
}
开发者ID:amrsobhy,项目名称:qminer,代码行数:76,代码来源:signalproc.cpp


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