本文整理汇总了C++中TExeTm::GetTmStr方法的典型用法代码示例。如果您正苦于以下问题:C++ TExeTm::GetTmStr方法的具体用法?C++ TExeTm::GetTmStr怎么用?C++ TExeTm::GetTmStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TExeTm
的用法示例。
在下文中一共展示了TExeTm::GetTmStr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EnumSubGraphs
void TSubGraphsEnum::EnumSubGraphs(const int& MaxEdges) {
TExeTm ExeTm;
Gen2Graphs();
printf(" %2d edge graphs: %d\t[%s]\n", 2, SgV.Len(), ExeTm.GetTmStr()); ExeTm.Tick();
//for (int i = 0; i < SgV.Len(); i++) { SgV[i].Dump(TStr::Fmt(" %d", i+1)); }
//printf("**************************************************************\n");
TSimpleGraph SimpleG;
TIntPrV& EdgeV = SimpleG.GetEdgeV();
// multiple edge sub-graphs
for (int edges = 3; edges <= MaxEdges; edges++) {
EdgeV.Clr();
printf(" %2d edge graphs:", edges);
for (int g1 = 0; g1 < SgV.Len()-1; g1++) {
for (int g2 = g1+1; g2 < SgV.Len(); g2++) {
if (SimpleG.Join(SgV[g1], SgV[g2])) { NextSgV.Add(SimpleG); }
}
}
printf(" candidates: %8d [%s]", NextSgV.Len(), ExeTm.GetTmStr()); ExeTm.Tick();
NextSgV.Sort();
SgV.Gen(NextSgV.Len(), 0);
SgV.Add(NextSgV[0]);
for (int i = 1; i < NextSgV.Len(); i++) {
if (SgV.Last() != NextSgV[i]) {
SgV.Add(NextSgV[i]);
}
}
NextSgV.Clr(false);
printf(" total: %8d [%s]\n", SgV.Len(), ExeTm.GetTmStr()); ExeTm.Tick();
//for (int i = 0; i < SgV.Len(); i++) { SgV[i].Dump(TStr::Fmt(" %d", i+1)); }
//printf("**************************************************************\n");
}
}
示例2: GenPy
int GenPy(PUNGraph &res, ofstream& TFile, const TStr& parameters)
{
Env = TEnv(parameters, TNotify::StdNotify);
TStr mN = Env.GetIfArgPrefixStr("-module:", "random_graphs", "Module name");
TStr fN = Env.GetIfArgPrefixStr("-func:", "fast_gnp_random_graph", "Function name");
PyObject **G = new PyObject*[1];
char *moduleName = mN.CStr();
char *funcName = fN.CStr();
AddFuncInfo();
TStrV args, argTypes;
if (!ParseArgs(funcName, parameters, args, argTypes))
{
printf("Fail to parse arguments for NetworkX generation...\n");
return 0;
};
TExeTm execTime;
if (!CallPyFunction(moduleName, funcName, args, argTypes, G))
{
cout << "CallPyFunction() raised error. Execution terminated.\n";
system("pause");
exit(1);
};
TFile << "Time of generation of graph by NetworkX: " << execTime.GetTmStr() << endl;
execTime.Tick();
PyObject*** nodes = new PyObject**[1];
GetNodes(G, nodes);
int nodesCount = PyList_Size(*(nodes[0]));
//printf("nodesCount = %d, ", nodesCount);
res = PUNGraph::TObj::New();
res->Reserve(nodesCount, nodesCount*nodesCount);
for (size_t i = 0; i < nodesCount; i++)
res->AddNode(i);
Py_DECREF(nodes);
PyObject*** edges = new PyObject**[1];
GetEdges(G, edges);
int edgesCount = PyList_Size(*(edges[0]));
//printf("edgesCount = %d\n", edgesCount);
for (size_t i = 0; i < edgesCount; i++)
{
PyObject* item = PySequence_Fast_GET_ITEM(*(edges[0]), i);
int v1, v2;
PyObject* node = PySequence_Fast_GET_ITEM(item,0);
v1 = PyLong_AsLong(node);
node = PySequence_Fast_GET_ITEM(item,1);
v2 = PyLong_AsLong(node);
res->AddEdge(v1,v2);
}
TFile << "Time of copying of graph from NetworkX representation: " << execTime.GetTmStr() << endl;
Py_DECREF(G);
Py_DECREF(edges);
//Py_Finalize(); // очищение памяти, отданной интерпретатору
return 0;
}
示例3: main
int main(int argc, char* argv[]) {
setbuf(stdout, NULL); // disables the buffer so that print statements are not buffered and display immediately (?)
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Backbone extractor (Vespignani). build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "input network");
const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "output prefix (alpha value and filename extensions added)");
const float alpha = Env.GetIfArgPrefixFlt("-a:", 0.01, "alpha significance level threshold");
// Load graph and create directed and undirected graphs (pointer to the same memory)
printf("\nLoading %s...", InFNm.CStr());
PFltWNGraph WGraph = TSnap::LoadFltWEdgeList<TWNGraph>(InFNm);
printf(" DONE\n");
printf(" nodes: %d\n", WGraph->GetNodes());
printf(" edges: %d\n", WGraph->GetEdges());
printf(" time elapsed: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
// Declare variables
TIntFltH OutWDegH, InWDegH;
TIntIntH OutDegH, InDegH;
// Get degrees, weighted and unweighted
printf("\nGetting initial distribution of binary in / out degrees...");
TSnap::GetInDegH(WGraph, InDegH);
TSnap::GetOutDegH(WGraph, OutDegH);
printf(" DONE (time elapsed: %s (%s))", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
printf("\nGetting initial distribution of weighted in / out degrees...");
TSnap::GetWInDegH(WGraph, InWDegH);
TSnap::GetWOutDegH(WGraph, OutWDegH);
printf(" DONE (time elapsed: %s (%s))", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
// Apply the disparity filter Vespignani method
printf("\nApplying the disparity filter vespignani method...");
TSnap::FilterEdgesVespignani(WGraph, InWDegH, OutWDegH, InDegH, OutDegH, alpha);
printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
printf("\nPruned graph:");
printf("\n nodes: %d", WGraph->GetNodes());
printf("\n edges: %d\n", WGraph->GetEdges());
// OUTPUTTING
printf("\nSaving %s-%f.snap...", OutFNm.CStr(), alpha);
TSnap::SaveFltWEdgeList(WGraph, TStr::Fmt("%s-%f.snap", OutFNm.CStr(), alpha), "");
printf(" DONE\n");
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例4: main
int main(int argc, char* argv[]) {
// code needed for inputing parameters
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Network diversity. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm; // for measuring execution time
Try
const TStr InFNmGraph = Env.GetIfArgPrefixStr("-i:", "artificial_intelligence_pub.txt", "Input graph (undirected graph)");
const TStr InFNmCat = Env.GetIfArgPrefixStr("-c:", "artificial_intelligence_cat_pub.txt", "Categories");
const TStr InFNmMat = Env.GetIfArgPrefixStr("-m:", "sciences.txt", "Matrix");
const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "diversity.txt", "Output file");
const int DivAlg = Env.GetIfArgPrefixInt("-a:", 1, "Measure: 1:Stirling");
const int Alpha = Env.GetIfArgPrefixInt("-alp:", 1, "alpha");
const int Beta = Env.GetIfArgPrefixInt("-bet:", 1, "beta");
const int Gamma = Env.GetIfArgPrefixInt("-gam:", 1, "gama");
// defining graph
PUNGraph Graph = TSnap::LoadEdgeList<PUNGraph>(InFNmGraph, false);
double D = 0.0;
TStr DivAlgStr;
// based on input parametr -a (variable DivAlg), diversity measure is choosen
if (DivAlg == 1) {
DivAlgStr = "Stirling";
D = TSnap::StirlingIndex(Graph,InFNmCat,InFNmMat, Alpha, Beta, Gamma);}
else { Fail; }
printf("\nDiversity: %f\nrun time: %s (%s)\n", D,ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr()); //print execution time
Catch
return 0;
}
示例5: main
int main(int argc, char* argv[]) {
printf("MemeWorks. build: %s, %s. Start time: %s\n\n", __TIME__, __DATE__, TExeTm::GetCurTm());
TExeTm ExeTm; TInt::Rnd.PutSeed(0); Try
TSecTm BegTm = TSecTm::GetCurTm();
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201101.txt", "-w:F", "-o:1101", "-mint:20110101", "-maxt:20110106"}; BigMain(7, ToDo);
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201101_201103.txt", "-w:F", "-o:11011103"}; BigMain(5, ToDo);
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201104_201106.txt", "-w:F", "-o:11041106", "-mint:20110401", "-maxt:20110701"}; BigMain(7, ToDo);
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201007_201107.txt", "-w:F", "-o:10071107"}; BigMain(5, ToDo);
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201007_201107.txt", "-o:10071107", "-mint:20100714", "-maxt:20110728"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:memestoqtbs", "-i:201101.txt", "-o:1101", "-mint:20110101", "-maxt:20110106"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:mkclustnet", "-i:1101-w4mfq5.QtBs", "-o:1101", "-shglready:F", "-netready:F"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:mkclustnet", "-i:qt08080902-w4mfq5.QtBs", "-o:0808", "-shglready:F", "-netready:F"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:mkclustnet", "-i:11011103-w4mfq5.QtBs", "-o:11011103", "-shglready:F", "-netready:F"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:mkclustnet", "-i:11041106-w4mfq5.QtBs", "-o:11041106", "-shglready:F", "-netready:F"}; BigMain(6, ToDo);
// char *ToDo [] = {"memeclust", "-do:mkclustnet", "-i:10071107-w4mfq5.QtBs", "-o:10071107", "-shglready:F", "-netready:F"}; BigMain(6, ToDo);
//char *ToDo [] = {"memeclust", "-do:memeclustzarya", "-i:201102.txt", "-o:201102", "-shglready:F", "-netready:F", "-mint:20110201", "-maxt:20110301"}; BigMain(8, ToDo);
BigMain(argc, argv);
TSecTm EndTm = TSecTm::GetCurTm();
double usedTime = EndTm.GetAbsSecs() - BegTm.GetAbsSecs();
printf("Total execution time : %02dh%02dm%02ds\n", int(usedTime)/3600, (int(usedTime)%3600)/60, int(usedTime)%60);
return 0;
CatchFull
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例6: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("\nGenerate stochastic block model networks. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const int noNodes = Env.GetIfArgPrefixInt("-n:", 512, "Number of nodes in synthetic graph (default: 512)\n");
const double pIn = Env.GetIfArgPrefixFlt("-pIn:", 0.8, "pIn (default: 0.8)\n");
const double pOut = Env.GetIfArgPrefixFlt("-pOut:", 0.2, "pOut (default: 0.2)\n");
const int noCommunities = Env.GetIfArgPrefixInt("-k:", 2, "Number of communities in graph (default: 2)\n");
TGraphAlgo graphAlgo;
graphAlgo.generateNetwork(noNodes, noCommunities, pIn, pOut);
TStr networkFilename = TStr("test-network-sbm.txt");
TStr networkAdjacencyMatrixFilename = TStr("test-network-sbm-adjacency-matrix.txt");
TStr networkGexfFilename = TStr("test-network-sbm.gexf");
TStr networkLouvainFormatFilename = TStr("test-network-sbm-louvain.txt");
TStr louvainTreeFilename = TStr("test-network-sbm-louvain.tree");
TStr communityLabelsFilename = TStr("test-network-sbm-assignments.txt");
graphAlgo.saveGroundTruth(networkFilename);
graphAlgo.saveGroundTruthAdjacencyMatrix(networkAdjacencyMatrixFilename);
graphAlgo.saveGroundTruthGexf(networkGexfFilename);
graphAlgo.convertGroundTruthToLouvainFormat(networkLouvainFormatFilename);
graphAlgo.saveCommunityLabels(communityLabelsFilename, noNodes, noCommunities);
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例7: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("ragm. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
TStr OutFPrx = Env.GetIfArgPrefixStr("-o:", "", "Output Graph data prefix");
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input edgelist file name");
const TStr LabelFNm = Env.GetIfArgPrefixStr("-l:", "", "Input file name for node names (Node ID, Node label) ");
int OptComs = Env.GetIfArgPrefixInt("-c:", -1, "The number of communities to detect (-1: detect automatically)");
const int MinComs = Env.GetIfArgPrefixInt("-mc:", 5, "Minimum number of communities to try");
const int MaxComs = Env.GetIfArgPrefixInt("-xc:", 100, "Maximum number of communities to try");
const int DivComs = Env.GetIfArgPrefixInt("-nc:", 10, "How many trials for the number of communities");
const int NumThreads = Env.GetIfArgPrefixInt("-nt:", 1, "Number of threads for parallelization");
const double StepAlpha = Env.GetIfArgPrefixFlt("-sa:", 0.3, "Alpha for backtracking line search");
const double StepBeta = Env.GetIfArgPrefixFlt("-sb:", 0.3, "Beta for backtracking line search");
PUNGraph G;
TIntStrH NIDNameH;
if (InFNm.IsStrIn(".ungraph")) {
TFIn GFIn(InFNm);
G = TUNGraph::Load(GFIn);
} else {
G = TAGMUtil::LoadEdgeListStr<PUNGraph>(InFNm, NIDNameH);
}
if (LabelFNm.Len() > 0) {
TSsParser Ss(LabelFNm, ssfTabSep);
while (Ss.Next()) {
if (Ss.Len() > 0) { NIDNameH.AddDat(Ss.GetInt(0), Ss.GetFld(1)); }
}
}
else {
}
printf("Graph: %d Nodes %d Edges\n", G->GetNodes(), G->GetEdges());
TVec<TIntV> EstCmtyVV;
TExeTm RunTm;
TAGMFast RAGM(G, 10, 10);
if (OptComs == -1) {
printf("finding number of communities\n");
OptComs = RAGM.FindComsByCV(NumThreads, MaxComs, MinComs, DivComs, OutFPrx, StepAlpha, StepBeta);
}
RAGM.NeighborComInit(OptComs);
if (NumThreads == 1 || G->GetEdges() < 1000) {
RAGM.MLEGradAscent(0.0001, 1000 * G->GetNodes(), "", StepAlpha, StepBeta);
} else {
RAGM.MLEGradAscentParallel(0.0001, 1000, NumThreads, "", StepAlpha, StepBeta);
}
RAGM.GetCmtyVV(EstCmtyVV);
TAGMUtil::DumpCmtyVV(OutFPrx + "cmtyvv.txt", EstCmtyVV, NIDNameH);
TAGMUtil::SaveGephi(OutFPrx + "graph.gexf", G, EstCmtyVV, 1.5, 1.5, NIDNameH);
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例8: MLENewton
int TLogRegFit::MLENewton(const double& ChangeEps, const int& MaxStep, const TStr PlotNm) {
TExeTm ExeTm;
TFltV GradV(Theta.Len()), DeltaLV(Theta.Len());
TFltVV HVV(Theta.Len(), Theta.Len());
int iter = 0;
double MinVal = -1e10, MaxVal = 1e10;
for(iter = 0; iter < MaxStep; iter++) {
Gradient(GradV);
Hessian(HVV);
GetNewtonStep(HVV, GradV, DeltaLV);
double Increment = TLinAlg::DotProduct(GradV, DeltaLV);
if (Increment <= ChangeEps) {
break;
}
double LearnRate = GetStepSizeByLineSearch(DeltaLV, GradV, 0.15, 0.5);//InitLearnRate/double(0.01*(double)iter + 1);
for(int i = 0; i < Theta.Len(); i++) {
double Change = LearnRate * DeltaLV[i];
Theta[i] += Change;
if(Theta[i] < MinVal) {
Theta[i] = MinVal;
}
if(Theta[i] > MaxVal) {
Theta[i] = MaxVal;
}
}
}
if (! PlotNm.Empty()) {
printf("MLE with Newton method completed with %d iterations(%s)\n",iter,ExeTm.GetTmStr());
}
return iter;
}
示例9: GetModel
// get model graph according to args
void GetModel(const TStr& Args, PNGraph& G){
Env = TEnv(Args, TNotify::NullNotify);
const TStr Gen = Env.GetIfArgPrefixStr("-g:", "gen", "How to get model graph: read, gen, deg, genpy");
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "Input graph file (single directed edge per line)");
TExeTm execTime;
if (Gen == "gen")
BasicGraphGen(Args, G);
else if (Gen == "read")
ReadPNGraphFromFile(InFNm, G);
else if (Gen == "genpy")
{
PUNGraph GU;
GenPy(GU, TFile, Args);
G = TSnap::ConvertGraph<PNGraph>(GU);
}
TFile << "Time of getting model: " << execTime.GetTmStr() << endl;
/*TFile << "Model graph: " << G->GetNodes() << " nodes, " << G->GetEdges() << " edges\n";
TIntV DegV;
TSnap::GetDegSeqV(G, DegV);
execTime.Tick();
PUNGraph Conf = TSnap::GenConfModel(DegV);
TFile << "Time of getting configuration model: " << execTime.GetTmStr() << endl;
cout << "Undirected configuration model: " << Conf->GetNodes() << " nodes, " << Conf->GetEdges() << " edges\n";
PNGraph ConfD = TSnap::ConvertGraph<PNGraph>(Conf);
SaveAndPlot(ConfD, "conf", false);
TFile << "Clustering coefficient of configuration model: " << TSnap::GetClustCf(ConfD) << endl;
TSnap::PlotClustCf(ConfD,"conf");*/
}
示例10: main
int main(int argc, char* argv[])
{
TExeTm ExeTm;
try
{
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("\nPlotting Scatter For Twitter Cascades. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
// THash< TUInt , TSecTmV > twitterUrls = Tools::loadTwitter("DATA/CascadesFullUrlsOnTwitterData_FINALFILTERED_HAVINGBOTH.rar");
// THash< TUInt , TSecTmV > twitterContents = Tools::loadTwitter("DATA/CascadesOnTwitterData_FINALFILTERED_HAVINGBOTH.rar");
THash< TUInt , TSecTmV > twitterUrls = Tools::loadTwitter("/NS/twitter-5/work/oaskaris/DATA/CascadesFullUrlsOnTwitterData_FINALFILTERED_HAVINGBOTH.rar"); // CascadesFullUrlsOnTwitterData_FINALFILTERED
THash< TUInt , TSecTmV > twitterContents = Tools::loadTwitter("/NS/twitter-5/work/oaskaris/DATA/CascadesOnTwitterData_FINALFILTERED_HAVINGBOTH.rar"); // CascadesOnTwitterData_FINALFILTERED
THash< TUInt , TSecTmV > full_twitterUrls = Tools::loadTwitter("/NS/twitter-5/work/oaskaris/DATA/CascadesFullUrlsOnTwitterData_FINALFILTERED.rar");
THash< TUInt , TSecTmV > full_twitterContents = Tools::loadTwitter("/NS/twitter-5/work/oaskaris/DATA/CascadesOnTwitterData_FINALFILTERED.rar");
// Scatter plot
plotScatterLengthOfEachCascade(twitterUrls,twitterContents);
// Percentage computation
double cnt = 0;
for(int i=0;i<full_twitterUrls.Len();i++)
{
if(full_twitterContents.GetKeyId(full_twitterUrls.GetKey(i)) != -1)
{
cnt++;
}
}
cnt /= full_twitterUrls.Len(); // twitterUrls.Len() / full_twitterUrls.Len()
printf("The percentage of Urls of quotes which have contents as well: %f\n", 100 * cnt);
cnt = 0;
for(int i=0;i<full_twitterContents.Len();i++)
{
if(full_twitterUrls.GetKeyId(full_twitterContents.GetKey(i)) != -1)
{
cnt++;
}
}
cnt /= full_twitterContents.Len();
printf("The percentage of Contents of quotes which have urls as well: %f\n", 100 * cnt);
printf("\nScatter Plot had been drawn successfully.");
}
catch(exception& ex)
{
printf("\nError1 happened, it was: %s\n\n",ex.what());
}
catch(TPt<TExcept>& ex)
{
printf("\nError2 happened: %s\n\n",ex[0].GetStr().CStr());
}
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例11: main
int main(int argc, char* argv[]) {
setbuf(stdout, NULL); // disables the buffer so that print statements are not buffered and display immediately (?)
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Node centrality. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "input network");
const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "output prefix (filename extensions added)");
const TStr BseFNm = OutFNm.RightOfLast('/');
const double eps = Env.GetIfArgPrefixFlt("-eps:", 1.0e-5, "minimum quality improvement threshold");
const double min_moves = Env.GetIfArgPrefixFlt("-moves:", 1.0e-2, "minimum number of moves required (proportional)");
const double max_iters = Env.GetIfArgPrefixFlt("-iters:", 1.0e+4, "maximum number of iterations");
// Load graph and create directed and undirected graphs (pointer to the same memory)
printf("\nLoading %s...", InFNm.CStr());
PFltWNGraph WGraph = TSnap::LoadFltWEdgeList<TWNGraph>(InFNm);
printf(" DONE\n");
printf(" nodes: %d\n", WGraph->GetNodes());
printf(" edges: %d\n", WGraph->GetEdges());
printf(" time elapsed: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
// Declare variables
// COMMUNITY
// TODO
// Louvain method (modularity objective)
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例12: main
int main(int argc, char* argv[])
{
// TFltPrV v;
// v.Add(TFltPr(1,4));
// v.Add(TFltPr(5,5));
// v.Add(TFltPr(9,11));
// v.Add(TFltPr(20,8));
// v.Add(TFltPr(21,30));
// cout << "C: " << Tools::computeCorrelation(v,Pearson) << endl;
// return 0;
TExeTm ExeTm;
try
{
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("\nPlotting Individually Memes-Twitter Cascades. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
// URLS
THash< TStr , CascadeElementV > quotes = Tools::loadQuotes("DATA/QuotesPreprocessedData_NIFTY_RANGEFIXED_FINALFILTERED_HAVINGBOTH.rar"); // QuotesPreprocessedData_NIFTY_RANGEFIXED_FINALFILTERED_4URLS
THash< TUInt , TSecTmV > twitterUrls = Tools::loadTwitter("DATA/CascadesFullUrlsOnTwitterData_FINALFILTERED_HAVINGBOTH.rar"); // CascadesFullUrlsOnTwitterData_FINALFILTERED
// CONTENTS
//THash< TStr , CascadeElementV > quotes2 = Tools::loadQuotes("DATA/QuotesPreprocessedData_NIFTY_RANGEFIXED_FINALFILTERED_HAVINGBOTH.rar"); // QuotesPreprocessedData_NIFTY_RANGEFIXED_FINALFILTERED_4Contents
THash< TUInt , TSecTmV > twitterContents = Tools::loadTwitter("DATA/CascadesOnTwitterData_FINALFILTERED_HAVINGBOTH.rar"); // CascadesOnTwitterData_FINALFILTERED
// Plotting
THash< TUInt , TSecTmV > twitterTotal;
for(int i=0;i<twitterContents.Len();i++)
{
TSecTmV tmp;
tmp.AddV(twitterContents[i]);
tmp.AddV(twitterUrls[i]);
twitterTotal.AddDat(i,tmp);
}
plotScatterLengthOfEachCascade(quotes,twitterUrls,"Urls");
plotScatterLengthOfEachCascade(quotes,twitterContents,"Contents");
plotScatterLengthOfEachCascade(quotes,twitterTotal,"Full");
printf("\nPlots had been drawn successfully.");
}
catch(exception& ex)
{
printf("\nError1 happened, it was: %s\n\n",ex.what());
}
catch(TPt<TExcept>& ex)
{
printf("\nError2 happened: %s\n\n",ex[0].GetStr().CStr());
}
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例13: MLEGradient
int TLogRegFit::MLEGradient(const double& ChangeEps, const int& MaxStep, const TStr PlotNm) {
TExeTm ExeTm;
TFltV GradV(Theta.Len());
int iter = 0;
TIntFltPrV IterLV, IterGradNormV;
double MinVal = -1e10, MaxVal = 1e10;
double GradCutOff = 100000;
for(iter = 0; iter < MaxStep; iter++) {
Gradient(GradV); //if gradient is going out of the boundary, cut off
for(int i = 0; i < Theta.Len(); i++) {
if (GradV[i] < -GradCutOff) {
GradV[i] = -GradCutOff;
}
if (GradV[i] > GradCutOff) {
GradV[i] = GradCutOff;
}
if (Theta[i] <= MinVal && GradV[i] < 0) {
GradV[i] = 0.0;
}
if (Theta[i] >= MaxVal && GradV[i] > 0) {
GradV[i] = 0.0;
}
}
double Alpha = 0.15, Beta = 0.9;
//double LearnRate = 0.1 / (0.1 * iter + 1); //GetStepSizeByLineSearch(GradV, GradV, Alpha, Beta);
double LearnRate = GetStepSizeByLineSearch(GradV, GradV, Alpha, Beta);
if (TLinAlg::Norm(GradV) < ChangeEps) {
break;
}
for(int i = 0; i < Theta.Len(); i++) {
double Change = LearnRate * GradV[i];
Theta[i] += Change;
if(Theta[i] < MinVal) {
Theta[i] = MinVal;
}
if(Theta[i] > MaxVal) {
Theta[i] = MaxVal;
}
}
if (! PlotNm.Empty()) {
double L = Likelihood();
IterLV.Add(TIntFltPr(iter, L));
IterGradNormV.Add(TIntFltPr(iter, TLinAlg::Norm(GradV)));
}
}
if (! PlotNm.Empty()) {
TGnuPlot::PlotValV(IterLV, PlotNm + ".likelihood_Q");
TGnuPlot::PlotValV(IterGradNormV, PlotNm + ".gradnorm_Q");
printf("MLE for Lambda completed with %d iterations(%s)\n",iter,ExeTm.GetTmStr());
}
return iter;
}
示例14: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Motifs. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input directed graph file (single directed edge per line)");
const int MotifSz = Env.GetIfArgPrefixInt("-m:", 3, "Motif size (has to be 3 or 4)");
const bool DrawMotifs = Env.GetIfArgPrefixBool("-d:", true, "Draw motif shapes (requires GraphViz)");
TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file prefix");
if (OutFNm.Empty()) { OutFNm = InFNm.GetFMid(); }
EAssert(MotifSz==3 || MotifSz==4);
// 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); }
bool IsOk = true;
for (int nid = 0; nid < G->GetNodes(); nid++) {
if (! G->IsNode(nid)) { IsOk=false; break; } }
if (! IsOk) {
printf("Nodes of the input graph have to be numbered 0...N-1\nRenumbering nodes...\n");
PNGraph OG = G; G = TNGraph::New();
TGraphEnumUtils::GetNormalizedGraph(OG, G);
}
// G = TSnap::GenRndGnm<PNGraph>(100, Kilo(1));
// count frequency of connected subgraphs in G that have MotifSz nodes
TD34GraphCounter GraphCounter(MotifSz);
TSubGraphEnum<TD34GraphCounter> GraphEnum;
GraphEnum.GetSubGraphs(G, MotifSz, GraphCounter);
FILE *F = fopen(TStr::Fmt("%s-counts.tab", OutFNm.CStr()).CStr(), "wt");
fprintf(F, "MotifId\tNodes\tEdges\tCount\n");
for (int i = 0; i < GraphCounter.Len(); i++) {
const int gid = GraphCounter.GetId(i);
PNGraph SG = GraphCounter.GetGraph(gid);
if (DrawMotifs) {
TGraphViz::Plot(SG, gvlNeato, TStr::Fmt("%s-motif%03d.gif", OutFNm.CStr(), i),
TStr::Fmt("GId:%d Count: %llu", gid, GraphCounter.GetCnt(gid)));
}
fprintf(F, "%d\t%d\t%d\t%llu\n", gid, SG->GetNodes(), SG->GetEdges(), GraphCounter.GetCnt(gid));
}
printf("done.");
fclose(F);
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例15: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Node Centrality. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input un/directed graph");
const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "node_centrality.tab", "Output file");
printf("Loading %s...", InFNm.CStr());
PNGraph Graph = TSnap::LoadEdgeList<PNGraph>(InFNm);
//PNGraph Graph = TSnap::GenRndGnm<PNGraph>(10, 10);
//TGraphViz::Plot(Graph, gvlNeato, InFNm+".gif", InFNm, true);
printf("nodes:%d edges:%d\n", Graph->GetNodes(), Graph->GetEdges());
PUNGraph UGraph = TSnap::ConvertGraph<PUNGraph>(Graph); // undirected version of the graph
TIntFltH BtwH, EigH, PRankH, CcfH, CloseH, HubH, AuthH;
//printf("Computing...\n");
printf("Treat graph as DIRECTED: ");
printf(" PageRank... "); TSnap::GetPageRank(Graph, PRankH, 0.85);
printf(" Hubs&Authorities..."); TSnap::GetHits(Graph, HubH, AuthH);
printf("\nTreat graph as UNDIRECTED: ");
printf(" Eigenvector..."); TSnap::GetEigenVectorCentr(UGraph, EigH);
printf(" Clustering..."); TSnap::GetNodeClustCf(UGraph, CcfH);
printf(" Betweenness (SLOW!)..."); TSnap::GetBetweennessCentr(UGraph, BtwH, 1.0);
printf(" Constraint (SLOW!)..."); TNetConstraint<PUNGraph> NetC(UGraph, true);
printf(" Closeness (SLOW!)...");
for (TUNGraph::TNodeI NI = UGraph->BegNI(); NI < UGraph->EndNI(); NI++) {
const int NId = NI.GetId();
CloseH.AddDat(NId, TSnap::GetClosenessCentr<PUNGraph>(UGraph, NId, false));
}
printf("\nDONE! saving...");
FILE *F = fopen(OutFNm.CStr(), "wt");
fprintf(F,"#Network: %s\n", InFNm.CStr());
fprintf(F,"#Nodes: %d\tEdges: %d\n", Graph->GetNodes(), Graph->GetEdges());
fprintf(F,"#NodeId\tDegree\tCloseness\tBetweennes\tEigenVector\tNetworkConstraint\tClusteringCoefficient\tPageRank\tHubScore\tAuthorityScore\n");
for (TUNGraph::TNodeI NI = UGraph->BegNI(); NI < UGraph->EndNI(); NI++) {
const int NId = NI.GetId();
const double DegCentr = UGraph->GetNI(NId).GetDeg();
const double CloCentr = CloseH.GetDat(NId);
const double BtwCentr = BtwH.GetDat(NId);
const double EigCentr = EigH.GetDat(NId);
const double Constraint = NetC.GetNodeC(NId);
const double ClustCf = CcfH.GetDat(NId);
const double PgrCentr = PRankH.GetDat(NId);
const double HubCentr = HubH.GetDat(NId);
const double AuthCentr = AuthH.GetDat(NId);
fprintf(F, "%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", NId,
DegCentr, CloCentr, BtwCentr, EigCentr, Constraint, ClustCf, PgrCentr, HubCentr, AuthCentr);
}
fclose(F);
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}