|
SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include "stdafx.h"
Go to the source code of this file.
Classes | |
| class | TGraphAttributes |
| class | TCluster |
Typedefs | |
| typedef TPt< TGraphAttributes > | PGraphAttributes |
| typedef TPt< TCluster > | PCluster |
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 TPt<TGraphAttributes> PGraphAttributes |
| enum lossType |
Definition at line 95 of file circles.h.
{
zeroOne = 0,
balancedError = 1,
fScore = 2
};
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;
}


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