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
circles.h File Reference
#include "stdafx.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.

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

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