jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
graph_wo_index.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_GRAPH_GRAPH_WO_INDEX_HPP_
18 #define JUBATUS_CORE_GRAPH_GRAPH_WO_INDEX_HPP_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #include "jubatus/util/data/unordered_map.h"
25 #include "jubatus/util/data/unordered_set.h"
26 #include "jubatus/util/data/serialization.h"
27 #include "jubatus/util/lang/enable_shared_from_this.h"
28 #include "jubatus/util/lang/shared_ptr.h"
29 
30 #include "../common/unordered_map.hpp"
31 #include "../framework/mixable_helper.hpp"
32 #include "graph_type.hpp"
33 
34 namespace jubatus {
35 namespace core {
36 namespace graph {
37 
39  : public jubatus::util::lang::enable_shared_from_this<graph_wo_index> {
40  public:
41  struct diff_type {
44 
45  void clear() {
46  eigen_vector_query.clear();
47  spt_query.clear();
48  }
49 
50  MSGPACK_DEFINE(eigen_vector_query, spt_query);
51  };
52 
53  struct config {
55  : damping_factor(0.9),
56  landmark_num(5) {
57  }
58 
61 
62  template<typename Ar>
63  void serialize(Ar& ar) {
64  ar
65  & JUBA_NAMED_MEMBER("damping_factor", damping_factor)
66  & JUBA_MEMBER(landmark_num);
67  }
68  };
69 
70  explicit graph_wo_index(const config& config);
73 
74  void damping_factor(double a);
75 
76  void clear();
77  void create_node(node_id_t id);
80  void update_node(node_id_t id, const property& p);
81  void remove_node(node_id_t id);
82 
83  void create_edge(edge_id_t eid, node_id_t src, node_id_t tgt);
84  void update_edge(edge_id_t eid, const property& p);
85  void remove_edge(edge_id_t eid);
86 
91 
92  double centrality(
93  node_id_t id,
94  centrality_type ct,
95  const preset_query&) const;
96 
97  void shortest_path(
98  node_id_t src,
99  node_id_t tgt,
100  uint64_t max_hop,
101  std::vector<node_id_t>& ret,
102  const preset_query&) const;
103 
104  void get_node(node_id_t id, node_info& ret) const;
105  void get_edge(edge_id_t eid, edge_info& ret) const;
106 
107  void get_diff(diff_type& diff) const;
108  bool put_diff(const diff_type& mixed);
109 
110  std::string type() const;
111 
112  void get_status(std::map<std::string, std::string>& status) const;
113  void update_index();
114 
115  void mix(const diff_type& diff, diff_type& mixed);
116 
118  // TODO(kumagi): it should return correct version of model
119  return storage::version();
120  }
121 
122  void pack(framework::packer& packer) const;
123  void unpack(msgpack::object o);
124 
127 
128  private:
129  typedef jubatus::util::data::unordered_map<node_id_t, node_info>
131  typedef jubatus::util::data::unordered_map<edge_id_t, edge_info>
133 
134  static void remove_by_swap(std::vector<edge_id_t>& edges, edge_id_t eid);
135 
138 
139  // value is dummy for serialization
140  jubatus::util::data::unordered_map<node_id_t, uint8_t> global_nodes_;
141 
142  // centeralities
143  static void mix(
144  const eigen_vector_query_diff& diff,
145  eigen_vector_query_diff& mixed);
146 
149  const eigen_vector_query_diff& mixed);
150 
152 
153  // shortest pathes
154  static void mix_spt(
155  const shortest_path_tree& diff,
156  shortest_path_tree& mixed);
157  static void mix(
158  const spt_query_diff& diff,
159  spt_query_diff& mixed,
160  size_t landmark_num);
161 
162  void may_set_landmark(node_id_t id);
163 
165 
167  const spt_query_diff& mixed);
168 
169  void update_spt();
170 
171  void update_spt_edges(
172  const preset_query& query,
173  spt_edges& se,
174  node_id_t landmark,
175  bool is_out);
176 
177  void update_spt_node(
178  const preset_query& query,
179  const std::vector<edge_id_t>& edges,
180  spt_edges& se,
181  bool is_out);
182 
183  bool is_node_matched_to_query(const preset_query& query, node_id_t id) const;
184 
186 
188 };
189 
192 
193 } // namespace graph
194 } // namespace core
195 } // namespace jubatus
196 
197 #endif // JUBATUS_CORE_GRAPH_GRAPH_WO_INDEX_HPP_
void update_spt_node(const preset_query &query, const std::vector< edge_id_t > &edges, spt_edges &se, bool is_out)
MSGPACK_DEFINE(eigen_vector_query, spt_query)
jubatus::util::data::unordered_map< preset_query, eigen_vector_diff > eigen_vector_query_diff
Definition: graph_type.hpp:97
void shortest_path(node_id_t src, node_id_t tgt, uint64_t max_hop, std::vector< node_id_t > &ret, const preset_query &) const
void get_diff_shortest_path_tree(spt_query_diff &diff) const
void get_status(std::map< std::string, std::string > &status) const
void get_edge(edge_id_t eid, edge_info &ret) const
void add_centrality_query(const preset_query &)
jubatus::util::data::unordered_map< node_id_t, node_info > node_info_map
static void mix_spt(const shortest_path_tree &diff, shortest_path_tree &mixed)
void mix(const diff_type &diff, diff_type &mixed)
jubatus::util::data::unordered_map< preset_query, spt_diff > spt_query_diff
Definition: graph_type.hpp:100
static void remove_by_swap(std::vector< edge_id_t > &edges, edge_id_t eid)
framework::linear_mixable_helper< graph_wo_index, graph_wo_index::diff_type > mixable_graph_wo_index
void remove_shortest_path_query(const preset_query &)
jubatus::util::data::unordered_map< node_id_t, uint8_t > global_nodes_
void update_node(node_id_t id, const property &p)
std::map< std::string, std::string > property
Definition: graph_type.hpp:39
double centrality(node_id_t id, centrality_type ct, const preset_query &) const
void pack(framework::packer &packer) const
bool put_diff(const diff_type &mixed)
void get_node(node_id_t id, node_info &ret) const
MSGPACK_DEFINE(local_nodes_, local_edges_, global_nodes_, eigen_scores_, spts_)
msgpack::packer< jubatus_packer > packer
Definition: bandit_base.hpp:31
void update_spt_edges(const preset_query &query, spt_edges &se, node_id_t landmark, bool is_out)
void update_edge(edge_id_t eid, const property &p)
void create_edge(edge_id_t eid, node_id_t src, node_id_t tgt)
void put_diff_eigen_score(const eigen_vector_query_diff &mixed)
jubatus::util::data::unordered_map< edge_id_t, edge_info > edge_info_map
void remove_centrality_query(const preset_query &)
void put_diff_shortest_path_tree(const spt_query_diff &mixed)
eigen_vector_query_diff eigen_scores_
void get_diff(diff_type &diff) const
jubatus::util::data::unordered_map< node_id_t, std::pair< uint64_t, node_id_t > > spt_edges
Definition: graph_type.hpp:84
void get_diff_eigen_score(eigen_vector_query_diff &diff) const
bool is_node_matched_to_query(const preset_query &query, node_id_t id) const
storage::version get_version() const
void add_shortest_path_query(const preset_query &)