8 while (i < lenA && j < lenB) {
17 return ct*1.0/(lenA+lenB-ct);
25 int lenA = list1->
Len();
28 if (lenA > 0 && lenB > 0) {
75 PNGraph Graph = TSnap::ToGraph<PNGraph>(P, S[index_col_1].GetVal1(), S[index_col_2].GetVal1(),
aaFirst);
84 int size = NIdV.
Len();
85 for (
int ind = 0; ind < size; ind++) {
86 KNN->AddNode(NIdV[ind]);
88 KNN->AddFltAttrE(
"sim");
93 int NumThreads = omp_get_max_threads();
94 omp_set_num_threads(NumThreads);
95 #pragma omp parallel private(ThNodeList, ThTopK)
101 #pragma omp for schedule(dynamic,1000)
102 for (
int ind = 0; ind < size; ind++) {
112 for (
int i = 0; i < K; i++) {
116 Neighbors->
Clr(
false);
117 Neighbors_old->
Clr(
false);
119 for (
int i = 0; i < NI.
GetOutDeg(); i++) {
121 MergeNbrs(Neighbors, Neighbors_old, Inst_NI);
123 temp = Neighbors_old;
125 Neighbors_old = Neighbors;
131 temp = Neighbors_old;
132 Neighbors_old = Neighbors;
134 for(
int j = 0; j< Neighbors->
Len(); j++) {
139 if (TopK[K-1].GetVal1() < similarity) {
141 for (
int i = K-2; i >= 0; i--)
142 if (TopK[i].GetVal1() < similarity) {
143 TopK.
SetVal(i+1, TopK[i]);
153 ThNodeList.
Add(NIdV[ind]);
161 for (
int j = 0; j < ThTopK.
Len(); j++) {
162 TopKList.
Add(ThTopK[j]);
163 NodeList.
Add(ThNodeList[j]);
168 int size2 = NodeList.
Len();
169 for (
int i= 0; i < size2 ; i++) {
171 for (
int j = 0; j < K; j++) {
172 if (TopKList[i][j].GetVal2() <= -1) {
175 int EId = KNN->AddEdge(NodeList[i], TopKList[i][j].GetVal2());
176 KNN->AddFltAttrDatE(EId, TopKList[i][j].GetVal1(),
"sim");
186 int sum_neighbors = 0;
195 int size = NIdV.
Len();
196 for (
int ind = 0; ind < size; ind++) {
197 KNN->AddNode(NIdV[ind]);
199 KNN->AddFltAttrE(
"sim");
201 for (
int ind = 0; ind < size; ind++) {
212 for (
int i = 0; i < K; i++) {
216 Neighbors->
Clr(
false);
217 Neighbors_old->
Clr(
false);
219 for (
int i = 0; i < NI.
GetOutDeg(); i++) {
221 MergeNbrs(Neighbors, Neighbors_old, Inst_NI);
223 temp = Neighbors_old;
225 Neighbors_old = Neighbors;
228 int num = Neighbors_old->
Len();
229 sum_neighbors += num;
233 temp = Neighbors_old;
234 Neighbors_old = Neighbors;
236 for (
int j = 0; j< Neighbors->
Len(); j++) {
241 if (TopK[K-1].GetVal1() < similarity) {
243 for (
int i = K-2; i >= 0; i--)
244 if (TopK[i].GetVal1() < similarity) {
245 TopK.
SetVal(i+1, TopK[i]);
254 for (
int i = 0; i < K; i++) {
255 int EId = KNN->AddEdge(NI.
GetId(), TopK[i].GetVal2());
256 KNN->AddFltAttrDatE(EId, TopK[i].GetVal1(),
"sim");
float JaccardSim(TNGraph::TNodeI NI1, TNGraph::TNodeI NI2)
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
PNEANet KNNJaccard(PNGraph Graph, int K)
TSizeTy Len() const
Returns the number of elements in the vector.
int GetNodes() const
Returns the number of nodes in the graph.
void MergeNbrs(TIntV *NeighbourV, TIntV *list1, TNGraph::TNodeI NI2)
PNGraph GetBiGraph(PTable P, int index_col_1, int index_col_2)
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
PNEANet KNNJaccardParallel(PNGraph Graph, int K)
void SetVal(const TSizeTy &ValN, const TVal &Val)
Sets the value of element at position ValN to Val.
int GetId() const
Returns ID of the current node.
int GetOutDeg() const
Returns out-degree of the current node.
Node iterator. Only forward iteration (operator++) is supported.
int GetInDeg() const
Returns in-degree of the current node.
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).