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
circles.h File Reference
#include "stdafx.h"
Include dependency graph for circles.h:

Go to the source code of this file.

Classes

class  TGraphAttributes
class  TCluster

Typedefs

typedef TPt< TGraphAttributesPGraphAttributes
typedef TPt< TClusterPCluster

Enumerations

enum  lossType { zeroOne = 0, balancedError = 1, fScore = 2 }

Functions

TFlt Loss (TIntSet &l, TIntSet lHat, int N, int Which)
 Compute the loss between a GroundTruth cluster l and a predicted cluster lHat.
TFlt Inner (TIntIntH &Feature, TFlt *Parameter)
 Inner product for sparse features.

Typedef Documentation

typedef TPt<TCluster> PCluster

Definition at line 93 of file circles.h.

Definition at line 26 of file circles.h.


Enumeration Type Documentation

enum lossType
Enumerator:
zeroOne 
balancedError 
fScore 

Definition at line 95 of file circles.h.

{
  zeroOne = 0,
  balancedError = 1,
  fScore = 2
};

Function Documentation

TFlt Inner ( TIntIntH Feature,
TFlt Parameter 
)

Inner product for sparse features.

Definition at line 349 of file circles.h.

References THash< TKey, TDat, THashFunc >::BegI(), and THashKeyDatI< TKey, TDat >::IsEnd().

Referenced by TCluster::Gradient(), TCluster::LogLikelihood(), and TCluster::MCMC().

                                               {
  TFlt res = 0;
  for (THashKeyDatI<TInt, TInt> it = Feature.BegI(); not it.IsEnd(); it++) {
    res += it.GetDat() * Parameter[it.GetKey()];
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TFlt Loss ( TIntSet l,
TIntSet  lHat,
int  N,
int  Which 
)

Compute the loss between a GroundTruth cluster l and a predicted cluster lHat.

Definition at line 103 of file circles.h.

References balancedError, THashSet< TKey, THashFunc >::BegI(), THashSet< TKey, THashFunc >::EndI(), fScore, THashSet< TKey, THashFunc >::IsKey(), THashSet< TKey, THashFunc >::Len(), and zeroOne.

{
  if (l.Len() == 0) {
    if (lHat.Len() == 0) {
      return 0;
    }
    return 1.0;
  }
  if (lHat.Len() == 0) {
    if (l.Len() == 0) {
      return 0;
    }
    return 1.0;
  }
  TInt TruePositives = 0;
  TInt FalsePositives = 0;
  TInt FalseNegatives = 0;

  TFlt LabelLoss = 0;
  for (THashSetKeyI<TInt> it = l.BegI(); it != l.EndI(); it ++) {
    int c = it.GetKey();
    if (not lHat.IsKey(c)) {
      // false negative
      FalseNegatives ++;
      if (Which == zeroOne) {
        LabelLoss += 1.0/N;
      }
      else if (Which == balancedError) {
        LabelLoss += 0.5/l.Len();
      }
    }
  }

  for (THashSetKeyI<TInt> it = lHat.BegI(); it != lHat.EndI(); it ++) {
    int c = it.GetKey();
    if (not l.IsKey(c)) {
      // false positive
      FalsePositives ++;
      if (Which == zeroOne) {
        LabelLoss += 1.0/N;
      }
      else if (Which == balancedError) {
        LabelLoss += 0.5/(N - l.Len());
      }
    }
    else {
      TruePositives ++;
    }
  }

  if ((lHat.Len() == 0 or TruePositives == 0) and Which == fScore) {
    return 1.0;
  }
  TFlt precision = (1.0*TruePositives)/lHat.Len();
  TFlt recall = (1.0*TruePositives)/l.Len();
  if (Which == fScore) {
    return 1 - 2 * (precision*recall) / (precision + recall);
  }

  return LabelLoss;
}

Here is the call graph for this function: