コード例 #1
0
 /** The gather function computes XtX and Xy */
 gather_type gather(icontext_type& context, const vertex_type& vertex, 
                    edge_type& edge) const {
   if(edge.data().role == edge_data::TRAIN) {
     const vertex_type other_vertex = get_other_vertex(edge, vertex);
     return gather_type(other_vertex.data().factor, edge.data().obs);
   } else return gather_type();
 } // end of gather function
コード例 #2
0
ファイル: SSSP.cpp プロジェクト: ddmbr/pregelplus-code
    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);
    }
コード例 #3
0
 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();
 }
コード例 #4
0
ファイル: Ramsey.hpp プロジェクト: MLewsey/oklibrary
    std::string var(const edge_type& v) const {
      assert(v.size() == r);
      std::stringstream s("V");
      typename edge_type::const_iterator i = v.begin();
      s << *(i++) + 1;
      for (; i != v.end(); ++i)
	s << "S" << *i + 1;
      return s.str();
    }
コード例 #5
0
ファイル: concomp.cpp プロジェクト: 3upperm2n/PowerGraph
  // 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);
    }
  }
コード例 #6
0
ファイル: program.hpp プロジェクト: karlnapf/graphlab
	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;
	}
コード例 #7
0
ファイル: inf_max.hpp プロジェクト: xiaojingzi/saedb
	void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {

		EData ed = edge.data();
		float weight = ed.weight;

		if (  !edge.source().data().actived && ((double)rand() / RAND_MAX) < weight){
//		if (  !edge.source().data().actived && 0.5 <= weight){

			context.signal(edge.source());
		}
	}
コード例 #8
0
 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();
     }
 }
コード例 #9
0
 factor_type gather(icontext_type& context, const vertex_type& vertex, 
                    edge_type& edge) const {
   vertex_type other_vertex = get_other_vertex(edge, vertex);
   // VIOLATING THE ABSTRACTION!
   vertex_data& vdata = graph_type::vertex_type(vertex).data();
   // VIOLATING THE ABSTRACTION!
   vertex_data& other_vdata = other_vertex.data();
   factor_type& doc_topic_count = 
     is_doc(vertex) ? vdata.factor : other_vdata.factor;
   factor_type& word_topic_count = 
     is_word(vertex) ? vdata.factor : other_vdata.factor;
   ASSERT_EQ(doc_topic_count.size(), NTOPICS);
   ASSERT_EQ(word_topic_count.size(), NTOPICS);
   // run the actual gibbs sampling 
   factor_type& belief = edge.data().belief;
   const uint32_t count = edge.data().count;
   // Resample the topics
   double sum = 0, old_sum = 0;
   for(size_t t = 0; t < NTOPICS; ++t) {
     old_sum += belief[t];
     doc_topic_count[t] -= belief[t];
     word_topic_count[t] -= belief[t];
     GLOBAL_TOPIC_COUNT[t] -= belief[t];
     const double n_dt = 
       std::max(count_type(doc_topic_count[t]), count_type(0));
     ASSERT_GE(n_dt, 0);
     const double n_wt = 
       std::max(count_type(word_topic_count[t]), count_type(0)); 
     ASSERT_GE(n_wt, 0);
     const double n_t  = 
       std::max(count_type(GLOBAL_TOPIC_COUNT[t]), count_type(0)); 
     ASSERT_GE(n_t, 0);
     belief[t] = (ALPHA + n_dt) * (BETA + n_wt) / (BETA * NWORDS + n_t);
     sum += belief[t];
   } // End of loop over each token
   ASSERT_GT(sum, 0);
   if(old_sum == 0) {
     size_t asg = graphlab::random::multinomial(belief);
     for(size_t i = 0; i < NTOPICS; ++i) belief[i] = 0;
     belief[asg] = count;
     return belief;
   }
   for(size_t t = 0; t < NTOPICS; ++t) {
     belief[t] = count * (belief[t]/sum);
     doc_topic_count[t] += belief[t];
     word_topic_count[t] += belief[t];
     GLOBAL_TOPIC_COUNT[t] += belief[t];
   }
   return belief;
 } // end of gather
コード例 #10
0
        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 {
                //
            }
        }
コード例 #11
0
ファイル: lda.cpp プロジェクト: SkTim/saedb
	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;
	}
コード例 #12
0
ファイル: sssp.cpp プロジェクト: YosubShin/PowerGraph
 /**
  * \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 = get_other_vertex(edge, vertex);
     distance_type newd = vertex.data().dist + edge.data().dist;
     if (other.data().dist > newd) {
         const min_distance_type msg(newd);
         context.signal(other, msg);
     }
 } // end of scatter
コード例 #13
0
ファイル: math.hpp プロジェクト: Alienfeel/graphlab
    /* 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;
    }
コード例 #14
0
ファイル: PageRank.cpp プロジェクト: pkuwalter/evaluation
    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);

    }
コード例 #15
0
  /**
   * \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);
  }
コード例 #16
0
ファイル: lda.cpp プロジェクト: SkTim/saedb
	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);
	}
コード例 #17
0
ファイル: pagerank.cpp プロジェクト: neozhangthe1/saedb
	void scatter(icontext_type& context, const vertex_type& vertex,
			edge_type& edge) const {
		context.signal(edge.target());
	}
コード例 #18
0
 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);
 }
コード例 #19
0
ファイル: inf_max.cpp プロジェクト: HongleiZhuang/saedb
 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());
     }
 }
コード例 #20
0
ファイル: shortest_path.cpp プロジェクト: HongleiZhuang/saedb
	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());
	}
コード例 #21
0
ファイル: shortest_path.cpp プロジェクト: HongleiZhuang/saedb
	gather_type gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const
	{
		float newval = edge.data() + edge.source().data();
		return gather_type(newval);
	}
コード例 #22
0
ファイル: DynPageRank.cpp プロジェクト: ddmbr/pregelplus-code
 sum_pagerank_type gather(icontext_type& context, const vertex_type& vertex,
                          edge_type& edge) const
 {
     return sum_pagerank_type(edge.source().data().pagerank / edge.source().num_out_edges());
 }
コード例 #23
0
ファイル: AsyncCC.cpp プロジェクト: ddmbr/pregelplus-code
 min_color_type gather(icontext_type& context, const vertex_type& vertex,
                       edge_type& edge) const
 {
     return min_color_type(edge.source().data().color);
 }
コード例 #24
0
ファイル: AsyncCC.cpp プロジェクト: ddmbr/pregelplus-code
    /**
	 * \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);
    }
コード例 #25
0
ファイル: program.hpp プロジェクト: karlnapf/graphlab
	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;
	}
コード例 #26
0
ファイル: kcore.cpp プロジェクト: todayman/cs423_graphlab
	void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {
		if( edge.target().data().in_core ) {
			context.signal(edge.target());
		}
	}
コード例 #27
0
ファイル: kcore.cpp プロジェクト: todayman/cs423_graphlab
	int gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {
		return ( edge.source().data().in_core ? 1 : 0 );
	}
コード例 #28
0
 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());
 }
コード例 #29
0
ファイル: pagerank.cpp プロジェクト: neozhangthe1/saedb
	double gather(icontext_type& context, const vertex_type& vertex,
			edge_type& edge) const {
		return ((1.0 - RESET_PROB) / edge.source().num_out_edges())
				* edge.source().data();
	}