GEDLIB  1.0
bipartite_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_METHODS_BIPARTITE_ML_HPP_
28 #define SRC_METHODS_BIPARTITE_ML_HPP_
29 
30 namespace ged {
31 
50 template<class UserNodeLabel, class UserEdgeLabel>
51 class BipartiteML : public MLBasedMethod<UserNodeLabel, UserEdgeLabel> {
52 
53 public:
54 
55  virtual ~BipartiteML();
56 
58 
59 private:
60 
61  typedef Eigen::Array<double, 1, Eigen::Dynamic> RowVector_;
62 
63  typedef Eigen::Array<double, Eigen::Dynamic, 1> ColumnVector_;
64 
65  class RowFeatures_ {
66 
67  public:
68 
69  RowFeatures_();
70 
71  void init(const Eigen::ArrayXXd & substitution_matrix);
72 
73  void add_features_(const Eigen::ArrayXXd & matrix, std::size_t row, std::size_t col, std::vector<double> & feature_vector) const;
74 
75  private:
76 
77  RowVector_ maxima_;
78 
79  RowVector_ minima_;
80 
81  RowVector_ means_;
82 
83  RowVector_ deviations_;
84 
85  RowVector_ leaders_;
86 
87  RowVector_ intervals_;
88  };
89 
90  class ColFeatures_ {
91 
92  public:
93 
94  ColFeatures_();
95 
96  void init(const Eigen::ArrayXXd & substitution_matrix);
97 
98  void add_features_(const Eigen::ArrayXXd & matrix, std::size_t row, std::size_t col, std::vector<double> & feature_vector) const;
99 
100  private:
101 
102  ColumnVector_ maxima_;
103 
104  ColumnVector_ minima_;
105 
106  ColumnVector_ means_;
107 
108  ColumnVector_ deviations_;
109 
110  ColumnVector_ leaders_;
111 
112  ColumnVector_ intervals_;
113  };
114 
116 
117  std::string lsape_method_options_;
118 
119  Eigen::ArrayXXd lsape_instance_;
120 
121  std::vector<double> global_features_;
122 
123  RowFeatures_ row_features_;
124 
125  ColFeatures_ col_features_;
126 
127  // Member functions inherited from MLBasedMethod.
128 
129  virtual void ml_init_() final;
130 
131  virtual void ml_set_default_options_() final;
132 
133  virtual bool ml_parse_option_(const std::string & option, const std::string & arg) final;
134 
135  virtual std::string ml_valid_options_string_() const final;
136 
137  virtual void ml_init_feature_variables_(const GEDGraph & g, const GEDGraph & h, std::size_t num_threads) final;
138 
139  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;
140 
141  virtual void ml_populate_deletion_feature_vector_(const GEDGraph & g, GEDGraph::NodeID i, std::vector<double> & feature_vector) final;
142 
143  virtual void ml_populate_insertion_feature_vector_(const GEDGraph & h, GEDGraph::NodeID k, std::vector<double> & feature_vector) final;
144 
145  virtual std::size_t ml_get_num_features_() final;
146 
147  // Private helper member functions.
148 
149  void populate_lsape_instance_(const GEDGraph & g, const GEDGraph & h, std::size_t num_threads);
150 
151  void compute_global_features_(const Eigen::ArrayXXd & substitution_matrix);
152 
153  void add_global_features_(std::vector<double> & feature_vector) const;
154 
155  void add_cell_features_(std::size_t row, std::size_t col, double node_cost, std::vector<double> & feature_vector) const;
156 
157 };
158 
159 }
160 
161 #endif /* SRC_METHODS_BIPARTITE_ML_HPP_ */
Contains the standardized input data along with basic functionality.
Definition: ged_data.hpp:55
virtual std::size_t ml_get_num_features_() final
Returns the number of features.
Uses characteristics of an LSAPE instance for defining feature vectors for node edit operations...
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...
virtual void ml_populate_insertion_feature_vector_(const GEDGraph &h, GEDGraph::NodeID k, std::vector< double > &feature_vector) final
Computes insertion feature vector.
virtual void ml_init_() final
Initializes the method after initializing the global variables for the graphs.
Abstract class for methods that use lossy transformations to LSAPE for approximating the graph edit d...
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
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.
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.
Global namespace for GEDLIB.
virtual void ml_populate_deletion_feature_vector_(const GEDGraph &g, GEDGraph::NodeID i, std::vector< double > &feature_vector) final
Computes deletion feature vector.
Abstract class for methods that transform GED to LSAPE by using a SVM or a DNN to predict the cost of...
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...
void init()
Initializes the method with options specified by set_options().
Definition: ged_method.ipp:81
std::size_t NodeID
Internally used vertex ID type.
Definition: ged_graph.hpp:108
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:...