GEDLIB  1.0
ring_ml.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 * *
3 * Copyright (C) 2018 by David B. Blumenthal *
4 * *
5 * This file is part of GEDLIB. *
6 * *
7 * GEDLIB is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * GEDLIB is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21 
27 #ifndef SRC_METHPODS_RING_ML_HPP_
28 #define SRC_METHPODS_RING_ML_HPP_
29 
30 namespace ged {
31 
47 template<class UserNodeLabel, class UserEdgeLabel>
48 class RingML : public MLBasedMethod<UserNodeLabel, UserEdgeLabel> {
49 
50 public:
51 
52  virtual ~RingML();
53 
55 
56 private:
57 
58  enum LEDMethod_ {LSAPE_OPTIMAL, LSAPE_GREEDY, GAMMA};
59 
60  enum SortMethod_ {STD, COUNTING};
61 
62  struct Layer_ {
63  Layer_(std::size_t level);
64 
65  std::size_t level;
66 
67  std::vector<LabelID> node_labels;
68 
69  std::vector<LabelID> inner_edge_labels;
70 
71  std::vector<LabelID> outer_edge_labels;
72  };
73 
74  struct Ring_ {
75  Ring_();
76 
77  std::vector<Layer_> layers;
78  };
79 
80  typedef std::map<GEDGraph::NodeID, Ring_> NodeRingMap_;
81 
82  std::map<GEDGraph::GraphID, NodeRingMap_> rings_;
83 
84  LEDMethod_ led_method_;
85 
86  SortMethod_ sort_method_;
87 
88  bool use_topological_features_;
89 
90  bool use_global_features_;
91 
92  std::size_t num_layers_;
93 
94  std::vector<double> global_features_;
95 
96  // Member functions inherited from MLBasedMethod.
97 
98  virtual void ml_init_graph_(const GEDGraph & graph) final;
99 
100  virtual void ml_set_default_options_() final;
101 
102  virtual std::string ml_valid_options_string_() const final;
103 
104  virtual bool ml_parse_option_(const std::string & option, const std::string & arg) final;
105 
106  virtual void ml_init_feature_variables_(const GEDGraph & g, const GEDGraph & h, std::size_t num_threads) final;
107 
108  virtual void ml_populate_substitution_feature_vector_(const GEDGraph & g, const GEDGraph & h, GEDGraph::NodeID i, GEDGraph::NodeID k, std::vector<double> & feature_vector) final;
109 
110  virtual void ml_populate_deletion_feature_vector_(const GEDGraph & g, GEDGraph::NodeID i, std::vector<double> & feature_vector) final;
111 
112  virtual void ml_populate_insertion_feature_vector_(const GEDGraph & h, GEDGraph::NodeID k, std::vector<double> & feature_vector) final;
113 
114  virtual std::size_t ml_get_num_features_() final;
115 
116  virtual void ml_init_for_num_features_() final;
117 
118  // Private helper member functions.
119 
120  void set_num_layers_();
121 
122  void build_rings_(const GEDGraph & graph);
123 
124  void build_ring_(const GEDGraph & graph, GEDGraph::NodeID root, NodeRingMap_ & rings);
125 
126  void add_global_features_(std::vector<double> & feature_vector) const;
127 
128  void add_layer_substitution_features_(const Ring_ & ring_i, const Ring_ & ring_k, std::size_t level, std::vector<double> & feature_vector) const;
129 
130  void add_layer_deletion_features_(const Ring_ & ring, std::size_t level, std::vector<double> & feature_vector) const;
131 
132  void add_layer_insertion_features_(const Ring_ & ring, std::size_t level, std::vector<double> & feature_vector) const;
133 
134  void add_layer_features_(const Layer_ & lhs, const Layer_ & rhs, std::vector<double> & feature_vector) const;
135 
136  double lsape_multiset_cost_(const std::vector<LabelID> & lhs, const std::vector<LabelID> & rhs, bool node_labels) const;
137 
138  double gamma_multiset_cost_(const std::vector<LabelID> & lhs, const std::vector<LabelID> & rhs, bool node_labels) const;
139 };
140 
141 }
142 
143 #endif /* SRC_METHPODS_RING_ML_HPP_ */
virtual void ml_init_for_num_features_() final
Initializes the derived class for running with feature vectors of size ged::MLBasedMethod::num_featur...
Definition: ring_ml.ipp:192
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual void ml_populate_substitution_feature_vector_(const GEDGraph &g, const GEDGraph &h, GEDGraph::NodeID i, GEDGraph::NodeID k, std::vector< double > &feature_vector) final
Computes substitution feature vector.
Definition: ring_ml.ipp:155
virtual std::string ml_valid_options_string_() const final
Returns string of all valid options that are not among the ones shared by all derived classes of ged:...
Definition: ring_ml.ipp:70
virtual void ml_set_default_options_() final
Sets all options that are not among the ones shared by all derived classes of ged::MLBasedMethod to d...
Definition: ring_ml.ipp:60
virtual void ml_populate_deletion_feature_vector_(const GEDGraph &g, GEDGraph::NodeID i, std::vector< double > &feature_vector) final
Computes deletion feature vector.
Definition: ring_ml.ipp:168
virtual bool ml_parse_option_(const std::string &option, const std::string &arg) final
Parses one option that is not among the ones shared by all derived classes of ged::MLBasedMethod.
Definition: ring_ml.ipp:77
Uses ring structures for defining feature vectors for node edit operations.
Definition: ring_ml.hpp:48
virtual void ml_init_graph_(const GEDGraph &graph) final
Initializes global variables for one graph.
Definition: ring_ml.ipp:53
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
virtual void ml_populate_insertion_feature_vector_(const GEDGraph &h, GEDGraph::NodeID k, std::vector< double > &feature_vector) final
Computes insertion feature vector.
Definition: ring_ml.ipp:180
Global namespace for GEDLIB.
Abstract class for methods that transform GED to LSAPE by using a SVM or a DNN to predict the cost of...
virtual std::size_t ml_get_num_features_() final
Returns the number of features.
Definition: ring_ml.ipp:211
std::size_t NodeID
Internally used vertex ID type.
Definition: ged_graph.hpp:108
virtual void ml_init_feature_variables_(const GEDGraph &g, const GEDGraph &h, std::size_t num_threads) final
Initializes variables that are used for populating the feature vectors of assignments between two inp...
Definition: ring_ml.ipp:136