static void finalize(icontext_type& context, error_aggregator& agg) {
   ASSERT_GT(agg.ntrain, 0);
   agg.train_error = std::sqrt(agg.train_error / agg.ntrain);
   context.cout() << context.elapsed_seconds() << "\t" << agg.train_error;
   if(agg.nvalidation > 0) {
     const double validation_error = 
       std::sqrt(agg.validation_error / agg.nvalidation);
     context.cout() << "\t" << validation_error; 
   }
   context.cout() << std::endl;
 }
        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 {
                //
            }
        }
Example #3
0
 edge_dir_type scatter_edges(icontext_type& context,
         const vertex_type& vertex) const {
     if (context.iteration() < ROUND)
         return graphlab::OUT_EDGES;
     else
         return graphlab::NO_EDGES;
 }
 edge_dir_type gather_edges(icontext_type& context, const vertex_type& vertex) const {
     if (context.iteration() == 0) {
         return graphlab::ALL_EDGES;
     } else {
         return graphlab::NO_EDGES;
     }
 }
void proxy_updater::apply(icontext_type& context){
  jobject vertex = context.const_vertex_data().obj();
  if (NULL == vertex) return; // BUG?
  JNIEnv *env = core::get_jni_env();
  env->CallVoidMethod(obj(), java_apply, vertex);
  handle_exception(env);
}
Example #6
0
 void aggregate(icontext_type& context, const vertex_type& vertex){
     if (!marked) {
         marked = true;
         saedb::IAggregator* active_node = context.getAggregator("active_node");
         float t = vertex.data();
         active_node->reduce(&t);
     }
 }
Example #7
0
	void apply(icontext_type& context, vertex_type& vertex,
			const graphlab::empty& empty) {
        if (context.iteration() < ROUND)
        {
            context.signal(vertex);
        }

        if(context.iteration() == 0)
        {
            return;
        }

        pagerank_type new_pagerank = 0.15 + 0.85 * sum_pagerank;

        vertex.data().pagerank = new_pagerank;

    }
Example #8
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 = 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
Example #9
0
    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);
    }
Example #10
0
    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);

    }
Example #11
0
  /**
   * \brief If the distance is smaller then update
   */
  void apply(icontext_type& context, vertex_type& vertex,
             const gather_type& total) {
    changed = false;
    if(context.iteration() == 0) {
    	changed = true;
    	vertex.data().dist = 0;
    	context.setUpdateFlag(changed);
    	return;
    	//lastchange = vertex.data().dist;
    }
    if(vertex.data().dist > total.dist) {
      changed = true;
      vertex.data().dist = total.dist;
      //lastchange = vertex.data().dist;
    }

    context.setUpdateFlag(changed);
    //std::cout << "vid=" << vertex.id() << ", val=" << vertex.data().dist << "\n";
  }
Example #12
0
  // 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 proxy_aggregator::operator()(icontext_type& context){
  
  // forward call to org.graphlab.Aggregator#exec
  JNIEnv *env = core::get_jni_env();
  env->CallVoidMethod (obj(), java_exec,
                       &context,
                       context.vertex_data().obj());
  handle_exception(env);

}
Example #14
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);
  }
Example #15
0
	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());
		}
	}
 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();
     }
 }
void proxy_updater::operator()(icontext_type& context){
  
  jobject vertex = context.const_vertex_data().obj();
  if (NULL == vertex) return; // BUG?
  
  // forward call to org.graphlab.Updater#update
  JNIEnv *env = core::get_jni_env();
  env->CallVoidMethod (obj(), java_update,
                       &context,
                       vertex);
  handle_exception(env);

}
        void apply(icontext_type& context, vertex_type& vertex, const gather_type &total) {
            if (context.iteration() == 0) {
                vertex.data().neighbors = total.get();
            } else {
                size_t d = vertex.data().neighbors.size();
                size_t t = last_msg;

                // Due to rounding errors, the results is sometimes not exactly
                // 0.0 even when it should be. Explicitly set LCC to 0 if that
                // is the case, other calculate it as tri / (degree * (degree - 1))
                double lcc = (d < 2 || t == 0) ? 0.0 : double(t) / (d * (d - 1));

                vertex.data().clustering_coef = lcc;
            }
        }
Example #19
0
	void scatter(icontext_type& context, const vertex_type& vertex,
			edge_type& edge) const {
		context.signal(edge.target());
	}
Example #20
0
 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());
     }
 }
 /**
  * \brief Signal all vertices on one side of the bipartite graph
  */
 static graphlab::empty signal_left(icontext_type& context,
                                    vertex_type& vertex) {
   if(vertex.num_out_edges() > 0) context.signal(vertex);
   return graphlab::empty();
 } // end of signal_left 
Example #22
0
	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());
	}
Example #23
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();
        context.signal(other);
    }
Example #24
0
 void scatter(icontext_type& context, const vertex_type& vertex, 
              edge_type& edge) const {
   const vertex_type other_vertex = get_other_vertex(edge, vertex);
   context.signal(other_vertex);
 } // end of scatter function
Example #25
0
	void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {
		if( edge.target().data().in_core ) {
			context.signal(edge.target());
		}
	}
void proxy_updater::scatter(icontext_type& context, const edge_type& edge){
  JNIEnv *env = core::get_jni_env();
  env->CallVoidMethod(obj(), java_scatter,
    &context, context.const_edge_data(edge).obj());
  handle_exception(env);
}
Example #27
0
	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;
	}
 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);
 }