gather_type gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { cout << "gather(), edge=" << edge.source().id() << "->" << edge.target().id() << ", called from vid=" << vertex.id() << endl; gather_type gathered; // add id of other vertex of edge and add id->beta to map if message source if (edge.target().id()==vertex.id()) { // incoming edge, outgoing message, only if target is non-observed if (!edge.source().data().is_observed) { gathered.message_targets.insert(edge.source().id()); cout << "added " << edge.source().id() << " as message target" << endl; } } else { // outgoing edge, incoming message with beta gathered.message_source_betas[edge.target().id()]=edge.data().beta; cout << "added " << edge.target().id() << " as message source" << endl; } cout << "gathered=" << gathered << endl; return gathered; }
std::string save_edge(const edge_type& edge) const { std::stringstream strm; const double prediction = edge.source().data().factor.dot(edge.target().data().factor); strm << edge.source().id() << '\t' << edge.target().id() << '\t' << prediction << '\n'; return strm.str(); }
// Scatter to scatter_edges edges with the new message value. void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { bool isEdgeSource = (vertex.id() == edge.source().id()); bool hasSameData = isEdgeSource ? (vertex.data() == edge.target().data()) : (vertex.data() == edge.source().data()) ; if (!hasSameData) { min_combiner combiner; combiner.value = message_value; context.signal(isEdgeSource ? edge.target() : edge.source(), combiner); } }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { if (context.iteration() == 0) { pair<size_t, size_t> p = count_triangles(edge.source(), edge.target()); if (p.first > 0) { context.signal(edge.source(), p.first); } if (p.second > 0) { context.signal(edge.target(), p.second); } } else { // } }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type other = edge.target(); distance_type newd = vertex.data().dist + edge.data().dist; const min_distance_type msg(newd); context.signal(other, msg); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type other = edge.target(); pagerank_type value = vertex.data().pagerank / vertex.num_out_edges(); assert(other.id() != vertex.id()); const sum_pagerank_type msg(value); context.signal(other, msg); }
gather_type gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { if (context.iteration() == 0) { if (vertex.id() == edge.source().id()) { return gather_type(edge.target().id()); } else { return gather_type(edge.source().id()); } } else { return gather_type(); } }
/** * \brief The scatter function just signal adjacent pages */ void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type other = edge.target(); /*if (USE_DELTA_CACHE) { gather_data_type delta; delta.dist = lastchange; context.post_delta(other, delta); }*/ context.signal(other); }
double gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { edge_data e = edge.parse<edge_data>(); int topic = rand()%env_inst.NTOPICS; //sample topic from Mean(1/K) e.assignment=topic; edge.update<edge_data>(e); vertex_data vs=edge.source().parse<vertex_data>(); vertex_data vt=edge.target().parse<vertex_data>(); vs.n[topic]++; vt.n[topic]++; env_inst.nwsum[topic]++; env_inst.ndsum[k2id(vs.id)]++; return 0; }
/* Gather the weighted rank of the adjacent page */ double gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { if (edge.data().role == edge_data::PREDICT) return 0; bool brows = vertex.id() < (uint)info.get_start_node(false); if (info.is_square()) brows = !mi.A_transpose; if (mi.A_offset && mi.x_offset >= 0){ double val = edge.data().obs * (brows ? edge.target().data().pvec[mi.x_offset] : edge.source().data().pvec[mi.x_offset]); //printf("gather edge on vertex %d val %lg obs %lg\n", vertex.id(), val, edge.data().obs); return val; } //printf("edge on vertex %d val %lg\n", vertex.id(), 0.0); return 0; }
double gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { // remove topic from the count variables edge_data e=edge.parse<edge_data>(); int topic = e.assignment; vertex_data vd=edge.source().parse<vertex_data>(); vertex_data vw=edge.target().parse<vertex_data>(); vw.n[topic]--; vd.n[topic]--; env_inst.nwsum[topic]--; env_inst.ndsum[k2id(vd.id)]--; // do multinomial sampling via cumulative method: double *p=new double[env_inst.NTOPICS]; for (int k = 0; k < env_inst.NTOPICS; k++) { p[k] = (vw.n[k] + env_inst.BETA) / (env_inst.nwsum[k] + env_inst.NWORDS * env_inst.BETA) * (vd.n[k] + env_inst.ALPHA) / (env_inst.ndsum[k2id(vd.id)] + env_inst.NTOPICS * env_inst.ALPHA); } // cumulate multinomial parameters for (int k = 1; k < env_inst.NTOPICS; k++) { p[k] += p[k - 1]; } // scaled sample because of unnormalised p[] double u = (double)rand()/RAND_MAX * p[env_inst.NTOPICS - 1]; for (topic = 0; topic < env_inst.NTOPICS; topic++) { if (u <= p[topic]) break; } delete []p; // add newly estimated topic to count variables vw.n[topic]++; vd.n[topic]++; env_inst.nwsum[topic]++; env_inst.ndsum[k2id(vd.id)]++; e.assignment=topic; edge.update<edge_data>(e); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { if( edge.target().data().in_core ) { context.signal(edge.target()); } }
/** * \brief The scatter function just signal adjacent pages */ void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type other = edge.target(); context.signal(other); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type& other = edge.source().id() == vertex.id() ? edge.target() : edge.source(); context.signal(other); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { float weight = edge.data(); if ( ((double)rand() / RAND_MAX) < weight){ context.signalVid(edge.target().id()); } }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { if (vertex.data() + edge.data() < edge.target().data()) context.signal(edge.target()); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { context.signal(edge.target()); }
gather_type gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { const vertex_type& other = edge.source().id() == vertex.id() ? edge.target() : edge.source(); return gather_type(other.data()); }
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const { cout << "scatter(), edge=" << edge.source().id() << "->" << edge.target().id() << ", called from vid=" << vertex.id() << endl; cout << "computing message from vid=" << vertex.id() << " to vid=" << edge.source().id() << endl; vertex_id_type message_target=edge.source().id(); // find out whether full rank or incomplete Cholesky mode // distinguish case this node being observed or not VectorXd new_beta; if (edge.target().data().is_observed) { cout << "observed target" << endl; // extract system solutions and observation kernel vector, base on full rank or incomplete Cholesky if (edge.data().full_rank) { cout << "full rank case" << endl; MatrixXd L_s=edge.data().solution_matrices["L_s"]; cout << "L_s:" << L_s << endl; MatrixXd L_t=edge.data().solution_matrices["L_t"]; cout << "L_t:" << L_t << endl; VectorXd k=vertex.data().kernel_dict_obs.at(message_target); cout << "k:" << k << endl; // L_{s}^{-T}(L_{s}^{-1}(L_{t}^{-T}(L_{t}^{-1}k_{t}^{s}), from right to left, 4 solver calls new_beta=k; new_beta=L_t.triangularView<Lower>().solve(new_beta); new_beta=L_t.transpose().triangularView<Upper>().solve(new_beta); new_beta=L_s.triangularView<Lower>().solve(new_beta); new_beta=L_s.transpose().triangularView<Upper>().solve(new_beta); } else { cout << "incomplete Cholesky case" << endl; MatrixXd Q_s=edge.data().solution_matrices["Q_s"]; cout << "Q_s:" << Q_s << endl; MatrixXd R_s=edge.data().solution_matrices["R_s"]; cout << "R_s:" << R_s << endl; MatrixXd P_s=edge.data().solution_matrices["P_s"]; cout << "P_s:" << P_s << endl; MatrixXd Q_t=edge.data().solution_matrices["Q_t"]; cout << "Q_t:" << Q_t << endl; MatrixXd R_t=edge.data().solution_matrices["R_t"]; cout << "R_t:" << R_t << endl; MatrixXd P_t=edge.data().solution_matrices["P_t"]; cout << "P_t:" << P_t << endl; MatrixXd W=edge.data().solution_matrices["W"]; cout << "W:" << W << endl; VectorXd k=vertex.data().kernel_dict_obs.at(message_target); cout << "k:" << k << endl; // R_{s}^{-1}(Q_{s}^{T}((P_{s}(W_{s}W_{t}^{T}))(R_{t}^{-1}(Q_{t}^{T}(P_{t}k_{\mathcal{I}_{t}}^{(s)}))) new_beta=k; new_beta=P_t.transpose()*new_beta; new_beta=Q_t.transpose()*new_beta; new_beta=R_t.triangularView<Upper>().solve(new_beta); new_beta=W*new_beta; new_beta=P_s.transpose()*new_beta; new_beta=Q_s.transpose()*new_beta; new_beta=R_s.triangularView<Upper>().solve(new_beta); } } else { cout << "non-observed target" << endl; cout << "multiplied_incoming_messages: " << vertex.data().multiplied_incoming_messages << endl; // extract system solutions, depending on full rank or incomplete Cholesky if (edge.data().full_rank) { cout << "full rank case" << endl; MatrixXd L_s=edge.data().solution_matrices["L_s"]; cout << "L_s:" << L_s << endl; VectorXd k; if (!vertex.data().multiplied_incoming_messages.size()) { cout << "no incoming messages, using constant unit norm vector" << endl; k=VectorXd::Constant(L_s.cols(), 1.0/sqrt(L_s.cols())); } else { k=vertex.data().multiplied_incoming_messages.at(message_target); } cout << "k:" << k << endl; // (K_{s}+\lambda I){}^{-1}k_{ut}^{(s)}=L_{s}^{-T}(L_{s}^{-1}k_{ut}^{(s)}) from right to left, 2 solver calls new_beta=k; new_beta=L_s.triangularView<Lower>().solve(new_beta); new_beta=L_s.transpose().triangularView<Upper>().solve(new_beta); } else { cout << "incomplete Cholesky case" << endl; MatrixXd Q_s=edge.data().solution_matrices["Q_s"]; cout << "Q_s:" << Q_s << endl; MatrixXd R_s=edge.data().solution_matrices["R_s"]; cout << "R_s:" << R_s << endl; MatrixXd P_s=edge.data().solution_matrices["P_s"]; cout << "P_s:" << P_s << endl; MatrixXd W=edge.data().solution_matrices["W"]; cout << "W:" << W << endl; VectorXd k; if (!vertex.data().multiplied_incoming_messages.size()) { cout << "no incoming messages, using constant unit norm vector" << endl; k=VectorXd::Constant(W.cols(), 1.0/sqrt(W.cols())); } else { k=vertex.data().multiplied_incoming_messages.at(message_target); } cout << "k:" << k << endl; // R_{s}^{-1}(Q_{s}^{T}(P_{s}^{T}k_{t}^{(s)})) new_beta=k; new_beta=W*new_beta; new_beta=P_s.transpose()*new_beta; new_beta=Q_s.transpose()*new_beta; new_beta=R_s.triangularView<Upper>().solve(new_beta); } } // normalise new_beta=new_beta/new_beta.norm(); // check whether has changed or not yet existed double difference; if (!edge.data().beta.rows()) difference=numeric_limits<double>::infinity(); else difference=(new_beta-edge.data().beta).norm(); cout << "beta norm difference is " << difference << endl; if (difference>BETA_EPSILON) { // store new message and signal depending node if beta has changed or has not yet existed edge.data().beta=new_beta; context.signal(edge.source()); cout << "beta has changed, new_beta=" << new_beta << "\nhas norm=" << new_beta.norm() << ", signalling vid=" << edge.source().id() << endl; } else { cout << "converged!\n"; } cout << "beta: " << edge.source().id() << "->" << edge.target().id() << ": " << edge.data().beta << endl; }