SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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(); !it.IsEnd(); it++) {
352  res += it.GetDat() * Parameter[it.GetKey()];
353  }
354  return res;
355 }
TIter BegI() const
Definition: hash.h:213
Definition: dt.h:1386
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
Definition: hash.h:78

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 (!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 (!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 || TruePositives == 0) && 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:1105
bool IsKey(const TKey &Key) const
Definition: shash.h:1148
Definition: dt.h:1386
Definition: circles.h:99
Definition: dt.h:1137
TIter EndI() const
Definition: shash.h:1112
int Len() const
Definition: shash.h:1121

Here is the call graph for this function: