本文整理汇总了C++中TFltV类的典型用法代码示例。如果您正苦于以下问题:C++ TFltV类的具体用法?C++ TFltV怎么用?C++ TFltV使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TFltV类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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); }
}
开发者ID:joaopitacosta,项目名称:qminer,代码行数:34,代码来源:ftrgen.cpp
示例2: Correct
TFltV KalmanFilter::Correct(TFltV measurement) {
// temp2 = H * P'(k)
TLinAlg::Multiply(measurementMatrix, errorCovPre, temp2VV);
// temp3 = temp2 * Ht + R
TLinAlg::Gemm(1.0, temp2VV, measurementMatrix, 1.0, measurementNoiseCov, temp3VV, TLinAlg::GEMM_B_T);
// temp4 = inv(temp3) * temp2 = Kt(k)
TLinAlg::Inverse(temp3VV, itemp3VV, TLinAlg::DECOMP_SVD);
TLinAlg::Multiply(itemp3VV, temp2VV, temp4VV);
// K(k)
TLinAlg::Transpose(temp4VV, gain);
// temp2V = z(k) - H*x'(k)
temp1V.Gen(1, 1);
TLinAlg::Multiply(measurementMatrix, statePre, temp1V);
temp2V.Gen(measurement.Len(), measurement.Len());
TLinAlg::AddVec(-1.0, temp1V, measurement, temp2V);
// x(k) = x'(k) + K(k) * temp2V
temp1V.Gen(gain.GetRows(), gain.GetRows());
TLinAlg::Multiply(gain, temp2V, temp1V);
TLinAlg::AddVec(1.0, statePre, temp1V, statePost);
// P(k) = P'(k) - K(k) * temp2
TLinAlg::Gemm(-1.0, gain, temp2VV, 1.0, errorCovPre, errorCovPost, TLinAlg::GEMM_NO_T);
// return statePost
return statePost;
}
开发者ID:klemenkenda,项目名称:NRG4Cast,代码行数:31,代码来源:kalman.cpp
示例3: GetEigVec
// to get first few eigenvectors
void GetEigVec(const PUNGraph& Graph, const int& EigVecs, TFltV& EigValV, TVec<TFltV>& EigVecV) {
const int Nodes = Graph->GetNodes();
// Lanczos
TUNGraphMtx GraphMtx(Graph);
int CalcVals = int(2*EigVecs);
if (CalcVals > Nodes) { CalcVals = Nodes; }
TFltVV EigVecVV;
//while (EigValV.Len() < EigVecs && CalcVals < 10*EigVecs) {
try {
TSparseSVD::Lanczos(GraphMtx, EigVecs, 2*EigVecs, ssotFull, EigValV, EigVecVV, false); }
catch(...) {
printf("\n ***EXCEPTION: TRIED %d GOT %d values** \n", CalcVals, EigValV.Len()); }
if (EigValV.Len() < EigVecs) {
printf(" ***TRIED %d GOT %d values** \n", CalcVals, EigValV.Len()); }
// CalcVals += EigVecs;
//}
TFltIntPrV EigValIdV;
for (int i = 0; i < EigValV.Len(); i++) {
EigValIdV.Add(TFltIntPr(EigValV[i], i));
}
EigValIdV.Sort(false);
EigValV.Sort(false);
for (int v = 0; v < EigValIdV.Len(); v++) { // vector components are not sorted!!!
EigVecV.Add();
EigVecVV.GetCol(EigValIdV[v].Val2, EigVecV.Last());
}
IsAllValVNeg(EigVecV[0], true);
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:29,代码来源:gsvd.cpp
示例4: Update
/////////////////////////////////////////////////
// Online Moving Standard M2
void TVar::Update(const double& InVal, const uint64& InTmMSecs,
const TFltV& OutValV, const TUInt64V& OutTmMSecsV, const int& N) {
pNo = N;
int tempN = N - 1 + OutValV.Len();
double delta;
// check if all the values are removed
if (OutValV.Len() >= tempN) {
Ma = 0;
M2 = 0;
tempN = 0;
} else {
// remove old values from the mean
for (int ValN = 0; ValN < OutValV.Len(); ValN++)
{
tempN--;
delta = OutValV[ValN] - Ma;
Ma = Ma - delta / tempN;
M2 = M2 - delta * (OutValV[ValN] - Ma);
}
}
//add the new value to the resulting mean
delta = InVal - Ma;
Ma = Ma + delta/N;
M2 = M2 + delta * (InVal - Ma);
TmMSecs = InTmMSecs;
}
开发者ID:amrsobhy,项目名称:qminer,代码行数:31,代码来源:signalproc.cpp
示例5: TEST
TEST(TSlottedHistogramTest, Simple2) {
try {
TQm::TStreamAggrs::PSlottedHistogram obj = TQm::TStreamAggrs::TSlottedHistogram::New(20, 5, 3);
obj->Add(1, 0); // slot 0
obj->Add(7, 0); // slot 1
obj->Add(12, 1); // slot 2
obj->Add(18, 0); // slot 3
obj->Add(22, 1); // slot 0
obj->Add(38, 0); // slot 3
TFltV Stats;
obj->GetStats(41, 45, Stats); // slots from 0 to 1 inclusive
ASSERT_EQ(Stats.Len(), 3);
ASSERT_EQ(Stats[0], 2.0);
ASSERT_EQ(Stats[1], 1.0);
ASSERT_EQ(Stats[2], 0.0);
obj->GetStats(45, 47, Stats); // slots from 1 to 1 inclusive
ASSERT_EQ(Stats.Len(), 3);
ASSERT_EQ(Stats[0], 1.0);
ASSERT_EQ(Stats[1], 0.0);
ASSERT_EQ(Stats[2], 0.0);
} catch (PExcept& Except) {
printf("Error: %s", Except->GetStr());
throw Except;
}
}
开发者ID:gitter-badger,项目名称:qminer,代码行数:31,代码来源:test-aggr.cpp
示例6: GetResults
void TNNet::GetResults(TFltV& ResultV) const{
ResultV.Clr(true, -1);
for(int NeuronN = 0; NeuronN < LayerV.Last().GetNeuronN() - 1; ++NeuronN){
ResultV.Add(LayerV.Last().GetOutVal(NeuronN));
}
}
开发者ID:amrsobhy,项目名称:qminer,代码行数:7,代码来源:signalproc.cpp
示例7: main
int main() {
TLSHash LSH(7, 7, DIM, TLSHash::EUCLIDEAN);
LSH.Init();
TRnd Gen;
Gen.Randomize();
TVec<TFltV> DataV;
for (int i=0; i<1000000; i++) {
TFltV Datum;
for (int j=0; j<3; j++) {
Datum.Add(Gen.GetUniDev()*2100);
}
DataV.Add(Datum);
}
LSH.AddV(DataV);
TVec<TPair<TFltV, TFltV> > NeighborsV = LSH.GetAllCandidatePairs();
printf("Number of Candidates: %d\n", NeighborsV.Len());
NeighborsV = LSH.GetAllNearPairs();
printf("Number of Close Pairs: %d\n", NeighborsV.Len());
for (int i=0; i<NeighborsV.Len(); i++) {
outputPoint(NeighborsV[i].GetVal1());
printf(" ");
outputPoint(NeighborsV[i].GetVal2());
printf("\n");
}
return 0;
}
开发者ID:BestSean2016,项目名称:snap,代码行数:30,代码来源:lshtest.cpp
示例8: ToStr
void TStrFeatureSpace::ToStr(const TFltV& 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 TFlt& FeatureVal = FeatureIds[j];
if (FeatureVal > MxVal) {
if (!TakenIndexes.IsKey(j)) {
MxVal = FeatureVal;
MxIndex = j;
}
}
}
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
示例9: GetEigVals
void GetEigVals(const PUNGraph& Graph, const int& EigVals, TFltV& EigValV) {
// Lanczos
TUNGraphMtx GraphMtx(Graph);
//const int Nodes = Graph->GetNodes();
//int CalcVals = int(2*EigVals);
//if (CalcVals > Nodes) { CalcVals = Nodes; }
//while (EigValV.Len() < EigVals && CalcVals < 3*EigVals) {
try {
if (EigVals > 4) {
TSparseSVD::SimpleLanczos(GraphMtx, 2*EigVals, EigValV, false); }
else { TFltVV EigVecVV; // this is much more precise, but also much slower
TSparseSVD::Lanczos(GraphMtx, EigVals, 3*EigVals, ssotFull, EigValV, EigVecVV, false); }
}
catch(...) {
printf("\n ***EXCEPTION: TRIED %d GOT %d values** \n", 2*EigVals, EigValV.Len()); }
if (EigValV.Len() < EigVals) {
printf(" ***TRIED %d GOT %d values** \n", 2*EigVals, EigValV.Len()); }
// CalcVals += EigVals;
//}
EigValV.Sort(false);
/*if (EigValV.Len() > EigVals) {
EigValV.Del(EigVals, EigValV.Len()-1); }
else {
while (EigValV.Len() < EigVals) EigValV.Add(1e-6);
}
IAssert(EigValV.Len() == EigVals);*/
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:27,代码来源:gsvd.cpp
示例10: Likelihood
double TAGMFit::Likelihood(const TFltV& NewLambdaV, double& LEdges, double& LNoEdges) {
IAssert(CIDNSetV.Len() == NewLambdaV.Len());
IAssert(ComEdgesV.Len() == CIDNSetV.Len());
LEdges = 0.0; LNoEdges = 0.0;
for (int e = 0; e < EdgeComVH.Len(); e++) {
TIntSet& JointCom = EdgeComVH[e];
double LambdaSum = SelectLambdaSum(NewLambdaV, JointCom);
double Puv = 1 - exp(- LambdaSum);
if (JointCom.Len() == 0) { Puv = PNoCom; }
IAssert(! _isnan(log(Puv)));
LEdges += log(Puv);
}
for (int k = 0; k < NewLambdaV.Len(); k++) {
int MaxEk = CIDNSetV[k].Len() * (CIDNSetV[k].Len() - 1) / 2;
int NotEdgesInCom = MaxEk - ComEdgesV[k];
if(NotEdgesInCom > 0) {
if (LNoEdges >= TFlt::Mn + double(NotEdgesInCom) * NewLambdaV[k]) {
LNoEdges -= double(NotEdgesInCom) * NewLambdaV[k];
}
}
}
double LReg = 0.0;
if (RegCoef > 0.0) {
LReg = - RegCoef * TLinAlg::SumVec(NewLambdaV);
}
return LEdges + LNoEdges + LReg;
}
开发者ID:RoyZhengGao,项目名称:CommunityEvaluation,代码行数:27,代码来源:agmfit.cpp
示例11: TestEigSvd
void TestEigSvd() {
PNGraph G = TSnap::GenRndGnm<PNGraph>(100,1000, true);
PUNGraph UG = TSnap::ConvertGraph<PUNGraph>(G);
TSnap::SaveMatlabSparseMtx(G, "test1.mtx");
TSnap::SaveMatlabSparseMtx(UG, "test2.mtx");
TFltV SngValV; TVec<TFltV> LeftV, RightV;
TSnap::GetSngVec(G, 20, SngValV, LeftV, RightV);
printf("Singular Values:\n");
for (int i =0; i < SngValV.Len(); i++) {
printf("%d\t%f\n", i, SngValV[i]()); }
printf("LEFT Singular Vectors:\n");
for (int i=0; i < LeftV[0].Len(); i++) {
printf("%d\t%f\t%f\t%f\t%f\t%f\n", i, LeftV[0][i](), LeftV[1][i](), LeftV[2][i](), LeftV[3][i](), LeftV[4][i]());
}
printf("RIGHT Singular Vectors:\n");
for (int i=0; i < RightV[0].Len(); i++) {
printf("%d\t%f\t%f\t%f\t%f\t%f\n", i, RightV[0][i](), RightV[1][i](), RightV[2][i](), RightV[3][i](), RightV[4][i]());
}
TFltV EigValV;
TVec<TFltV> EigV;
TSnap::GetEigVec(UG, 20, EigValV, EigV);
printf("Eigen Values:\n");
for (int i =0; i < EigValV.Len(); i++) {
printf("%d\t%f\n", i, EigValV[i]()); }
printf("Eigen Vectors %d:\n", EigV.Len());
for (int i =0; i < EigV[0].Len(); i++) {
printf("%d\t%f\t%f\t%f\t%f\t%f\n", i, EigV[0][i](), EigV[1][i](), EigV[2][i](), EigV[3][i](), EigV[4][i]());
}
}
开发者ID:margotduek,项目名称:AnalisisDisenioDeAlgoritmos,代码行数:32,代码来源:testgraph.cpp
示例12: AddPlot
int TGnuPlot::AddPlot(const TFltV& YValV, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style) {
TFltKdV XYValV(YValV.Len(), 0);
for (int i = 0; i < YValV.Len(); i++) {
XYValV.Add(TFltKd(TFlt(i+1), TFlt(YValV[i])));
}
return AddPlot(XYValV, SeriesTy, Label, Style);
}
开发者ID:mkrnc,项目名称:snap,代码行数:7,代码来源:gnuplot.cpp
示例13: GetSngVec
void GetSngVec(const PNGraph& Graph, TFltV& LeftSV, TFltV& RightSV) {
const int Nodes = Graph->GetNodes();
TFltVV LSingV, RSingV;
TFltV SngValV;
if (Nodes < 500) {
// perform full SVD
TFltVV AdjMtx(Nodes+1, Nodes+1);
TIntH NodeIdH;
// create adjecency matrix
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
NodeIdH.AddKey(NodeI.GetId()); }
for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1;
for (int e = 0; e < NodeI.GetOutDeg(); e++) {
const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1; // no self edges
if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1;
}
}
try { // can fail to converge but results seem to be good
TSvd::Svd1Based(AdjMtx, LSingV, SngValV, RSingV); }
catch(...) {
printf("\n***No SVD convergence: G(%d, %d)\n", Nodes, Graph->GetEdges()); }
} else { // Lanczos
TNGraphMtx GraphMtx(Graph);
TSparseSVD::LanczosSVD(GraphMtx, 1, 8, ssotFull, SngValV, LSingV, RSingV);
}
TFlt MxSngVal = TFlt::Mn;
int ValN = 0;
for (int i = 0; i < SngValV.Len(); i++) {
if (MxSngVal < SngValV[i]) { MxSngVal = SngValV[i]; ValN = i; } }
LSingV.GetCol(ValN, LeftSV);
RSingV.GetCol(ValN, RightSV);
IsAllValVNeg(LeftSV, true);
IsAllValVNeg(RightSV, true);
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:35,代码来源:gsvd.cpp
示例14: IAssert
void TEpidemModel::RungeKutta(const TFltV& y, const TFltV& dydx, double x, double h, TFltV& SirOutV) {
const int n = y.Len();
IAssert(y.Len() == n && dydx.Len() == n);
TFltV dym(n), dyt(n), yt(n);
int i;
double hh=h*0.5;
double h6=h/6.0;
double xh=x+hh;
for (i=0; i < n; i++) {
yt[i]=y[i]+hh*dydx[i];
}
GetDerivs(xh, yt, dyt);
for (i=0; i<n; i++) {
yt[i]=y[i]+hh*dyt[i];
}
GetDerivs(xh,yt,dym);
for (i=0; i<n; i++) {
yt[i]=y[i]+h*dym[i];
dym[i] += dyt[i];
}
GetDerivs(x+h,yt,dyt);
SirOutV.Clr(false);
for (i=0; i<n; i++) {
SirOutV.Add(y[i]+h6 * (dydx[i]+dyt[i]+2.0*dym[i]));
}
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:26,代码来源:sir.cpp
示例15: PlotSngValRank
void PlotSngValRank(const PNGraph& Graph, const int& SngVals, const TStr& FNmPref, TStr DescStr) {
TFltV SngValV;
TSnap::GetSngVals(Graph, SngVals, SngValV);
SngValV.Sort(false);
if (DescStr.Empty()) { DescStr = FNmPref; }
TGnuPlot::PlotValV(SngValV, "sngVal."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f",
DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges(), SngValV[0].Val), "Rank", "Singular value", gpsLog10XY, false, gpwLinesPoints);
}
开发者ID:Accio,项目名称:snap,代码行数:8,代码来源:statplot.cpp
示例16: AddErrBar
int TGnuPlot::AddErrBar(const TFltV& YValV, const TFltV& DeltaYV, const TStr& Label) {
IAssert(YValV.Len() == DeltaYV.Len());
TFltKdV XYFltValV(YValV.Len(), 0);
for (int i = 0; i < YValV.Len(); i++) {
XYFltValV.Add(TFltKd(TFlt(i+1), YValV[i]));
}
return AddErrBar(XYFltValV, DeltaYV, Label);
}
开发者ID:mkrnc,项目名称:snap,代码行数:8,代码来源:gnuplot.cpp
示例17:
int TLSHash::EuclideanHash::Hash(TFltV Datum) {
double Proj = Line[Datum.Len()];
for (int i=0; i<Datum.Len(); i++) {
Proj += Datum[i] * Line[i];
}
Proj /= Gap;
return static_cast<int>(Proj);
}
开发者ID:EDzhangjianyu,项目名称:snap,代码行数:8,代码来源:lsh.cpp
示例18: GetParam
void TSirModel::GetParam(TFltV& ParamV) const {
ParamV.Clr(false);
ParamV.Add(N0);
ParamV.Add(I0);
ParamV.Add(Beta);
ParamV.Add(Gamma);
ParamV.Add(T0);
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:8,代码来源:sir.cpp
示例19: GetIDFWeightV
void TStrParser::GetIDFWeightV(TFltV& WeightV) {
int AlphN = GetAlphabetSize();
WeightV.Gen(AlphN);
for (int AlphC = 0; AlphC < AlphN; AlphC++)
WeightV[AlphC] = log((double)DocsParsed / WordToIdH[AlphC]);
double MaxVal = WeightV[WeightV.GetMxValN()];
for (int AlphC = 0; AlphC < AlphN; AlphC++)
WeightV[AlphC] /= MaxVal;
}
开发者ID:Austindeadhead,项目名称:qminer,代码行数:9,代码来源:strkernel.cpp
示例20: ConjugGrad
static void ConjugGrad(const TMatrix& Matrix, const TFltV& b, TFltV& x,
const int& CGMxIter, const double& RelErr, const TFltV& x0) {
// prepare start vector
x.Gen(Matrix.GetCols());
if (x0.Empty()) { x.PutAll(0.0); }
else { x = x0; }
// do the magic
}
开发者ID:Accio,项目名称:snap,代码行数:9,代码来源:mkcca.cpp
注:本文中的TFltV类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论