20 template <
class Graph,
class CouplingMap,
class TempMap>
21 void partition_all_update_directed_edge(
23 typename boost::graph_traits<Graph>::vertex_descriptor v_a,
24 typename boost::graph_traits<Graph>::vertex_descriptor v_b,
27 CouplingMap coupling_map,
28 TempMap cs_xa, TempMap cs_by)
30 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
31 typedef typename boost::graph_traits<Graph>::vertex_iterator VertexIter;
36 denom = exp(weight_frac)
37 - boost::get(coupling_map, std::make_pair(v_b,v_a));
44 denom = - exp(weight_frac)
45 - boost::get(coupling_map, std::make_pair(v_b,v_a));
48 for (std::pair<VertexIter,VertexIter> vp=boost::vertices(g);
49 vp.first!=vp.second; vp.first++)
53 boost::get(coupling_map, std::make_pair(v,v_a)));
55 boost::get(coupling_map, std::make_pair(v_b,v)));
58 for (std::pair<VertexIter,VertexIter> vpx=boost::vertices(g);
59 vpx.first!=vpx.second; vpx.first++)
61 Vertex v_x = *vpx.first;
62 for (std::pair<VertexIter,VertexIter> vpy=boost::vertices(g);
63 vpy.first!=vpy.second; vpy.first++)
65 Vertex v_y = *vpy.first;
66 boost::put(coupling_map, std::make_pair(v_x,v_y),
67 boost::get(coupling_map, std::make_pair(v_x,v_y))
68 + boost::get(cs_xa,v_x)*boost::get(cs_by,v_y)/denom);
73 template <
class Graph,
class CouplingMap,
class TempMap>
74 void partition_all_update_edge(
76 typename boost::graph_traits<Graph>::edge_descriptor edge,
79 CouplingMap coupling_map,
80 TempMap cs_xa, TempMap cs_by)
82 typedef typename boost::graph_traits<Graph>::directed_category DirCat;
83 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
86 BOOST_STATIC_CONSTANT(
bool, is_undirected
87 = (boost::is_base_and_derived<boost::undirected_tag, DirCat>::value
88 || boost::is_same<boost::undirected_tag, DirCat>::value));
90 Vertex v_s = boost::source(edge, g);
91 Vertex v_t = boost::target(edge, g);
94 partition_all_update_directed_edge(g,
99 coupling_map, cs_xa, cs_by);
104 partition_all_update_directed_edge(g,
109 coupling_map, cs_xa, cs_by);
113 template <
class Graph,
class CouplingMap>
114 void partition_all_init(
116 CouplingMap coupling_map)
118 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
119 typedef typename boost::graph_traits<Graph>::vertex_iterator VertexIter;
121 for (std::pair<VertexIter,VertexIter> vpx=boost::vertices(g);
122 vpx.first!=vpx.second; vpx.first++)
124 Vertex v_x = *vpx.first;
125 for (std::pair<VertexIter,VertexIter> vpy=boost::vertices(g);
126 vpy.first!=vpy.second; vpy.first++)
128 Vertex v_y = *vpy.first;
129 boost::put(coupling_map, std::make_pair(v_x,v_y),
130 (v_x == v_y) ? 1.0 : 0.0);
142 template <
class Graph,
class WeightMap,
class CouplingMap,
class TempMap>
146 WeightMap weight_map,
147 CouplingMap coupling_map,
148 TempMap cs_xa, TempMap cs_by)
150 typedef typename boost::graph_traits<Graph>::edge_iterator EdgeIter;
152 partition_all_init(g, coupling_map);
154 std::pair<EdgeIter,EdgeIter> ep=boost::edges(g);
155 for (EdgeIter ei=ep.first; ei!=ep.second; ei++)
157 partition_all_update_edge(
160 boost::get(weight_map,*ei) / len_ref,
162 coupling_map, cs_xa, cs_by);
166 template <
class Graph,
class CouplingMap>
167 double partition_all_without_edge(
169 typename boost::graph_traits<Graph>::vertex_descriptor v_x,
170 typename boost::graph_traits<Graph>::vertex_descriptor v_y,
171 typename boost::graph_traits<Graph>::edge_descriptor edge,
173 CouplingMap coupling_map)
175 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
176 typedef typename boost::graph_traits<Graph>::directed_category DirCat;
179 BOOST_STATIC_CONSTANT(
bool, is_undirected
180 = (boost::is_base_and_derived<boost::undirected_tag, DirCat>::value
181 || boost::is_same<boost::undirected_tag, DirCat>::value));
183 Vertex v_s = boost::source(edge, g);
184 Vertex v_t = boost::target(edge, g);
191 double cpp_xy = boost::get(coupling_map, std::make_pair(v_x,v_y));
192 double cpp_xs = boost::get(coupling_map, std::make_pair(v_x,v_s));
193 double cpp_xt = boost::get(coupling_map, std::make_pair(v_x,v_t));
194 double cpp_sy = boost::get(coupling_map, std::make_pair(v_s,v_y));
195 double cpp_ss = boost::get(coupling_map, std::make_pair(v_s,v_s));
196 double cpp_st = boost::get(coupling_map, std::make_pair(v_s,v_t));
197 double cpp_ty = boost::get(coupling_map, std::make_pair(v_t,v_y));
198 double cpp_ts = boost::get(coupling_map, std::make_pair(v_t,v_s));
199 double cpp_tt = boost::get(coupling_map, std::make_pair(v_t,v_t));
203 double cp_xy = cpp_xy - (cpp_xs * cpp_ty)/(exp(weight_frac) + cpp_ts);
204 double cp_xt = cpp_xt - (cpp_xs * cpp_tt)/(exp(weight_frac) + cpp_ts);
205 double cp_sy = cpp_sy - (cpp_ss * cpp_ty)/(exp(weight_frac) + cpp_ts);
206 double cp_st = cpp_st - (cpp_ss * cpp_tt)/(exp(weight_frac) + cpp_ts);
209 double c_xy = cp_xy - (cp_xt * cp_sy)/(exp(weight_frac) + cp_st);
214 double cp_xy = boost::get(coupling_map, std::make_pair(v_x,v_y));
215 double cp_xs = boost::get(coupling_map, std::make_pair(v_x,v_s));
216 double cp_ty = boost::get(coupling_map, std::make_pair(v_t,v_y));
217 double cp_ts = boost::get(coupling_map, std::make_pair(v_t,v_s));
220 double c_xy = cp_xy - (cp_xs * cp_ty)/(exp(weight_frac) + cp_ts);
228 boost::numeric::ublas::matrix<double> Z;
229 boost::numeric::ublas::vector<double> Z_xa;
230 boost::numeric::ublas::vector<double> Z_by;
233 Z(num_vertices,num_vertices),
234 Z_xa(num_vertices), Z_by(num_vertices)
236 Z = boost::numeric::ublas::identity_matrix<double>(num_vertices);
239 inline void add_edge(
size_t va,
size_t vb,
double weight_frac)
241 double denom = exp(weight_frac) - Z(vb, va);
243 throw std::runtime_error(
"divergent!");
245 Z_xa = column(Z, va);
248 Z += (1.0/denom) * outer_prod(Z_xa, Z_by);
251 inline void remove_edge(
size_t va,
size_t vb,
double weight_frac)
253 double denom = exp(weight_frac) + Z(vb, va);
255 Z_xa = column(Z, va);
258 Z -= (1.0/denom) * outer_prod(Z_xa, Z_by);
261 inline double without_undirected(
size_t vx,
size_t vy,
size_t va,
size_t vb,
double weight_frac)
266 double cpp_xy = Z(vx, vy);
267 double cpp_xs = Z(vx, va);
268 double cpp_xt = Z(vx, vb);
269 double cpp_sy = Z(va, vy);
270 double cpp_ss = Z(va, va);
271 double cpp_st = Z(va, vb);
272 double cpp_ty = Z(vb, vy);
273 double cpp_ts = Z(vb, va);
274 double cpp_tt = Z(vb, vb);
278 double cp_xy = cpp_xy - (cpp_xs * cpp_ty)/(exp(weight_frac) + cpp_ts);
279 double cp_xt = cpp_xt - (cpp_xs * cpp_tt)/(exp(weight_frac) + cpp_ts);
280 double cp_sy = cpp_sy - (cpp_ss * cpp_ty)/(exp(weight_frac) + cpp_ts);
281 double cp_st = cpp_st - (cpp_ss * cpp_tt)/(exp(weight_frac) + cpp_ts);
284 double c_xy = cp_xy - (cp_xt * cp_sy)/(exp(weight_frac) + cp_st);
Definition: partition_all.h:18
Definition: partition_all.h:225