SNAP Library 2.2, User Reference  2014-03-11 19:15:55
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"

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.

                                                                                         {
  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);
  }
}
void McMcGetAvgAvg ( const TFltV AvgJV,
double &  AvgAvg 
)

Definition at line 1876 of file kronecker.cpp.

                                                       {
  AvgAvg = 0.0;
  for (int j = 0; j < AvgJV.Len(); j++) {
    AvgAvg += AvgJV[j]; }
  AvgAvg /= AvgJV.Len();
}
void McMcGetAvgJ ( const TVec< TFltV > &  ChainLLV,
TFltV AvgJV 
)

Definition at line 1883 of file kronecker.cpp.

                                                            {
  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());
  }
}
void PlotAutoCorrelation ( const TFltV ValV,
const int &  MaxK,
const TStr OutFNm,
const TStr Desc 
)

Definition at line 1773 of file kronecker.cpp.

                                                                                                   {
  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();
}
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.

                                                                                                                                                        {
  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();
}
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.

                                                                                                                         {
  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();
}