Esempio n. 1
0
/// extract community affiliation from F_uc
void TAGMFast::GetCmtyVV(TVec<TIntV>& CmtyVV, const double Thres, const int MinSz) {
  CmtyVV.Gen(NumComs, 0);
  TIntFltH CIDSumFH(NumComs);
  for (int c = 0; c < SumFV.Len(); c++) {
    CIDSumFH.AddDat(c, SumFV[c]);
  }
  CIDSumFH.SortByDat(false);
  for (int c = 0; c < NumComs; c++) {
    int CID = CIDSumFH.GetKey(c);
    TIntFltH NIDFucH(F.Len() / 10);
    TIntV CmtyV;
    IAssert(SumFV[CID] == CIDSumFH.GetDat(CID));
    if (SumFV[CID] < Thres) { continue; }
    for (int u = 0; u < F.Len(); u++) {
      int NID = u;
      if (! NodesOk) { NID = NIDV[u]; }
      if (GetCom(u, CID) >= Thres) { NIDFucH.AddDat(NID, GetCom(u, CID)); }
    }
    NIDFucH.SortByDat(false);
    NIDFucH.GetKeyV(CmtyV);
    if (CmtyV.Len() >= MinSz) { CmtyVV.Add(CmtyV); }
  }
  if ( NumComs != CmtyVV.Len()) {
    printf("Community vector generated. %d communities are ommitted\n", NumComs.Val - CmtyVV.Len());
  }
}
void TTokenizer::GetTokens(const TStrV& TextV, TVec<TStrV>& TokenVV) const {
	IAssert(TextV.Len() == TokenVV.Len()); // shall we rather say Tokens.Gen(Texts.Len(), 0); ?
	for (int TextN = 0; TextN < TextV.Len(); TextN++) {
		TStrV& TokenV = TokenVV[TextN];
		TokenVV.Gen(32,0); // assume there will be at least 32 tokens, to avoid small resizes
		GetTokens(TextV[TextN], TokenV);
	}
}
Esempio n. 3
0
void TIndex::TQmGixSumWithoutFqMerger<TQmGixItem, TQmGixResItem>::Def(const TQmGixKey& Key,
        TVec<TQmGixItem>& MainV, TVec<TQmGixResItem>& ResV) const {

    ResV.Gen(MainV.Len(), 0);
    for (TQmGixItem& Item : MainV) {
        ResV.Add(TQmGixResItem(Item.Val, 1));
    }
}
Esempio n. 4
0
int main(int argc, char* argv[]) {
	Env = TEnv(argc, argv, TNotify::StdNotify);
	Env.PrepArgs(TStr::Fmt("agmgen. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
	TExeTm ExeTm;
	Try
	const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "DEMO", "Community affiliation data");
	const TStr OutFPrx = Env.GetIfArgPrefixStr("-o:", "agm", "out file name prefix");
	const int RndSeed = Env.GetIfArgPrefixInt("-rs:",10,"Rnd Seed");
	const double DensityCoef= Env.GetIfArgPrefixFlt("-a:",0.6,"Power-law Coefficient a of density (density ~ N^(-a)");
	const double ScaleCoef= Env.GetIfArgPrefixFlt("-c:",1.3,"Scaling Coefficient c of density (density ~ c");

	TRnd Rnd(RndSeed);
	TVec<TIntV> CmtyVV;
	if(InFNm=="DEMO") {
		CmtyVV.Gen(2);
		TIntV NIdV;
		for(int i=0;i<25;i++) {
			TIntV& CmtyV = CmtyVV[0];
			CmtyV.Add(i+1);
		}
		for(int i=15;i<40;i++) {
			TIntV& CmtyV = CmtyVV[1];
			CmtyV.Add(i+1);
		}
	}
	else {
		TVec<TIntV> CmtyVV;
	  TSsParser Ss(InFNm, ssfWhiteSep);
	  while (Ss.Next()) {
			if(Ss.GetFlds()>0) {
				TIntV CmtyV;
				for(int i=0;i<Ss.GetFlds();i++) {
					if(Ss.IsInt(i)){CmtyV.Add(Ss.GetInt(i));}
				}
				CmtyVV.Add(CmtyV);
			}
	  }
		printf("community loading completed (%d communities)\n",CmtyVV.Len());
	}
	PUNGraph AG = TAGM::GenAGM(CmtyVV,DensityCoef,ScaleCoef,Rnd);
	TSnap::SaveEdgeList(AG,OutFPrx + ".edgelist.txt");
	if(AG->GetNodes()<50) {
		TAGM::GVizComGraph(AG,CmtyVV,OutFPrx + ".graph.gif");
	}
	Catch
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
}
void TPartialGS::GetBasisV(TVec<TFltV>& q) {
    const int l = R.Len();

    q.Gen(l);
    for (int i = 0; i < l; i++) {
        q[i].Gen(l); 
        q[i].PutAll(0.0);
    }

    for (int n = 0; n < l; n++) {
        double Rnn = R[n][0];
        for (int j = 0; j < n; j++) {
            TLinAlg::AddVec(-R[j][n-j]/Rnn, q[j], q[n], q[n]);
        }
        q[n][n] = 1/Rnn;
    }
}
Esempio n. 6
0
void TGnuPlot::LoadTs(const TStr& FNm, TStrV& ColNmV, TVec<TFltKdV>& ColV) {
  PSs Ss = TSs::LoadTxt(ssfTabSep, FNm);
  int row = 0;
  ColNmV.Clr();
  while (Ss->At(0, row)[0] == '#') { row++; }
  for (int c = 1; c < Ss->GetXLen(row); c+=2) {
    ColNmV.Add(Ss->At(c, row));
  }
  row++;
  ColV.Gen(ColNmV.Len(), ColNmV.Len());
  for (; row < Ss->GetYLen(); row++) {
    for (int c = 0; c < Ss->GetXLen(row); c+=2) {
      if (Ss->At(c,row).Empty()) break;
      ColV[c/2].Add(TFltKd(Ss->At(c,row).GetFlt(), Ss->At(c+1,row).GetFlt()));
    }
  }
}
Esempio n. 7
0
/// load bipartite community affiliation graph from text file (each row contains the member node IDs for each community)
void TAGMUtil::LoadCmtyVV(const TStr& InFNm, TVec<TIntV>& CmtyVV) {
    CmtyVV.Gen(Kilo(100), 0);
    TSsParser Ss(InFNm, ssfWhiteSep);
    while (Ss.Next()) {
        if(Ss.GetFlds() > 0) {
            TIntV CmtyV;
            for (int i = 0; i < Ss.GetFlds(); i++) {
                if (Ss.IsInt(i)) {
                    CmtyV.Add(Ss.GetInt(i));
                }
            }
            CmtyVV.Add(CmtyV);
        }
    }
    CmtyVV.Pack();
    printf("community loading completed (%d communities)\n",CmtyVV.Len());

}
Esempio n. 8
0
File: mkcca.cpp Progetto: Accio/snap
void TMKCCASemSpace::CalcKCCA(const TVec<TBowMatrix>& BowMatrixV, const int& Dims, 
        const double& Kapa, const int& CGMxIter, const int& HorstMxIter, 
        TVec<TFltVV>& AlphaVV) {

    // some basic constants
    const int Langs = BowMatrixV.Len();
    IAssert(Langs > 1);
    const int Docs = BowMatrixV[0].GetCols();
    // reservate space on the output
    AlphaVV.Gen(Langs);
    for (int LangN = 0; LangN < Langs; LangN++) {
        IAssert(BowMatrixV[LangN].GetCols() == Docs);
        AlphaVV[LangN].Gen(Docs, Dims);
        AlphaVV[LangN].PutAll(0.0);
    }

    // par vektorjev
    TFltV x(Docs);  // vektor dolzine docs
    TLAMisc::FillRnd(x, TRnd(1)); // napolnemo z random elementi
    TLinAlg::Normalize(x); // normiramo vektor
    TFltV y(BowMatrixV[1].GetRows()); // nek vektor
    // spreminanje elemnta v matriki
    AlphaVV[1](5,4) = 4.43;
    // skalarni produkt 5 stolpca matrike alphaVV[1] z vektorjem x
    TLinAlg::DotProduct(AlphaVV[1], 5, x);
    // pristeje 0.4 * prvi stolpec drugemu stoplcu
    TLinAlg::AddVec(0.4, AlphaVV[1], 0, AlphaVV[1], 1);
    // pristeje 0.4 * prvi stoplec vektorju x
    TLinAlg::AddVec(0.4, AlphaVV[1], 0, x);
    // naracunamo normo petega stoplca
    double Norm = TLinAlg::Norm(AlphaVV[1], 5);
    // preberemo cetrto vrstico matrike
    TFltV z; AlphaVV[1].GetRow(4, z);
    // preberemo cetrti stoplec matrike
    TFltV zz; AlphaVV[1].GetCol(4, zz);
    // mnozimo vektor x z matriko BowMatrixV[1]
    BowMatrixV[1].Multiply(x, y);
    BowMatrixV[1].MultiplyT(y, x);
    BowMatrixV[1].Multiply(AlphaVV[1], 0, y);
}
Esempio n. 9
0
void TStrFeatureSpace::GetAddIdFreqs(const TStrV& Features,  TVec<TKeyDat<TStrFSSize, TInt> >& IdFreqs) {
	TIntH Freqs;
	for (int i = 0; i < Features.Len(); i++) {
		int Id = GetAddId(Features[i]);

		TInt Freq = 0;
		if (Freqs.IsKeyGetDat(Id, Freq)) {
			Freqs.AddDat(Id, Freq + 1);
		} else {
			Freqs.AddDat(Id, 1);
		}
	}

	IdFreqs.Gen(Freqs.Len());
	for (int i = 0; i < Freqs.Len(); i++) {
		TInt Key, Freq;
		Freqs.GetKeyDat(i, Key, Freq);
		IdFreqs[i].Key = Key;
		IdFreqs[i].Dat = Freq;
	}
	IdFreqs.Sort();
}
Esempio n. 10
0
void TStrFeatureSpace::GetIdFreqs(const TVec<const char *>& Features,  TVec<TKeyDat<TStrFSSize, TInt> >& IdFreqs) const {
	TIntH Freqs;
	for (int i = 0; i < Features.Len(); i++) {
		TInt Id;
		if (GetIfExistsId(Features[i], Id)) {
			TInt Freq = 0;
			if (Freqs.IsKeyGetDat(Id, Freq)) {
				Freqs.AddDat(Id, Freq + 1);
			} else {
				Freqs.AddDat(Id, 1);
			}
		}
	}

	IdFreqs.Gen(Freqs.Len());
	for (int i = 0; i < Freqs.Len(); i++) {
		TInt Key, Freq;
		Freqs.GetKeyDat(i, Key, Freq);
		IdFreqs[i].Key = Key;
		IdFreqs[i].Dat = Freq;
	}
	IdFreqs.Sort();
}
Esempio n. 11
0
void TGraphEnumUtils::GetIsoGraphs(const PNGraph &G, TVec<PNGraph> &isoG) {
	int nodes = G->GetNodes();
	//
	TIntV v(nodes); for(int i=0; i<nodes; i++) v[i]=i;
	TVec<TIntV> perms; GetPermutations(v, 0, perms);
	isoG.Gen(perms.Len());
	//
	for(int i=0; i<perms.Len(); i++) {
		isoG[i] = TNGraph::New();
		//Add nodes
		for(int j=0; j<nodes; j++) isoG[i]->AddNode(j);
		//Add edges
		for(TNGraph::TEdgeI eIt=G->BegEI(); eIt<G->EndEI(); eIt++) {
			int srcId = eIt.GetSrcNId();
			int dstId = eIt.GetDstNId();
			//
			int pSrcId = perms[i][srcId];
			int pDstId = perms[i][dstId];
			//
			isoG[i]->AddEdge(pSrcId, pDstId);
		}
	}
}
Esempio n. 12
0
void TAGMFit::GetCmtyVV(TVec<TIntV>& CmtyVV, TFltV& QV, const double QMax) {
  CmtyVV.Gen(CIDNSetV.Len(), 0);
  QV.Gen(CIDNSetV.Len(), 0);
  TIntFltH CIDLambdaH(CIDNSetV.Len());
  for (int c = 0; c < CIDNSetV.Len(); c++) {
    CIDLambdaH.AddDat(c, LambdaV[c]);
  }
  CIDLambdaH.SortByDat(false);
  for (int c = 0; c < CIDNSetV.Len(); c++) {
    int CID = CIDLambdaH.GetKey(c);
    IAssert(LambdaV[CID] >= MinLambda);
    double Q = exp( - (double) LambdaV[CID]);
    if (Q > QMax) { continue; }
    TIntV CmtyV;
    CIDNSetV[CID].GetKeyV(CmtyV);
    if (CmtyV.Len() == 0) { continue; }
    if (CID == BaseCID) { //if the community is the base community(epsilon community), discard
      IAssert(CmtyV.Len() == G->GetNodes());
    } else {
      CmtyVV.Add(CmtyV);
      QV.Add(Q);
    }
  }
}
Esempio n. 13
0
void TCliqueOverlap::CalculateOverlapMtx(const TVec<TIntV>& MaxCliques, int MinNodeOverlap, TVec<TIntV>& OverlapMtx) {
	OverlapMtx.Clr();
	//
	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
	n = cliques.Len();
	OverlapMtx.Gen(n);
	for (int i=0; i<n; i++) OverlapMtx[i].Gen(n);
	//Calculate clique clique overlap matrix
  for (int i=0; i<n; i++) {
    OverlapMtx[i][i] = cliques[i].Len();
    for (int j=i+1; j<n; j++) {
      OverlapMtx[i][j] = Intersection(cliques[i], cliques[j]); }
  }
}
Esempio n. 14
0
void TGraphEnumUtils::GetIsoGraphs(uint64 graphId, int nodes, TVec<PNGraph> &isoG) {
	TIntV v(nodes); for(int i=0; i<nodes; i++) v[i]=i;
	TVec<TIntV> perms; GetPermutations(v, 0, perms);
	isoG.Gen(perms.Len());
	//
	TVec<TPair<int,int> > edges;
	GetEdges(graphId, nodes, edges);
	//
	for(int i=0; i<perms.Len(); i++) {
		isoG[i] = TNGraph::New();
		//Add nodes
		for(int j=0; j<nodes; j++) isoG[i]->AddNode(j);
		//Add edges
		for(int j=0; j<edges.Len(); j++) {
			int srcId = edges[j].Val1;
			int dstId = edges[j].Val2;
			//
			int pSrcId = perms[i][srcId];
			int pDstId = perms[i][dstId];
			//
			isoG[i]->AddEdge(pSrcId, pDstId);
		}
	}
}