aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
structuralComparator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief A class for comparing graphs based on their structures
24  *
25  * Classifies corresponding arcs, edges and nothing in a graph given a reference
26  * graph to then return values of recall, precision and Fscore.
27  *
28  * @author Quentin FALCAND and Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 #ifndef GUM_LEARNING_STRUCTURAL_COMPARATOR_H
31 #define GUM_LEARNING_STRUCTURAL_COMPARATOR_H
32 
33 #include <agrum/BN/BayesNet.h>
34 #include <agrum/tools/graphs/diGraph.h>
35 #include <agrum/tools/graphs/mixedGraph.h>
36 #include <agrum/tools/graphs/undiGraph.h>
37 
38 
39 namespace gum {
40 
41  /** @class StructuralComparator
42  * @brief A class for comparing graphs based on their structures
43  *
44  * @ingroup bn_group
45  */
47  public:
48  // ##########################################################################
49  /// @name Constructors / Destructors
50  // ##########################################################################
51  /// @{
52 
53  /// default constructor
55 
56  /// destructor
58 
59  /// @}
60 
61  // ##########################################################################
62  /// @name Accessors
63  // ##########################################################################
64  /// @{
65  /// compare two DiGraphs
66  void compare(const DiGraph& ref, const DiGraph& test);
67  /// compare two UndiGraphs
68  void compare(const UndiGraph& ref, const UndiGraph& test);
69  /// compare two MixedGraphs
70  void compare(const MixedGraph& ref, const MixedGraph& test);
71  /// compare two BNs based on their DAG
72  template < typename GS1, typename GS2 >
73  void compare(const BayesNet< GS1 >& ref, const BayesNet< GS2 >& test);
74  /// compare a MixedGraph with the essential graph of a reference BN
75  template < typename GUM_SCALAR >
76  void compare(const BayesNet< GUM_SCALAR >& ref, const MixedGraph& test);
77  /// compare the essential graph of a BN with a reference MixedGraph
78  template < typename GUM_SCALAR >
79  void compare(const MixedGraph& ref, const BayesNet< GUM_SCALAR >& test);
80 
81  /// Measures for the skeleton, aka graph without orientations
82  double precision_skeleton() const;
83  double recall_skeleton() const;
84  double f_score_skeleton() const;
85 
86  /// Measures for the graphs
87  double precision() const;
88  double recall() const;
89  double f_score() const;
90  /// @}
91 
92  protected:
93  private:
94  /// Confusion matrix
95  /* __________________________________________________
96  * | \predicted | | | |
97  * |true\ | --> | --- | X |
98  * |--------------|-----------|-----------|-----------|
99  * | --> | true arc |wrong edge |wrong none |
100  * | | mis. arc | arc | arc |
101  * |--------------|-----------|-----------|-----------|
102  * | --- |wrong arc | true edge |wrong none |
103  * | | edge | | edge |
104  * |--------------|-----------|-----------|-----------|
105  * | X |wrong arc |wrong edge | true none |
106  * | | none | none | |
107  * | ______________| ___________| ___________| ___________|
108  *
109  */
114  // double _precision_, _recall_, _f_score_;
115  };
116 
117 } /* namespace gum */
118 
119 /// always include templated methods
120 #include <agrum/BN/algorithms/structuralComparator_tpl.h>
121 
122 #endif /* GUM_LEARNING_STRUCTURAL_COMPARATOR_H */
double f_score_skeleton() const
compare two DiGraphs
void compare(const MixedGraph &ref, const MixedGraph &test)
compare two MixedGraphs
double recall_skeleton() const
compare two DiGraphs
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
double f_score() const
compare two DiGraphs
double precision() const
Measures for the graphs.
double recall() const
compare two DiGraphs
void compare(const MixedGraph &ref, const BayesNet< GUM_SCALAR > &test)
compare the essential graph of a BN with a reference MixedGraph
A class for comparing graphs based on their structures.
StructuralComparator()
default constructor
double precision_skeleton() const
Measures for the skeleton, aka graph without orientations.
void compare(const BayesNet< GS1 > &ref, const BayesNet< GS2 > &test)
compare two BNs based on their DAG
~StructuralComparator()
destructor
double _true_edge_
Confusion matrix.