示例#1
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
// 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");
}
示例#2
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
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]; 
    }
  }
}
示例#3
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
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++]; 
    }
  }
}
示例#4
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
void TWgtNet::PutRnd01Wgts() {
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      NI.GetOutEDat(e) = TInt::Rnd.GetUniDev();
    }
  }
}
示例#5
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
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;
    }
  }
}
示例#6
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
/////////////////////////////////////////////////
// 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;
}
示例#7
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
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());
}