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


C++ TFltV::Len方法代码示例

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


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

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

示例2: Update

void TChiSquare::Update(const TFltV& OutValVX, const TFltV& OutValVY) {
	Chi2 = 0.0;	
	EAssertR(OutValVX.Len() == OutValVY.Len(), "TChiSquare: histogram dimensions do not match!");
	// http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/chi2samp.htm
	double SumR = TLinAlg::SumVec(OutValVX);
	double SumS = TLinAlg::SumVec(OutValVY);
	// Do nothing if zero histogram is detected
	if (SumR <= 0.0 || SumS <= 0.0) { return; }
	double K1 = TMath::Sqrt(SumS / SumR);
	double K2 = 1.0 / K1;
	for (int ValN = 0; ValN < OutValVX.Len(); ValN++) {
		double Ri = OutValVX[ValN];
		double Si = OutValVY[ValN];
		double RpS = Ri + Si;
		if (RpS > 0) {
			Chi2 += TMath::Sqr(K1 * Ri - K2 * Si) / RpS;
		}
	}
	if (Chi2 == 0.0) {
		P = TFlt::PInf;
	}
	else {
		P = TSpecFunc::GammaQ(0.5*(DegreesOfFreedom), 0.5*(Chi2));
	}
}
开发者ID:amrsobhy,项目名称:qminer,代码行数:25,代码来源:signalproc.cpp

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

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

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

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

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

示例8: RungeKutta

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

示例9: catch

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

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

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

示例12:

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

示例13: Dump

void TNEANetMP::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
    fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
    // load node attributes
    TIntV IntAttrN;
    IntAttrValueNI(NodeI.GetId(), IntAttrN);
    fprintf(OutF, "    nai[%d]", IntAttrN.Len());
    for (int i = 0; i < IntAttrN.Len(); i++) {
      fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
    TStrV StrAttrN;
    StrAttrValueNI(NodeI.GetId(), StrAttrN);
    fprintf(OutF, "    nas[%d]", StrAttrN.Len());
    for (int i = 0; i < StrAttrN.Len(); i++) {
      fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
    TFltV FltAttrN;
    FltAttrValueNI(NodeI.GetId(), FltAttrN);
    fprintf(OutF, "    naf[%d]", FltAttrN.Len());
    for (int i = 0; i < FltAttrN.Len(); i++) {
      fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }

    fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
    for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
    fprintf(OutF, "\n");
    fprintf(OutF, "    out[%d]", NodeI.GetOutDeg());
    for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
    fprintf(OutF, "\n");
  }
  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
    fprintf(OutF, "  %*d]  %*d  ->  %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());

    // load edge attributes
    TIntV IntAttrE;
    IntAttrValueEI(EdgeI.GetId(), IntAttrE);
    fprintf(OutF, "    eai[%d]", IntAttrE.Len());
    for (int i = 0; i < IntAttrE.Len(); i++) {
      fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]());
    }
    TStrV StrAttrE;
    StrAttrValueEI(EdgeI.GetId(), StrAttrE);
    fprintf(OutF, "    eas[%d]", StrAttrE.Len());
    for (int i = 0; i < StrAttrE.Len(); i++) {
      fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]());
    }
    TFltV FltAttrE;
    FltAttrValueEI(EdgeI.GetId(), FltAttrE);
    fprintf(OutF, "    eaf[%d]", FltAttrE.Len());
    for (int i = 0; i < FltAttrE.Len(); i++) {
      fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]());
    }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
}
开发者ID:JohnMatta,项目名称:snap,代码行数:58,代码来源:networkmp.cpp

示例14: IsAllValVNeg

bool IsAllValVNeg(TFltV& ValV, const bool& InvertSign) {
  bool IsAllNeg=true;
  for (int i = 0; i < ValV.Len(); i++) {
    if (ValV[i]>0.0) { IsAllNeg=false; break; }
  }
  if (IsAllNeg && InvertSign) {
    for (int i = 0; i < ValV.Len(); i++) { 
      ValV[i] = -ValV[i]; }
  }
  return IsAllNeg;
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:11,代码来源:gsvd.cpp

示例15: PMultiplyT

// Result = A' * Vec
void TNGraphMtx::PMultiplyT(const TFltV& Vec, TFltV& Result) const {
  const int RowN = GetRows();
  Assert(Vec.Len() >= RowN && Result.Len() >= RowN);
  const THash<TInt, TNGraph::TNode>& NodeH = Graph->NodeH;
  for (int i = 0; i < RowN; i++) Result[i] = 0.0;
  for (int j = 0; j < RowN; j++) {
    const TIntV& RowV = NodeH[j].OutNIdV;
    for (int i = 0; i < RowV.Len(); i++) {
      Result[RowV[i]] += Vec[j];
    }
  }
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:13,代码来源:gsvd.cpp


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