本文整理汇总了C++中TVec::Last方法的典型用法代码示例。如果您正苦于以下问题:C++ TVec::Last方法的具体用法?C++ TVec::Last怎么用?C++ TVec::Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TVec
的用法示例。
在下文中一共展示了TVec::Last方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetCPMCommunities
/// Clique Percolation method communities
void TCliqueOverlap::GetCPMCommunities(const PUNGraph& G, int MinMaxCliqueSize, TVec<TIntV>& NIdCmtyVV) {
printf("Clique Percolation Method\n");
TExeTm ExeTm;
TVec<TIntV> MaxCliques;
TCliqueOverlap::GetMaxCliques(G, MinMaxCliqueSize, MaxCliques);
// op RS 2012/05/15, commented out next line, a parameter is missing,
// creating a warning on OS X
// printf("...%d cliques found\n");
// get clique overlap matrix (graph)
PUNGraph OverlapGraph = TCliqueOverlap::CalculateOverlapMtx(MaxCliques, MinMaxCliqueSize-1);
printf("...overlap matrix (%d, %d)\n", G->GetNodes(), G->GetEdges());
// connected components are communities
TCnComV CnComV;
TSnap::GetWccs(OverlapGraph, CnComV);
NIdCmtyVV.Clr(false);
TIntSet CmtySet;
for (int c = 0; c < CnComV.Len(); c++) {
CmtySet.Clr(false);
for (int i = 0; i <CnComV[c].Len(); i++) {
const TIntV& CliqueNIdV = MaxCliques[CnComV[c][i]];
CmtySet.AddKeyV(CliqueNIdV);
}
NIdCmtyVV.Add();
CmtySet.GetKeyV(NIdCmtyVV.Last());
NIdCmtyVV.Last().Sort();
}
printf("done [%s].\n", ExeTm.GetStr());
}
示例2: SplitOnCh
int TStrUtil::SplitOnCh(TChA& ChA, TVec<char *>& WrdV, const char& Ch, const bool& SkipEmpty) {
WrdV.Clr(false);
WrdV.Add(ChA.CStr());
for (char *c = (char *) ChA.CStr(); *c; c++) {
if (*c == Ch) {
*c = 0;
if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
WrdV.Add(c+1);
}
}
if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
return WrdV.Len();
}
示例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);
}
示例4: GetSngVec
void GetSngVec(const PNGraph& Graph, const int& SngVecs, TFltV& SngValV, TVec<TFltV>& LeftSV, TVec<TFltV>& RightSV) {
const int Nodes = Graph->GetNodes();
SngValV.Clr();
LeftSV.Clr();
RightSV.Clr();
TFltVV LSingV, RSingV;
if (Nodes < 100) {
// perform full SVD
TFltVV AdjMtx(Nodes+1, Nodes+1);
TIntH NodeIdH;
// create adjecency matrix (1-based)
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, SngVecs, 2*SngVecs, ssotFull, SngValV, LSingV, RSingV);
//TGAlg::SaveFullMtx(Graph, "adj_mtx.txt");
//TLAMisc::DumpTFltVVMjrSubMtrx(LSingV, LSingV.GetRows(), LSingV.GetCols(), "LSingV2.txt"); // save MTX
}
TFltIntPrV SngValIdV;
for (int i = 0; i < SngValV.Len(); i++) {
SngValIdV.Add(TFltIntPr(SngValV[i], i));
}
SngValIdV.Sort(false);
SngValV.Sort(false);
for (int v = 0; v < SngValIdV.Len(); v++) {
LeftSV.Add();
LSingV.GetCol(SngValIdV[v].Val2, LeftSV.Last());
RightSV.Add();
RSingV.GetCol(SngValIdV[v].Val2, RightSV.Last());
}
IsAllValVNeg(LeftSV[0], true);
IsAllValVNeg(RightSV[0], true);
}
示例5: SplitWords
int TStrUtil::SplitWords(TChA& ChA, TVec<char *>& WrdV, const bool& SplitOnWs) {
WrdV.Clr(false);
WrdV.Add(ChA.CStr());
for (char *c = (char *) ChA.CStr(); *c; c++) {
if ((SplitOnWs && *c == ' ') || (! SplitOnWs && ! TCh::IsAlNum(*c))) {
*c = 0;
if (! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
WrdV.Add(c+1);
}
}
return WrdV.Len();
}
示例6: RunEuler
void TEpidemModel::RunEuler(const TFltV& StartValV, const double& StartT, const double& StopT, const int& NSteps, TVec<TFltV>& OutValV) {
const double h = (StopT-StartT) / NSteps;
TFltV ValV(StartValV), dydx(StartValV.Len()), ValV2(StartValV.Len());
for (int v = 0; v < StartValV.Len(); v++) {
OutValV.Add();
OutValV[v].Clr(false);
OutValV[v].Add(StartValV[v]);
}
OutValV.Add(); // x values
OutValV.Last().Add(StartT);
for (double x = StartT; x <= StopT; x += h) {
GetDerivs(x, ValV, dydx);
for (int v = 0; v < ValV.Len(); v++) {
ValV[v] += h*dydx[v];
OutValV[v].Add(ValV[v]);
}
OutValV.Last().Add(x+h);
}
for (int v = 1; v < OutValV.Len(); v++) {
IAssert(OutValV[v].Len()==OutValV[v-1].Len());
}
}
示例7: GetOverlapCliques
void TCliqueOverlap::GetOverlapCliques(const TVec<TIntV>& OverlapMtx, int MinNodeOverlap, TVec<TIntV>& CliqueIdVV) {
int n = OverlapMtx.Len();
for (int i=0; i<n; i++) {
bool isCommunity = false;
for (int j=i+1; j<n; j++) {
if (OverlapMtx[i][j] >= MinNodeOverlap) {
if (! isCommunity) {
TIntV v; v.Add(i);
CliqueIdVV.Add(v);
isCommunity=true;
}
CliqueIdVV.Last().Add(j);
}
}
}
}
示例8: NextFromIndex
// Essesntially the same as TssParser::Next
// For parallel load, FldV cannot be shared across many threads
void TSsParserMP::NextFromIndex(uint64 Index, TVec<char*>& FieldsV)
{
// split on SplitCh
FieldsV.Clr();
char* cur = FInPt->GetLine(Index);
if (SkipLeadBlanks) { // skip leading blanks
while (*cur && TCh::IsWs(*cur)) { cur++; }
}
char *last = cur;
while (*cur != 0 && *cur != '\n') {
if (SsFmt == ssfWhiteSep) { while (*cur && (*cur != '\n') && ! TCh::IsWs(*cur)) { cur++; } }
else { while (*cur && *cur!=SplitCh && (*cur != '\n')) { cur++; } }
if (*cur == 0) { break; }
if (*cur == '\n') { break; }
//*cur = 0;
cur++;
FieldsV.Add(last); last = cur;
if (SkipEmptyFld && strlen(FieldsV.Last())==0) { FieldsV.DelLast(); } // skip empty fields
}
FieldsV.Add(last); // add last field
}
示例9: CalculateOverlapMtx
PUNGraph TCliqueOverlap::CalculateOverlapMtx(const TVec<TIntV>& MaxCliques, int MinNodeOverlap) {
const int n = MaxCliques.Len();
//Convert max cliques to HashSets
TVec<THashSet<TInt> > cliques;
for (int i=0; i<n; i++) {
const int len = MaxCliques[i].Len();
cliques.Add();
if (len < MinNodeOverlap) { continue; }
THashSet<TInt>& set = cliques.Last(); set.Gen(len);
for (int j=0; j<len; j++) { set.AddKey(MaxCliques[i][j]); }
}
//Init clique clique overlap matrix
PUNGraph OverlapMtx = TUNGraph::New();
for (int i=0; i < n; i++) {
OverlapMtx->AddNode(i); }
//Calculate clique clique overlap matrix
for (int i=0; i<n; i++) {
for (int j=i+1; j<n; j++) {
if (Intersection(cliques[i], cliques[j]) >= MinNodeOverlap) {
OverlapMtx->AddEdge(i,j); }
}
}
return OverlapMtx;
}