SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
kronecker.cpp File Reference
#include "stdafx.h"
#include "kronecker.h"
Include dependency graph for kronecker.cpp:

Go to the source code of this file.

Functions

void GetMinMax (const TFltPrV &XYValV, double &Min, double &Max, const bool &ResetMinMax)
void PlotGrad (const TFltPrV &EstLLV, const TFltPrV &TrueLLV, const TVec< TFltPrV > &GradVV, const TFltPrV &AcceptV, const TStr &OutFNm, const TStr &Desc)
void PlotAutoCorrelation (const TFltV &ValV, const int &MaxK, const TStr &OutFNm, const TStr &Desc)
void McMcGetAvgAvg (const TFltV &AvgJV, double &AvgAvg)
void McMcGetAvgJ (const TVec< TFltV > &ChainLLV, TFltV &AvgJV)
void PlotTrueAndEst (const TStr &OutFNm, const TStr &Desc, const TStr &YLabel, const TFltPrV &EstV, const TFltPrV &TrueV)

Function Documentation

void GetMinMax ( const TFltPrV XYValV,
double &  Min,
double &  Max,
const bool &  ResetMinMax 
)

Definition at line 1732 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Len(), TMath::Mn(), TFlt::Mn, TMath::Mx(), and TFlt::Mx.

