SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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. More...
 
TFlt Inner (TIntIntH &Feature, TFlt *Parameter)
 Inner product for sparse features. More...
 

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.

96 {
97  zeroOne = 0,
98  balancedError = 1,
99  fScore = 2
100 };
Definition: circles.h:99

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().

349  {
350  TFlt res = 0;
351  for (THashKeyDatI<TInt, TInt> it = Feature.BegI(); not it.IsEnd(); it++) {
352  res += it.GetDat() * Parameter[it.GetKey()];
353  }
354  return res;
355 }
TIter BegI() const
Definition: hash.h:171
Definition: dt.h:1289
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
Definition: hash.h:69

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.

104 {
105  if (l.Len() == 0) {
106  if (lHat.Len() == 0) {
107  return 0;
108  }
109  return 1.0;
110  }
111  if (lHat.Len() == 0) {
112  if (l.Len() == 0) {
113  return 0;
114  }
115  return 1.0;
116  }
117  TInt TruePositives = 0;
118  TInt FalsePositives = 0;
119  TInt FalseNegatives = 0;
120 
121  TFlt LabelLoss = 0;
122  for (THashSetKeyI<TInt> it = l.BegI(); it != l.EndI(); it ++) {
123  int c = it.GetKey();
124  if (not lHat.IsKey(c)) {
125  // false negative
126  FalseNegatives ++;
127  if (Which == zeroOne) {
128  LabelLoss += 1.0/N;
129  }
130  else if (Which == balancedError) {
131  LabelLoss += 0.5/l.Len();
132  }
133  }
134  }
135 
136  for (THashSetKeyI<TInt> it = lHat.BegI(); it != lHat.EndI(); it ++) {
137  int c = it.GetKey();
138  if (not l.IsKey(c)) {
139  // false positive
140  FalsePositives ++;
141  if (Which == zeroOne) {
142  LabelLoss += 1.0/N;
143  }
144  else if (Which == balancedError) {
145  LabelLoss += 0.5/(N - l.Len());
146  }
147  }
148  else {
149  TruePositives ++;
150  }
151  }
152 
153  if ((lHat.Len() == 0 or TruePositives == 0) and Which == fScore) {
154  return 1.0;
155  }
156  TFlt precision = (1.0*TruePositives)/lHat.Len();
157  TFlt recall = (1.0*TruePositives)/l.Len();
158  if (Which == fScore) {
159  return 1 - 2 * (precision*recall) / (precision + recall);
160  }
161 
162  return LabelLoss;
163 }
TIter BegI() const
Definition: shash.h:1099
bool IsKey(const TKey &Key) const
Definition: shash.h:1142
Definition: dt.h:1289
Definition: circles.h:99
Definition: dt.h:1041
TIter EndI() const
Definition: shash.h:1106
int Len() const
Definition: shash.h:1115

Here is the call graph for this function: