All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EvaluationMetric.h
Go to the documentation of this file.
1 /*
2  * EvaluationMetric.h
3  *
4  * Created on: 17.03.2015
5  * Author: Kolja Esders (kolja.esders@student.kit.edu)
6  */
7 
8 #ifndef EVALUATIONMETRIC_H_
9 #define EVALUATIONMETRIC_H_
10 
11 #include "../graph/Graph.h"
12 #include "LinkPredictor.h"
13 
14 namespace NetworKit {
15 
24 private:
25 
32  virtual std::pair<std::vector<double>, std::vector<double>> generatePoints() = 0;
33 
38  void calculateStatisticalMeasures();
39 
40  // The following three helper methods generate statistical measures for every threshold
41  // based on the given predictions. The names should be self-explanatory.
42  void setPositivesAndNegatives();
43 
44  void setTrueAndFalsePositives();
45 
46  void setTrueAndFalseNegatives();
47 
54  void sortPointsOfCurve(std::pair<std::vector<double>, std::vector<double>>& curve) const;
55 
56 protected:
57  std::pair<std::vector<double>, std::vector<double>> generatedPoints;
58 
59  const Graph* testGraph;
60 
61  std::vector<LinkPredictor::prediction> predictions;
62 
63  std::vector<index> thresholds;
64 
66 
68 
69  std::vector<count> truePositives;
70 
71  std::vector<count> falsePositives;
72 
73  std::vector<count> trueNegatives;
74 
75  std::vector<count> falseNegatives;
76 
77 public:
79 
85  explicit EvaluationMetric(const Graph& testGraph);
86 
90  virtual ~EvaluationMetric() = default;
91 
98  void setTestGraph(const Graph& newTestGraph);
99 
111  virtual std::pair<std::vector<double>, std::vector<double>> getCurve(std::vector<LinkPredictor::prediction> predictions, count numThresholds = 1000);
112 
118  virtual double getAreaUnderCurve(std::pair<std::vector<double>, std::vector<double>> curve) const;
119 
125  virtual double getAreaUnderCurve() const;
126 
127 };
128 
129 } // namespace NetworKit
130 
131 #endif /* EVALUATIONMETRIC_H_ */
count numPositives
Absolute number of positive instances in the prediction-set.
Definition: EvaluationMetric.h:65
std::vector< index > thresholds
Indices for the thresholds to use. All node-pairs with an index < thresholds[i] will be regarded as l...
Definition: EvaluationMetric.h:63
Abstract base class for evaluation curves.
Definition: EvaluationMetric.h:23
EvaluationMetric()
Definition: EvaluationMetric.cpp:14
std::vector< count > trueNegatives
True negatives regarding the corresponding threshold.
Definition: EvaluationMetric.h:73
std::pair< std::vector< double >, std::vector< double > > generatedPoints
Points describing the generated curve. Will be set after a call to getCurve.
Definition: EvaluationMetric.h:57
std::vector< LinkPredictor::prediction > predictions
Predictions that should be evaluated.
Definition: EvaluationMetric.h:61
virtual double getAreaUnderCurve() const
Returns the area under the curve that was most recently calculated by this instance.
Definition: EvaluationMetric.cpp:69
void setTestGraph(const Graph &newTestGraph)
Sets a new graph to use as ground truth for evaluation.
Definition: EvaluationMetric.cpp:20
uint64_t count
Definition: Globals.h:21
std::vector< count > truePositives
True positives regarding the corresponding threshold.
Definition: EvaluationMetric.h:69
std::vector< count > falsePositives
False positives regarding the corresponding threshold.
Definition: EvaluationMetric.h:71
std::vector< count > falseNegatives
False negatives regarding the corresponding threshold.
Definition: EvaluationMetric.h:75
virtual std::pair< std::vector< double >, std::vector< double > > getCurve(std::vector< LinkPredictor::prediction > predictions, count numThresholds=1000)
Returns a pair of X- and Y-vectors describing the evaluation curve generated from the predictions...
Definition: EvaluationMetric.cpp:24
const Graph * testGraph
Used to evaluate the binary predictions at the thresholds.
Definition: EvaluationMetric.h:59
A graph (with optional weights) and parallel iterator methods.
Definition: Graph.h:79
virtual ~EvaluationMetric()=default
Default destructor.
count numNegatives
Absolute number of negative instances in the prediction-set.
Definition: EvaluationMetric.h:67