Referenced by PlotGrad().

                                                                                         {
  if (ResetMinMax) { Min = TFlt::Mx;  Max = TFlt::Mn; }
  for (int i = 0; i < XYValV.Len(); i++) {
    Min = TMath::Mn(Min, XYValV[i].Val2.Val);
    Max = TMath::Mx(Max, XYValV[i].Val2.Val);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void McMcGetAvgAvg ( const TFltV AvgJV,
double &  AvgAvg 
)

Definition at line 1876 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Len().

Referenced by TKroneckerLL::CalcChainR2().

                                                       {
  AvgAvg = 0.0;
  for (int j = 0; j < AvgJV.Len(); j++) {
    AvgAvg += AvgJV[j]; }
  AvgAvg /= AvgJV.Len();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void McMcGetAvgJ ( const TVec< TFltV > &  ChainLLV,
TFltV AvgJV 
)

Definition at line 1883 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Len().

Referenced by TKroneckerLL::CalcChainR2().

                                                            {
  for (int j = 0; j < ChainLLV.Len(); j++) {
    const TFltV& ChainV = ChainLLV[j];
    double Avg = 0;
    for (int i = 0; i < ChainV.Len(); i++) {
      Avg += ChainV[i];
    }
    AvgJV.Add(Avg/ChainV.Len());
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotAutoCorrelation ( const TFltV ValV,
const int &  MaxK,
const TStr OutFNm,
const TStr Desc 
)

Definition at line 1773 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), TGnuPlot::AddPlot(), TStr::CStr(), TStr::Fmt(), gpwLines, TVec< TVal, TSizeTy >::Len(), TMath::Mn(), TGnuPlot::SavePng(), TGnuPlot::SetXYLabel(), and TMath::Sqr().

Referenced by TKroneckerLL::TestSamplePerm().

                                                                                                   {
  double Avg=0.0, Var=0.0;
  for (int i = 0; i < ValV.Len(); i++) { Avg += ValV[i]; }
  Avg /= (double) ValV.Len();
  for (int i = 0; i < ValV.Len(); i++) { Var += TMath::Sqr(ValV[i]-Avg); }
  TFltPrV ACorrV;
  for (int k = 0; k < TMath::Mn(ValV.Len(), MaxK); k++) {
    double corr = 0.0;
    for (int i = 0; i < ValV.Len() - k; i++) {
      corr += (ValV[i]-Avg)*(ValV[i+k]-Avg);
    }
    ACorrV.Add(TFltPr(k, corr/Var));
  }
  // plot grads
  TGnuPlot GP("sAutoCorr-"+OutFNm, TStr::Fmt("AutoCorrelation (%d samples). %s", ValV.Len(), Desc.CStr()), true);
  GP.AddPlot(ACorrV, gpwLines, "", "linewidth 1");
  GP.SetXYLabel("Lag, k", "Autocorrelation, r_k");
  GP.SavePng();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotGrad ( const TFltPrV EstLLV,
const TFltPrV TrueLLV,
const TVec< TFltPrV > &  GradVV,
const TFltPrV AcceptV,
const TStr OutFNm,
const TStr Desc 
)

Definition at line 1740 of file kronecker.cpp.

References TGnuPlot::AddPlot(), TStr::CStr(), TVec< TVal, TSizeTy >::Empty(), TStr::Fmt(), GetMinMax(), gpwLines, TVec< TVal, TSizeTy >::Len(), TGnuPlot::SavePng(), TGnuPlot::SetXYLabel(), and TGnuPlot::SetYRange().

Referenced by TKroneckerLL::TestSamplePerm().

                                                                                                                                                        {
  double Min, Max, Min1, Max1;
  // plot log-likelihood
  { TGnuPlot GP("sLL-"+OutFNm, TStr::Fmt("Log-likelihood (avg 1k samples). %s", Desc.CStr()), true);
  GP.AddPlot(EstLLV, gpwLines, "Esimated LL", "linewidth 1");
  if (! TrueLLV.Empty()) { GP.AddPlot(TrueLLV, gpwLines, "TRUE LL", "linewidth 1"); }
  //GetMinMax(EstLLV, Min, Max, true);  GetMinMax(TrueLLV, Min, Max, false);
  //GP.SetYRange((int)floor(Min-1), (int)ceil(Max+1));
  GP.SetXYLabel("Sample Index (time)", "Log-likelihood");
  GP.SavePng(); }
  // plot accept
  { TGnuPlot GP("sAcc-"+OutFNm, TStr::Fmt("Pct. accepted rnd moves (over 1k samples). %s", Desc.CStr()), true);
  GP.AddPlot(AcceptV, gpwLines, "Pct accepted swaps", "linewidth 1");
  GP.SetXYLabel("Sample Index (time)", "Pct accept permutation swaps");
  GP.SavePng(); }
  // plot grads
  TGnuPlot GPAll("sGradAll-"+OutFNm, TStr::Fmt("Gradient (avg 1k samples). %s", Desc.CStr()), true);
  GetMinMax(GradVV[0], Min1, Max1, true);
  for (int g = 0; g < GradVV.Len(); g++) {
    GPAll.AddPlot(GradVV[g], gpwLines, TStr::Fmt("param %d", g+1), "linewidth 1");
    GetMinMax(GradVV[g], Min1, Max1, false);
    TGnuPlot GP(TStr::Fmt("sGrad%02d-", g+1)+OutFNm, TStr::Fmt("Gradient (avg 1k samples). %s", Desc.CStr()), true);
    GP.AddPlot(GradVV[g], gpwLines, TStr::Fmt("param id %d", g+1), "linewidth 1");
    GetMinMax(GradVV[g], Min, Max, true);
    GP.SetYRange((int)floor(Min-1), (int)ceil(Max+1));
    GP.SetXYLabel("Sample Index (time)", "Gradient");
    GP.SavePng();
  }
  GPAll.SetYRange((int)floor(Min1-1), (int)ceil(Max1+1));
  GPAll.SetXYLabel("Sample Index (time)", "Gradient");
  GPAll.SavePng();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotTrueAndEst ( const TStr OutFNm,
const TStr Desc,
const TStr YLabel,
const TFltPrV EstV,
const TFltPrV TrueV 
)

Definition at line 2009 of file kronecker.cpp.

References TGnuPlot::AddPlot(), TStr::CStr(), TVec< TVal, TSizeTy >::Empty(), gpwLines, and gpwLinesPoints.

Referenced by TKroneckerLL::GradDescentConvergence().

                                                                                                                         {
  TGnuPlot GP(OutFNm, Desc.CStr(), true);
  GP.AddPlot(EstV, gpwLinesPoints, YLabel, "linewidth 1 pointtype 6 pointsize 1");
  if (! TrueV.Empty()) { GP.AddPlot(TrueV, gpwLines, "TRUE"); }
  GP.SetXYLabel("Gradient descent iterations", YLabel);
  GP.SavePng();
}

Here is the call graph for this function:

Here is the caller graph for this function: