本文整理汇总了C++中TExeTm::GetSecs方法的典型用法代码示例。如果您正苦于以下问题:C++ TExeTm::GetSecs方法的具体用法?C++ TExeTm::GetSecs怎么用?C++ TExeTm::GetSecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TExeTm
的用法示例。
在下文中一共展示了TExeTm::GetSecs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddNodes
TFfGGen::TStopReason TFfGGen::AddNodes(const int& GraphNodes, const bool& FloodStop) {
printf("\n***ForestFire: %s Nodes:%d StartNodes:%d Take2AmbProb:%g\n", BurnExpFire ? "ExpFire" : "GeoFire", GraphNodes, StartNodes(), Take2AmbProb());
printf(" FwdBurnP:%g BckBurnP:%g ProbDecay:%g Orphan:%g\n", FwdBurnProb(), BckBurnProb(), ProbDecay(), OrphanProb());
TExeTm ExeTm;
int Burned1 = 0, Burned2 = 0, Burned3 = 0; // last 3 fire sizes
// create initial set of nodes
if (Graph.Empty()) { Graph = PNGraph::New(); }
if (Graph->GetNodes() == 0) {
for (int n = 0; n < StartNodes; n++) { Graph->AddNode(); }
}
int NEdges = Graph->GetEdges();
// forest fire
TRnd Rnd(0);
TForestFire ForestFire(Graph, FwdBurnProb, BckBurnProb, ProbDecay, 0);
// add nodes
for (int NNodes = Graph->GetNodes() + 1; NNodes <= GraphNodes; NNodes++) {
const int NewNId = Graph->AddNode(-1);
IAssert(NewNId == Graph->GetNodes() - 1); // node ids have to be 0...N
// not an Orphan (burn fire)
if (OrphanProb == 0.0 || Rnd.GetUniDev() > OrphanProb) {
// infect ambassadors
if (Take2AmbProb == 0.0 || Rnd.GetUniDev() > Take2AmbProb || NewNId < 2) {
ForestFire.Infect(Rnd.GetUniDevInt(NewNId)); // take 1 ambassador
}
else {
const int AmbassadorNId1 = Rnd.GetUniDevInt(NewNId);
int AmbassadorNId2 = Rnd.GetUniDevInt(NewNId);
while (AmbassadorNId1 == AmbassadorNId2) {
AmbassadorNId2 = Rnd.GetUniDevInt(NewNId);
}
ForestFire.Infect(TIntV::GetV(AmbassadorNId1, AmbassadorNId2)); // take 2 ambassadors
}
// burn fire
if (BurnExpFire) { ForestFire.BurnExpFire(); }
else { ForestFire.BurnGeoFire(); }
// add edges to burned nodes
for (int e = 0; e < ForestFire.GetBurned(); e++) {
Graph->AddEdge(NewNId, ForestFire.GetBurnedNId(e));
NEdges++;
}
Burned1 = Burned2; Burned2 = Burned3; Burned3 = ForestFire.GetBurned();
}
else {
// Orphan (zero out-links)
Burned1 = Burned2; Burned2 = Burned3; Burned3 = 0;
}
if (NNodes % Kilo(1) == 0) {
printf("(%d, %d) burned: [%d,%d,%d] [%s]\n", NNodes, NEdges, Burned1, Burned2, Burned3, ExeTm.GetStr());
}
if (FloodStop && NEdges>GraphNodes && (NEdges / double(NNodes)>1000.0)) { // average node degree is more than 500
printf(". FLOOD. G(%6d, %6d)\n", NNodes, NEdges); return srFlood;
}
if (NNodes % 1000 == 0 && TimeLimitSec > 0 && ExeTm.GetSecs() > TimeLimitSec) {
printf(". TIME LIMIT. G(%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
return srTimeLimit;
}
}
IAssert(Graph->GetEdges() == NEdges);
return srOk;
}
示例2: GenKron
void GenKron(const TStr& Args, TKronMtx& FitMtx, TFltPrV& KronDegAvgIn, TFltPrV& KronDegAvgOut){
Env = TEnv(Args, TNotify::NullNotify);
TExeTm ExecTime;
// number of Kronecker graphs to generate
const TInt NKron = Env.GetIfArgPrefixInt("-n:", 1, "Number of generated Kronecker graphs");
// iterations of Kronecker product
const TInt NIter = Env.GetIfArgPrefixInt("-i:", 10, "Iterations of Kronecker product");
// is graph directed?
TStr IsDir = Env.GetIfArgPrefixStr("-isdir:", "false", "Produce directed graph (true, false)");
TFlt ExpectedNodes = FitMtx.GetNodes(NIter), ExpectedEdges = FitMtx.GetEdges(NIter);
TFile << "Kronecker nodes: " << ExpectedNodes << ", expected Kronecker edges: " << ExpectedEdges << endl;
double Sec = 0.0;
int AvgMaxOutDeg = 0, AvgMaxInDeg = 0, MinMaxOutDeg = 0, MaxMaxOutDeg = 0, MinMaxInDeg = 0, MaxMaxInDeg = 0;
bool Dir = IsDir == "true" ? true : false;
for (int i = 0; i < NKron; i++){
ExecTime.Tick();
PNGraph Kron = TKronMtx::GenFastKronecker(FitMtx, NIter, Dir, 0);
Sec += ExecTime.GetSecs();
printf("Calculating maximum degree...\n");
int MaxOutDeg = GetMaxMinDeg(Kron, IsDir, "false", "true"), MaxInDeg = GetMaxMinDeg(Kron, IsDir, "true", "true");
CompareDeg(i, MaxOutDeg, MinMaxOutDeg, MaxMaxOutDeg, AvgMaxOutDeg);
CompareDeg(i, MaxInDeg, MinMaxInDeg, MaxMaxInDeg, AvgMaxInDeg);
//printf("Nodes count: %d, nodes with non-zero degree %d, edges count %d\n max deg = %d\n", kron->GetNodes(), TSnap::CntNonZNodes(kron), kron->GetEdges(), MaxDeg);
if (i == NKron - 1){
//TFile << "Clustering coefficient: " << TSnap::GetClustCf(kron) << endl;
//TSnap::PlotClustCf(kron,"kronSingle");
//TSnap::PlotHops(kron, "kronSingle");
TFile << "Maximum output degree in kron graph: " << "from " << MinMaxOutDeg << " to " << MaxMaxOutDeg << " (average: " << (double)AvgMaxOutDeg / (double)NKron << ")" << endl;
TFile << "Maximum input degree in kron graph: " << "from " << MinMaxInDeg << " to " << MaxMaxInDeg << " (average: " << (double)AvgMaxInDeg / (double)NKron << ")" << endl;
}
AddDegreesStat(KronDegAvgIn, Kron, true);
AddDegreesStat(KronDegAvgOut, Kron, false);
}
Sec /= NKron;
GetAvgDegreeStat(KronDegAvgIn, NKron);
GetAvgDegreeStat(KronDegAvgOut, NKron);
KronDegAvgIn.Sort();
KronDegAvgOut.Sort();
TFile << "Average time of generation of Kronecker product: " << Sec << endl;
}
示例3: GenRewire
/// Rewire the network. Keeps node degrees as is but randomly rewires the edges.
/// Use this function to generate a random graph with the same degree sequence
/// as the OrigGraph.
/// See: On the uniform generation of random graphs with prescribed degree
/// sequences by R. Milo, N. Kashtan, S. Itzkovitz, M. E. J. Newman, U. Alon
/// URL: http://arxiv.org/abs/cond-mat/0312028
PUNGraph GenRewire(const PUNGraph& OrigGraph, const int& NSwitch, TRnd& Rnd) {
const int Nodes = OrigGraph->GetNodes();
const int Edges = OrigGraph->GetEdges();
PUNGraph GraphPt = TUNGraph::New();
TUNGraph& Graph = *GraphPt;
Graph.Reserve(Nodes, -1);
TExeTm ExeTm;
// generate a graph that satisfies the constraints
printf("Randomizing edges (%d, %d)...\n", Nodes, Edges);
TIntPrSet EdgeSet(Edges);
for (TUNGraph::TNodeI NI = OrigGraph->BegNI(); NI < OrigGraph->EndNI(); NI++) {
const int NId = NI.GetId();
for (int e = 0; e < NI.GetOutDeg(); e++) {
if (NId <= NI.GetOutNId(e)) { continue; }
EdgeSet.AddKey(TIntPr(NId, NI.GetOutNId(e)));
}
Graph.AddNode(NI.GetId());
}
// edge switching
uint skip=0;
for (uint swps = 0; swps < 2*uint(Edges)*uint(NSwitch); swps++) {
const int keyId1 = EdgeSet.GetRndKeyId(Rnd);
const int keyId2 = EdgeSet.GetRndKeyId(Rnd);
if (keyId1 == keyId2) { skip++; continue; }
const TIntPr& E1 = EdgeSet[keyId1];
const TIntPr& E2 = EdgeSet[keyId2];
TIntPr NewE1(E1.Val1, E2.Val1), NewE2(E1.Val2, E2.Val2);
if (NewE1.Val1 > NewE1.Val2) { Swap(NewE1.Val1, NewE1.Val2); }
if (NewE2.Val1 > NewE2.Val2) { Swap(NewE2.Val1, NewE2.Val2); }
if (NewE1!=NewE2 && NewE1.Val1!=NewE1.Val2 && NewE2.Val1!=NewE2.Val2 && ! EdgeSet.IsKey(NewE1) && ! EdgeSet.IsKey(NewE2)) {
EdgeSet.DelKeyId(keyId1); EdgeSet.DelKeyId(keyId2);
EdgeSet.AddKey(TIntPr(NewE1));
EdgeSet.AddKey(TIntPr(NewE2));
} else { skip++; }
if (swps % Edges == 0) {
printf("\r %uk/%uk: %uk skip [%s]", swps/1000u, 2*uint(Edges)*uint(NSwitch)/1000u, skip/1000u, ExeTm.GetStr());
if (ExeTm.GetSecs() > 2*3600) { printf(" *** Time limit!\n"); break; } // time limit 2 hours
}
}
printf("\r total %uk switchings attempted, %uk skiped [%s]\n", 2*uint(Edges)*uint(NSwitch)/1000u, skip/1000u, ExeTm.GetStr());
for (int e = 0; e < EdgeSet.Len(); e++) {
Graph.AddEdge(EdgeSet[e].Val1, EdgeSet[e].Val2); }
return GraphPt;
}
示例4: em_multi
void em_multi(ExamMgr& ExM) {
TExeTm tm;
TFltV Alphas(ExM.CPU), ThVs[ExM.CPU];
for (int i=0; i<ExM.CPU; i++) ThVs[i] = TFltV(ExM.W+1);
std::vector<std::thread> threads;
for (int i=0; i<ExM.CPU; i++) threads.emplace_back([i, &ExM, &Alphas, &ThVs] { em_sub(i, ExM, Alphas[i], ThVs[i]); });
for(std::thread& t: threads) t.join();
for (int n=1; n<ExM.CPU; n++) Alphas[0] += Alphas[n];
Alphas[0] /= ExM.CPU;
for (int i=0; i<=ExM.W; i++) {
for (int n=1; n<ExM.CPU; n++) ThVs[0][i] += ThVs[n][i];
ThVs[0][i] /= ExM.CPU;
}
if (ExM.TrimTail) ExM.TrimTailNTh(ThVs[0], Alphas[0]);
const TStr OFnm = ExM.GetBNTHFNm();
BIO::SaveFltVWithIdx(ThVs[0], OFnm, TStr::Fmt("# Nodes: %d\n# Repeated: %d\n# Avg time cost: %.2f secs.\n# Alpha: %.6e",
ExM.N, ExM.GetRpt(), tm.GetSecs()/ExM.GetRpt(), Alphas[0].Val));
printf("Saved to %s\n", OFnm.CStr());
}
示例5: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(
TStr::Fmt("Kronecker graphs. build: %s, %s. Time: %s", __TIME__,
__DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
Env = TEnv(argc, argv, TNotify::StdNotify);
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt",
"Input graph file (single directed edge per line)");
TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file prefix");
const TInt NZero = Env.GetIfArgPrefixInt("-n0:", 2,
"Innitiator matrix size");
const TStr InitMtx = Env.GetIfArgPrefixStr("-m:", "0.9 0.7; 0.5 0.2",
"Init Gradient Descent Matrix (R=random)").GetLc();
const TStr Perm =
Env.GetIfArgPrefixStr("-p:", "d",
"Initial node permutation: d:Degree, r:Random, o:Order").GetLc();
const TInt GradIter = Env.GetIfArgPrefixInt("-gi:", 50,
"Gradient descent iterations");
const TFlt LrnRate = Env.GetIfArgPrefixFlt("-l:", 1e-5,
"Learning rate");
const TFlt MnStep = Env.GetIfArgPrefixFlt("-mns:", 0.005,
"Minimum gradient step");
const TFlt MxStep = Env.GetIfArgPrefixFlt("-mxs:", 0.05,
"Maximum gradient step");
const TInt WarmUp = Env.GetIfArgPrefixInt("-w:", 10000,
"Samples to warm up");
const TInt NSamples = Env.GetIfArgPrefixInt("-s:", 100000,
"Samples per gradient estimation");
//const TInt GradType = Env.GetIfArgPrefixInt("-gt:", 1, "1:Grad1, 2:Grad2");
const bool ScaleInitMtx = Env.GetIfArgPrefixBool("-sim:", true,
"Scale the initiator to match the number of edges");
const TFlt PermSwapNodeProb =
Env.GetIfArgPrefixFlt("-nsp:", 1.0,
"Probability of using NodeSwap (vs. EdgeSwap) MCMC proposal distribution");
if (OutFNm.Empty()) {
OutFNm = TStr::Fmt("%s-fit%d", InFNm.GetFMid().CStr(), NZero());
}
// load graph
PNGraph G;
if (InFNm.GetFExt().GetLc() == ".ungraph") {
TFIn FIn(InFNm);
G = TSnap::ConvertGraph<PNGraph>(TUNGraph::Load(FIn), true);
} else if (InFNm.GetFExt().GetLc() == ".ngraph") {
TFIn FIn(InFNm);
G = TNGraph::Load(FIn);
} else {
G = TSnap::LoadEdgeList<PNGraph>(InFNm, 0, 1);
}
// fit
TKronMtx InitKronMtx =
InitMtx == "r" ?
TKronMtx::GetRndMtx(NZero, 0.1) :
TKronMtx::GetMtx(InitMtx);
InitKronMtx.Dump("INIT PARAM", true);
TKroneckerLL KronLL(G, InitKronMtx, PermSwapNodeProb);
if (ScaleInitMtx) {
InitKronMtx.SetForEdges(G->GetNodes(), G->GetEdges());
}
KronLL.InitLL(G, InitKronMtx);
InitKronMtx.Dump("SCALED PARAM", true);
KronLL.SetPerm(Perm.GetCh(0));
double LogLike = 0;
//if (GradType == 1) {
LogLike = KronLL.GradDescent(GradIter, LrnRate, MnStep, MxStep, WarmUp,
NSamples);
//} else if (GradType == 2) {
// LogLike = KronLL.GradDescent2(GradIter, LrnRate, MnStep, MxStep, WarmUp, NSamples); }
//else{ Fail; }
const TKronMtx& FitMtx = KronLL.GetProbMtx();
FILE *F = fopen(OutFNm.CStr(), "w");
fprintf(F, "Input\t%s\n", InFNm.CStr());
TStrV ParamV;
Env.GetCmLn().SplitOnAllCh(' ', ParamV);
fprintf(F, "Command line options\n");
for (int i = 0; i < ParamV.Len(); i++) {
fprintf(F, "\t%s\n",
ParamV[i].CStr() + (ParamV[i][0] == '-' ? 1 : 0));
}
fprintf(F, "Loglikelihood\t%10.2f\n", LogLike);
fprintf(F, "Absolute error (based on expected number of edges)\t%f\n",
KronLL.GetAbsErr());
fprintf(F, "RunTime\t%g\n", ExeTm.GetSecs());
fprintf(F, "Estimated initiator\t%s\n", FitMtx.GetMtxStr().CStr());
fclose(F);
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(),
TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}