763 time_t InitTime = time(NULL);
771 for (
int i = 0; i <
F.Len(); i++) { NIdxV.
Add(i); }
775 TIntV NewNIDV(ChunkNum * ChunkSize);
776 for (iter = 0; iter < MaxIter; iter++) {
778 for (
int i = 0; i <
F.Len(); i++) {
779 if (NIDOPTV[i] == 0) { NIdxV.Add(i); }
784 #pragma omp parallel for schedule(static, 1)
785 for (
int TIdx = 0; TIdx < ChunkNum; TIdx++) {
787 for (
int ui = TIdx * ChunkSize; ui < (TIdx + 1) * ChunkSize; ui++) {
789 if (ui > NIdxV.Len()) {
continue; }
795 for (
int e = 0; e < UI.
GetDeg(); e++) {
799 CIDSet.AddKey(CI.GetKey());
802 if (CIDSet.Empty()) {
807 if (! CIDSet.IsKey(CI.GetKey())) {
808 CurFU.DelIfKey(CI.GetKey());
812 if (
Norm2(GradV) < 1e-4) { NIDOPTV[u] = 1;
continue; }
814 if (LearnRate == 0.0) { NewNIDV[ui] = -2;
continue; }
815 for (
int ci = 0; ci < GradV.
Len(); ci++) {
816 int CID = GradV.
GetKey(ci);
817 double Change = LearnRate * GradV.
GetDat(CID);
818 double NewFuc = CurFU.IsKey(CID)? CurFU.GetDat(CID) + Change : Change;
822 CurFU.AddDat(CID) = NewFuc;
832 int NumNoChangeGrad = 0;
833 int NumNoChangeStepSize = 0;
834 for (
int ui = 0; ui < NewNIDV.Len(); ui++) {
835 int NewNID = NewNIDV[ui];
836 if (NewNID == -1) { NumNoChangeGrad++;
continue; }
837 if (NewNID == -2) { NumNoChangeStepSize++;
continue; }
842 #pragma omp parallel for
843 for (
int ui = 0; ui < NewNIDV.Len(); ui++) {
844 int NewNID = NewNIDV[ui];
845 if (NewNID < 0) {
continue; }
846 F[NewNID] = NewF[ui];
848 for (
int ui = 0; ui < NewNIDV.Len(); ui++) {
849 int NewNID = NewNIDV[ui];
850 if (NewNID < 0) {
continue; }
856 for (
int ui = 0; ui < NewNIDV.Len(); ui++) {
857 int NewNID = NewNIDV[ui];
858 if (NewNID < 0) {
continue; }
861 for (
int e = 0; e < UI.
GetDeg(); e++) {
866 for (
int i = 0; i < NIDOPTV.Len(); i++) {
if (NIDOPTV[i] == 1) { OPTCnt++; } }
867 if (! PlotNm.
Empty()) {
868 printf(
"\r%d iterations [%s] %d secs", iter * ChunkSize * ChunkNum, ExeTm.
GetTmStr(), int(
TSecTm::GetCurTm().GetAbsSecs() - StartTm));
869 if (PrevL >
TFlt::Mn) { printf(
" (%f) %d g %d s %d OPT", PrevL, NumNoChangeGrad, NumNoChangeStepSize, OPTCnt); }
872 if ((iter - PrevIter) * ChunkSize * ChunkNum >=
G->
GetNodes()) {
875 IterLV.
Add(
TIntFltPr(iter * ChunkSize * ChunkNum, CurL));
876 printf(
"\r%d iterations, Likelihood: %f, Diff: %f [%d secs]", iter, CurL, CurL - PrevL,
int(time(NULL) - InitTime));
878 if (CurL - PrevL <= Thres * fabs(PrevL)) {
886 if (! PlotNm.
Empty()) {
887 printf(
"\nMLE completed with %d iterations(%d secs)\n", iter,
int(
TSecTm::GetCurTm().GetAbsSecs() - StartTm));
890 printf(
"\rMLE completed with %d iterations(%d secs)", iter,
int(time(NULL) - InitTime));
double Norm2(const TIntFltH &UV)
Node iterator. Only forward iteration (operator++) is supported.
const TDat & GetDat(const TKey &Key) const
int GetNodes() const
Returns the number of nodes in the graph.
TPair< TInt, TFlt > TIntFltPr
int GetDeg() const
Returns degree of the current node.
const char * GetTmStr() const
double GetStepSizeByLineSearch(const int UID, const TIntFltH &DeltaV, const TIntFltH &GradV, const double &Alpha, const double &Beta, const int MaxIter=10)
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
unsigned long long uint64
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
double Likelihood(const bool DoParallel=false)
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
void GradientForRow(const int UID, TIntFltH &GradU, const TIntSet &CIDSet)
static void PlotValV(const TVec< TVal1 > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
const TKey & GetKey(const int &KeyId) const
Vector is a sequence TVal objects representing an array that can change in size.