本文整理汇总了C++中TIntV::Len方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntV::Len方法的具体用法?C++ TIntV::Len怎么用?C++ TIntV::Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntV
的用法示例。
在下文中一共展示了TIntV::Len方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PutBlockLenV
void TBlobBs::PutBlockLenV(const PFRnd& FBlobBs, const TIntV& BlockLenV){
FBlobBs->PutStr(BlockLenVNm);
FBlobBs->PutInt(BlockLenV.Len());
for (int BlockLenN=0; BlockLenN<BlockLenV.Len(); BlockLenN++){
FBlobBs->PutInt(BlockLenV[BlockLenN]);}
FBlobBs->PutInt(-1);
}
示例2: ElCheapoHashing
void LSH::ElCheapoHashing(TQuoteBase *QuoteBase, TInt ShingleLen,
THash<TMd5Sig, TIntSet>& ShingleToQuoteIds) {
fprintf(stderr, "Hashing shingles the el cheapo way...\n");
TIntV QuoteIds;
QuoteBase->GetAllQuoteIds(QuoteIds);
for (int qt = 0; qt < QuoteIds.Len(); qt++) {
if (qt % 1000 == 0) {
fprintf(stderr, "%d out of %d completed\n", qt, QuoteIds.Len());
}
TQuote Q;
QuoteBase->GetQuote(QuoteIds[qt], Q);
// Put x-character (or x-word) shingles into hash table; x is specified by ShingleLen parameter
TStr QContentStr;
Q.GetParsedContentString(QContentStr);
TChA QContentChA = TChA(QContentStr);
for (int i = 0; i < QContentChA.Len() - ShingleLen + 1; i++) {
TChA ShingleChA = TChA();
for (int j = 0; j < ShingleLen; j++) {
ShingleChA.AddCh(QContentChA.GetCh(i + j));
}
TStr Shingle = TStr(ShingleChA);
const TMd5Sig ShingleMd5(Shingle);
TIntSet ShingleQuoteIds;
if (ShingleToQuoteIds.IsKey(ShingleMd5)) {
ShingleQuoteIds = ShingleToQuoteIds.GetDat(ShingleMd5);
}
ShingleQuoteIds.AddKey(QuoteIds[qt]);
ShingleToQuoteIds.AddDat(ShingleMd5, ShingleQuoteIds);
}
}
Err("Done with el cheapo hashing!\n");
}
示例3: GetNmObjDIdV
void TNmObjBs::GetNmObjDIdV(
const PBowDocBs& BowDocBs, TIntV& BowDIdV,
const TStr& NmObjStr1, const TStr& NmObjStr2) const {
// get first named-object-id
int NmObjId1=GetNmObjId(NmObjStr1);
TIntV NmObjDocIdV1; GetNmObjDocIdV(NmObjId1, NmObjDocIdV1);
NmObjDocIdV1.Sort();
// get second named-object-id
TIntV NmObjDocIdV2;
if (!NmObjStr2.Empty()){
int NmObjId2=GetNmObjId(NmObjStr2);
GetNmObjDocIdV(NmObjId2, NmObjDocIdV2);
NmObjDocIdV2.Sort();
}
// create joint doc-id-vector
TIntV NmObjDocIdV;
if (NmObjDocIdV2.Empty()){
NmObjDocIdV=NmObjDocIdV1;
} else {
NmObjDocIdV1.Intrs(NmObjDocIdV2, NmObjDocIdV);
}
// traverse named-object-documents to collect bow-document-ids
BowDIdV.Gen(NmObjDocIdV.Len(), 0);
for (int NmObjDocIdN=0; NmObjDocIdN<NmObjDocIdV.Len(); NmObjDocIdN++){
TStr DocNm=GetDocNm(NmObjDocIdV[NmObjDocIdN]);
int DId=BowDocBs->GetDId(DocNm);
if (DId!=-1){
BowDIdV.Add(DId);
}
}
}
示例4: AddPlot
int TGnuPlot::AddPlot(const TIntV& 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);
}
示例5: CalcPNoComByCmtyVV
// Compute the empirical edge probability between a pair of nodes who share no community (epsilon), based on current community affiliations.
double TAGMFit::CalcPNoComByCmtyVV(const int& SamplePairs) {
TIntV NIdV;
G->GetNIdV(NIdV);
uint64 PairNoCom = 0, EdgesNoCom = 0;
for (int u = 0; u < NIdV.Len(); u++) {
for (int v = u + 1; v < NIdV.Len(); v++) {
int SrcNID = NIdV[u], DstNID = NIdV[v];
TIntSet JointCom;
TAGMUtil::GetIntersection(NIDComVH.GetDat(SrcNID),NIDComVH.GetDat(DstNID),JointCom);
if(JointCom.Len() == 0) {
PairNoCom++;
if (G->IsEdge(SrcNID, DstNID)) { EdgesNoCom++; }
if (SamplePairs > 0 && PairNoCom >= (uint64) SamplePairs) { break; }
}
}
if (SamplePairs > 0 && PairNoCom >= (uint64) SamplePairs) { break; }
}
double DefaultVal = 1.0 / (double)G->GetNodes() / (double)G->GetNodes();
if (EdgesNoCom > 0) {
PNoCom = (double) EdgesNoCom / (double) PairNoCom;
} else {
PNoCom = DefaultVal;
}
printf("%s / %s edges without joint com detected (PNoCom = %f)\n", TUInt64::GetStr(EdgesNoCom).CStr(), TUInt64::GetStr(PairNoCom).CStr(), PNoCom.Val);
return PNoCom;
}
示例6: GetCommon
// Eric #4
//Count Triangles time (elapsed): 166.162323, cpu: 2048.942704
//Count Triangles time (elapsed): 159.984497, cpu: 1769.572704
//Count Triangles time (elapsed): 167.080368, cpu: 1727.222704
int GetCommon(TIntV& A, TIntV& B) {
int ret = 0;
int i = 0;
int j = 0;
int alen, blen;
alen = A.Len();
blen = B.Len();
while (i < alen && j < blen) {
while (i < alen && A[i] < B[j]) {
i++;
}
// Optional check
if (i == alen) {
break;
}
while (j < blen && A[i] > B[j]) {
j++;
}
// Optional check
if (j == blen) {
break;
}
if (A[i] == B[j]) {
ret++;
i++;
j++;
}
}
return ret;
}
示例7: GetSubGraphMocked
int TMultimodalGraphImplB::GetSubGraphMocked(const TIntV ModeIds) const {
int NumVerticesAndEdges = 0;
for (THash<TInt,TInt>::TIter CurI = NodeToModeMapping.BegI(); CurI < NodeToModeMapping.EndI(); CurI++) {
if (ModeIds.IsIn(CurI.GetDat())) {
NumVerticesAndEdges++;
}
}
for (int ModeIdx1 = 0; ModeIdx1 < ModeIds.Len(); ModeIdx1++) {
int ModeId1 = ModeIds.GetVal(ModeIdx1);
for (int ModeIdx2 = 0; ModeIdx2 < ModeIds.Len(); ModeIdx2++) {
int ModeId2 = ModeIds.GetVal(ModeIdx2);
TPair<TInt,TInt> ModeIdsKey = GetModeIdsKey(ModeId1, ModeId2);
if (!Graphs.IsKey(ModeIdsKey)) { continue; }
const TNGraph& Graph = Graphs.GetDat(ModeIdsKey);
for (TNGraph::TNodeI it = Graph.BegNI(); it < Graph.EndNI(); it++) {
for (int e = 0; e < it.GetOutDeg(); e++) {
NumVerticesAndEdges += it.GetOutNId(e);
}
}
}
}
return NumVerticesAndEdges;
}
示例8: PutMergedNmObj
void TNmObjBs::PutMergedNmObj(const TIntV& NewNmObjIdV){
// create temporary table of new named-objects
TStrVIntVH NewNmObjWordStrVToDocIdVH;
for (int NmObjId=0; NmObjId<NewNmObjIdV.Len(); NmObjId++){
if (NewNmObjIdV[NmObjId]!=NmObjId){continue;}
// take data for new named-object from old definition
const TStrV& WordStrV=NmObjWordStrVToDocIdVH.GetKey(NmObjId);
// define new named-object
NewNmObjWordStrVToDocIdVH.AddDat(WordStrV);
}
//printf("Old Named-Objects: %d\n", NmObjWordStrVToDocIdVH.Len());
//printf("New Named-Objects: %d\n", NewNmObjWordStrVToDocIdVH.Len());
// obsolete named-object define as aliases
{for (int NmObjId=0; NmObjId<NewNmObjIdV.Len(); NmObjId++){
if (NewNmObjIdV[NmObjId]==NmObjId){continue;}
// take data for obsolete named-object from old definition
const TStrV& WordStrV=NmObjWordStrVToDocIdVH.GetKey(NmObjId);
// define alias for obsolete named-object
int NrNmObjId=NewNmObjIdV[NmObjId];
if (NrNmObjId!=-1){
const TStrV& NrWordStrV=NmObjWordStrVToDocIdVH.GetKey(NrNmObjId);
NmObjWordStrVToNrH.AddDat(WordStrV, NrWordStrV);
}
}}
// redefine documents
int Docs=GetDocs();
for (int DocId=0; DocId<Docs; DocId++){
TIntPrV& NmObjIdFqPrV=GetDoc_NmObjIdFqPrV(DocId);
// create temporary-document: new-named-object to frequency table
TIntIntH NewNmObjIdToFqH(NmObjIdFqPrV.Len());
for (int NmObjN=0; NmObjN<NmObjIdFqPrV.Len(); NmObjN++){
// get obsolete named-object data
int NmObjId=NmObjIdFqPrV[NmObjN].Val1;
int Fq=NmObjIdFqPrV[NmObjN].Val2;
// get named-document-id for normalized named-object
int NrNmObjId=NewNmObjIdV[NmObjId];
if (NrNmObjId!=-1){
// get normalized version of word-vector
const TStrV& NrWordStrV=NmObjWordStrVToDocIdVH.GetKey(NrNmObjId);
// get new named-object-id
int NewNmObjId=NewNmObjWordStrVToDocIdVH.GetKeyId(NrWordStrV);
// add new named-object-id and term-frequency to temporary-document
NewNmObjIdToFqH.AddDat(NewNmObjId)+=Fq;
}
}
// transfere new-named-object data to document
NmObjIdFqPrV.Gen(NewNmObjIdToFqH.Len(), 0);
for (int NmObjP=0; NmObjP<NewNmObjIdToFqH.Len(); NmObjP++){
int NewNmObjId=NewNmObjIdToFqH.GetKey(NmObjP);
int Fq=NewNmObjIdToFqH[NmObjP];
// add named-object and increment by term-frequency
NmObjIdFqPrV.Add(TIntPr(NewNmObjId, Fq));
// merge document-ids
NewNmObjWordStrVToDocIdVH[NewNmObjId].Add(DocId);
}
NmObjIdFqPrV.Sort();
}
// assign new named-objects
NmObjWordStrVToDocIdVH=NewNmObjWordStrVToDocIdVH;
}
示例9: v
double TStringKernel::KTrie2(const TIntV& s, const TIntV& t, const double& lb, const int& p, int m, const int& AlphN) {
int ls = s.Len(), lt = t.Len();
if (ls < p || lt < p) return 0.0;
m = TInt::GetMn(m, ls-p, lt-p);
TVec<TVec<TTrieNodeP> > LsV(AlphN), LtV(AlphN);
TIntV v(p), x(p+m); double Kern = 0.0;
// precalculate weights
TFltV lbV(m+1); lbV[0] = 1;
for (int i = 0; i < p; i++) lbV[0] *= lb;
for (int i = 1; i <= m; i++) lbV[i] = lb * lbV[i-1];
for (int i = 0; i <= ls - p; i++) {
int j = TInt::GetMn(ls, i+p+m);
LsV[s[i]].Add(TTrieNodeP(TIntPr(i, j-i), 0, 0)); // i == 0 becasue strings start with 0 (not 1 as in Matlab!)
}
for (int i = 0; i <= lt - p; i++) {
int j = TInt::GetMn(lt, i+p+m);
LtV[t[i]].Add(TTrieNodeP(TIntPr(i, j-i), 0, 0)); // i == 0 becasue strings start with 0 (not 1 as in Matlab!)
}
for (int AlphC = 0; AlphC < AlphN; AlphC++) {
v[0] = AlphC;
KTrieR2(s, t, LsV[AlphC], LtV[AlphC], v, 1, Kern, lbV, p, m, AlphN); //depth == 1, not 0 !!!!
}
return Kern;
}
示例10: GetSubGraph
TIntNNet TMultimodalGraphImplB::GetSubGraph(const TIntV ModeIds) const {
TIntNNet SubGraph = TIntNNet();
for (THash<TInt,TInt>::TIter CurI = NodeToModeMapping.BegI(); CurI < NodeToModeMapping.EndI(); CurI++) {
if (ModeIds.IsIn(CurI.GetDat())) {
SubGraph.AddNode(CurI.GetKey(), CurI.GetDat());
}
}
for (int ModeIdx1 = 0; ModeIdx1 < ModeIds.Len(); ModeIdx1++) {
int ModeId1 = ModeIds.GetVal(ModeIdx1);
for (int ModeIdx2 = 0; ModeIdx2 < ModeIds.Len(); ModeIdx2++) {
int ModeId2 = ModeIds.GetVal(ModeIdx2);
TPair<TInt,TInt> ModeIdsKey = GetModeIdsKey(ModeId1, ModeId2);
if (!Graphs.IsKey(ModeIdsKey)) { continue; }
const TNGraph& Graph = Graphs.GetDat(ModeIdsKey);
for (TNGraph::TNodeI it = Graph.BegNI(); it < Graph.EndNI(); it++) {
for (int e = 0; e < it.GetOutDeg(); e++) {
SubGraph.AddEdge(it.GetId(), it.GetOutNId(e));
}
}
}
}
printf("Number of nodes in SubGraph: %d...\n", SubGraph.GetNodes());
printf("Number of edges in SubGraph: %d...\n", SubGraph.GetEdges());
return SubGraph;
}
示例11: PrintClusterInformationToText
void LogOutput::PrintClusterInformationToText(TDocBase *DB, TQuoteBase *QB, TClusterBase *CB, TIntV& ClusterIds, TSecTm PresentTime) {
if (!ShouldLog) return;
TStr CurDateString = PresentTime.GetDtYmdStr();
TStr TopFileName = Directory + "/text/top/topclusters_" + CurDateString + ".txt";
FILE *T = fopen(TopFileName.CStr(), "w");
for (int i = 0; i < ClusterIds.Len(); i++) {
TCluster C;
CB->GetCluster(ClusterIds[i], C);
TStr CRepQuote;
C.GetRepresentativeQuoteString(CRepQuote, QB);
TIntV CQuoteIds;
TVec<TUInt> CUniqueSources;
C.GetQuoteIds(CQuoteIds);
TCluster::GetUniqueSources(CUniqueSources, CQuoteIds, QB);
fprintf(T, "%d\t%d\t%s\n", CUniqueSources.Len(), CQuoteIds.Len(), CRepQuote.CStr());
for (int j = 0; j < CQuoteIds.Len(); j++) {
TQuote Q;
if (QB->GetQuote(CQuoteIds[j], Q)) {
TStr QuoteStr;
Q.GetContentString(QuoteStr);
fprintf(T, "\t%d\t%s\n", Q.GetNumSources().Val, QuoteStr.CStr());
}
}
}
fclose(T);
}
示例12: HashShinglesOfClusters
/// Shingles by words
void LSH::HashShinglesOfClusters(TQuoteBase *QuoteBase,
TClusterBase *ClusterBase, TIntV& ClusterIds, TInt ShingleLen,
THash<TMd5Sig, TIntV>& ShingleToClusterIds) {
Err("Hashing shingles of clusters...\n");
for (int i = 0; i < ClusterIds.Len(); i++) {
if (i % 1000 == 0) {
fprintf(stderr, "%d out of %d completed\n", i, ClusterIds.Len());
}
TCluster C;
ClusterBase->GetCluster(ClusterIds[i], C);
//fprintf(stderr, "%d vs. %d\n", ClusterIds[i].Val, C.GetId().Val);
// Put x-word shingles into hash table; x is specified by ShingleLen parameter
THashSet < TMd5Sig > CHashedShingles;
GetHashedShinglesOfCluster(QuoteBase, C, ShingleLen, CHashedShingles);
for (THashSet<TMd5Sig>::TIter Hash = CHashedShingles.BegI();
Hash < CHashedShingles.EndI(); Hash++) {
TIntV ShingleClusterIds;
if (ShingleToClusterIds.IsKey(*Hash)) {
ShingleClusterIds = ShingleToClusterIds.GetDat(*Hash);
}
ShingleClusterIds.Add(ClusterIds[i]);
ShingleToClusterIds.AddDat(*Hash, ShingleClusterIds);
}
}
Err("Done hashing!\n");
}
示例13: PrintClusterInformation
void LogOutput::PrintClusterInformation(TDocBase *DB, TQuoteBase *QB, TClusterBase *CB, PNGraph& QGraph, TIntV& ClusterIds, TSecTm PresentTime, TIntV &OldTopClusters) {
if (!ShouldLog) return;
TStr CurDateString = PresentTime.GetDtYmdStr();
Err("Writing cluster information...\n");
// PREVIOUS RANKING SETUP
THash<TInt, TInt> OldRankings;
if (OldTopClusters.Len() > 0) {
for (int i = 0; i < OldTopClusters.Len(); i++) {
OldRankings.AddDat(OldTopClusters[i], i + 1);
}
}
TStrV RankStr;
TStr ClusterJSONDirectory = Directory + "/web/json/clusters/";
for (int i = 0; i < ClusterIds.Len(); i++) {
TStr OldRankStr;
ComputeOldRankString(OldRankings, ClusterIds[i], i+1, OldRankStr);
RankStr.Add(OldRankStr);
// JSON file for each cluster!
TPrintJson::PrintClusterJSON(QB, DB, CB, QGraph, ClusterJSONDirectory, ClusterIds[i], PresentTime);
}
Err("JSON Files for individual written!\n");
TStr JSONTableFileName = Directory + "/web/json/daily/" + CurDateString + ".json";
TPrintJson::PrintClusterTableJSON(QB, DB, CB, JSONTableFileName, ClusterIds, RankStr);
Err("JSON Files for the cluster table written!\n");
}
示例14: while
TVec<TPair<TFltV, TFltV> > TLSHash::GetAllCandidatePairs() {
THashSet<TPair<TInt, TInt> > CandidateIdPairs;
for (int i=0; i<Bands; i++) {
TVec<TIntV> BucketVV;
SigBucketVHV[i].GetDatV(BucketVV);
for (int j=0; j<BucketVV.Len(); j++) {
TIntV BucketV = BucketVV[j];
for (int k=0; k<BucketV.Len(); k++) {
for (int l=k+1; l<BucketV.Len(); l++) {
int First = BucketV[k], Second = BucketV[l];
if (First > Second) {
int Temp = First;
First = Second;
Second = Temp;
}
CandidateIdPairs.AddKey(TPair<TInt, TInt> (First, Second));
}
}
}
}
TVec<TPair<TFltV, TFltV> > CandidatePairs;
int Ind = CandidateIdPairs.FFirstKeyId();
while (CandidateIdPairs.FNextKeyId(Ind)) {
TPair<TInt, TInt> IdPair = CandidateIdPairs[Ind];
TPair<TFltV, TFltV> Pair(DataV[IdPair.GetVal1()], DataV[IdPair.GetVal2()]);
CandidatePairs.Add(Pair);
}
return CandidatePairs;
}
示例15: InitializeCounters
void StarTriad3TEdgeCounter<EdgeData>::Count(const TVec<EdgeData>& events,
const TIntV& timestamps, double delta) {
InitializeCounters();
if (events.Len() != timestamps.Len()) {
TExcept::Throw("Number of events must match number of timestamps.");
}
int start = 0;
int end = 0;
int L = timestamps.Len();
for (int j = 0; j < L; j++) {
double tj = double(timestamps[j]);
// Adjust counts in pre-window [tj - delta, tj)
while (start < L && double(timestamps[start]) < tj - delta) {
PopPre(events[start]);
start++;
}
// Adjust counts in post-window (tj, tj + delta]
while (end < L && double(timestamps[end]) <= tj + delta) {
PushPos(events[end]);
end++;
}
// Move current event off post-window
PopPos(events[j]);
ProcessCurrent(events[j]);
PushPre(events[j]);
}
}