Exemplo n.º 1
0
// IN-OUT edges are swapped (so that the prog runs faster)
// Send message via IN edge proportional to the OUT edge weight
void TWgtNet::ReinforceEdges(const int& NIters) {
  THash<TInt, TFlt> OutWgtSumH;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    double wgt = 0;
    for (int e = 0; e < NI.GetOutDeg(); e++) { 
      wgt += NI.GetOutEDat(e); }
    OutWgtSumH.AddDat(NI.GetId(), wgt);
  }
  printf("Reinforcing edges for %d iterations\n", NIters);
  // iterate
  TExeTm ExeTm;
  for (int iter = 0; iter < NIters; iter++) {
    for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
      const double X = TInt::Rnd.GetUniDev() * OutWgtSumH.GetDat(NI.GetId());
      double x = 0;  int e = 0;
      for ( ; x + NI.GetOutEDat(e) < X; e++) {
        x += NI.GetOutEDat(e); }
      IAssert(IsEdge(NI.GetOutNId(e), NI.GetId()));
      GetEDat(NI.GetOutNId(e), NI.GetId()) += 1; // reinforce the edge
      OutWgtSumH.GetDat(NI.GetOutNId(e)) += 1; 
    }
    if (iter % (NIters/100) == 0) {
      printf("\r%d [%s]", iter, ExeTm.GetStr()); 
    }
  }
  printf(" done.\n");
}
Exemplo n.º 2
0
void TWgtNet::PermOutEdgeWgt() {
  TFltV WgtV;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    WgtV.Clr(false);
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      WgtV.Add(NI.GetOutEDat(e)); 
    }
    WgtV.Shuffle(TInt::Rnd);
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      NI.GetOutEDat(e) = WgtV[e]; 
    }
  }
}
Exemplo n.º 3
0
void TWgtNet::PermEdgeWgt() {
  TFltV WgtV;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      WgtV.Add(NI.GetOutEDat(e)); 
    }
  }
  WgtV.Shuffle(TInt::Rnd);
  int w = 0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      NI.GetOutEDat(e) = WgtV[w++]; 
    }
  }
}
Exemplo n.º 4
0
void TWgtNet::PutRnd01Wgts() {
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      NI.GetOutEDat(e) = TInt::Rnd.GetUniDev();
    }
  }
}
Exemplo n.º 5
0
void TWgtNet::MulEdgeWgt(const double& MulBy) {
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      NI.GetOutEDat(e) *= MulBy;
    }
  }
}
Exemplo n.º 6
0
/////////////////////////////////////////////////
// Weighted network
double TWgtNet::GetEdgeWgt() const {
  double wgt = 0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      wgt += NI.GetOutEDat(e);
    }
  }
  return wgt;
}
Exemplo n.º 7
0
void TWgtNet::DelMinWgtNodes(const double MinWgt) {
  printf("Deleting Min Wgt %g nodes\n", MinWgt);
  printf("  (%d,%d)  -->", GetNodes(), GetEdges());
  TIntV DelNIdV;  
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    double wgt = 0;
    for (int e = 0; e < NI.GetOutDeg(); e++) { 
      wgt += NI.GetOutEDat(e);
    }
    if (wgt < MinWgt) { DelNIdV.Add(NI.GetId()); }
  }
  for (int d = 0; d < DelNIdV.Len(); d++) {
    DelNode(DelNIdV[d]);
  }
  printf("  (%d,%d)\n", GetNodes(), GetEdges());
}