Example #1
0
 std::string save_vertex(const graph_type::vertex_type& v) {
  std::stringstream sstream;
  if (is_user(v)) {
    const std::vector<std::pair<double, graphlab::vertex_id_type> >& top_rated 
        = v.data().top_rated;
    const std::vector<std::pair<double, graphlab::vertex_id_type> >& top_pred
        = v.data().top_pred;
    if (top_rated.size() < 10 || top_pred.size() == 0) {
      return "";
    }
    // save top rated
    sstream << v.id() << " "; 
    sstream << pair2str(top_rated[0]); 
    for (size_t i = 1; i < top_rated.size(); ++i) {
      sstream << "," <<  (pair2str(top_rated[i]));
    }
    // save top pred
    sstream << " ";
    sstream << pair2str(top_pred[0]);
    for (size_t i = 1; i < top_pred.size(); ++i) {
      sstream << "," << (pair2str(top_pred[i]));
    }
    sstream << "\n";
    return sstream.str();
  } else {
    return "";
  }
 }
Example #2
0
 void transform_ortho(graph_type::vertex_type & vertex){
   assert(curMat != NULL && curMat->start_offset < pcurrent->offset);
   for (int i=curMat->start_offset; i< pcurrent->offset; i++){
     //assert(alphas.pvec[i-curMat->start_offset] != 0);
     vertex.data().pvec[pcurrent->offset] -= alphas.pvec[i-curMat->start_offset] * vertex.data().pvec[i]; 
   }
 }
Example #3
0
 std::string save_vertex(const graph_type::vertex_type& vtx)
 {
     std::stringstream strm;
     strm << vtx.id() << "\t" << vtx.data().dist << "\n";
     if (vtx.data().dist == std::numeric_limits<distance_type>::max())
         return "";
     else
         return strm.str();
 }
Example #4
0
gather_type output_vector(const graph_type::vertex_type & vertex){
   assert(pcurrent && pcurrent->offset >= 0 && pcurrent->offset < vertex.data().pvec.size());
   gather_type ret;
   assert(pcurrent->end - pcurrent->start > 0);
   assert(vertex.id() - pcurrent->start >= 0);
   ret.pvec = vec::Zero(pcurrent->end - pcurrent->start);
   ret.pvec[vertex.id() - pcurrent->start] = vertex.data().pvec[pcurrent->offset];
   return ret;
}
Example #5
0
map_join_pair collect_map (const graph_type::vertex_type& center,
                           graph_type::edge_type& edge,
                           const graph_type::vertex_type& other) {
  map_join_pair ret;
  if (edge.data().role == edge_data::TRAIN) {
    ret.first.data[other.id()] = edge.data().obs; // save the old rating
  } else {
    // use prediction
    double pred = center.data().factor.dot(other.data().factor);
    ret.second.data[other.id()] = pred; // save the prediction
  }
  return ret;
}
Example #6
0
gather_type map_reduce_ortho(const graph_type::vertex_type & vertex){
  gather_type ret;
  assert(curoffset >= 0);
  assert(curMat && curMat->start_offset - pcurrent->offset);
  ret.pvec = vec::Zero(curoffset);
  assert(curMat != NULL && curMat->start_offset < pcurrent->offset);
  //for (int i=mat.start_offset; i< current.offset; i++){
  for (int i=curMat->start_offset; i< pcurrent->offset; i++){
    ret.pvec[i - curMat->start_offset] = vertex.data().pvec[i] * vertex.data().pvec[pcurrent->offset];
  }
  //printf("map_Reduce_ortho: node %d\n", vertex.id());
  //std::cout<<ret.pvec<<std::endl;
  return ret;
}
Example #7
0
void collect_function (engine_type::context_type& context,
                       graph_type::vertex_type& vertex) {
  if (is_user(vertex)) {
    map_join_pair sum = context.map_reduce<map_join_pair>(COLLECT_TASK, ALL_EDGES);
    vertex.data().top_rated = sum.first.get_top_k(10);
    vertex.data().top_pred = sum.second.get_top_k(5);
  }
}
Example #8
0
	std::string save_vertex(graph_type::vertex_type v)
	{
		stringstream strm;
		//strm << "Process id: " << dc.procid() << " : " << mpi_tools::rank() << " / " << mpi_tools::size() << "\n";
		/*char name[81];
		gethostname(name, 80);
		name[80] = 0;*/
		if( v.data().in_core ) {
			return string("1\n");
		}
		else {
			return string();
		}
	}
Example #9
0
/*
* \brief 
* Aggregates in parallel the list of items rated by each user by map reducing on all the user
* vertices connected to an item. It also counts the number of users common between the current item
* and the items in the aggregated list. It then removes the item that have less than MIN_ALLOWED_INTERSECTION
* common users. 
*/
void get_topk(engine_type::context& context, graph_type::vertex_type vertex)
{
	// Gather the list of items rated by each user.
	rated_type gather_result = graphlab::warp::map_reduce_neighborhood<rated_type, graph_type::vertex_type>(vertex, graphlab::IN_EDGES, map_get_topk, combine);

	// Get a reference to the vertex data
	vertex_data& vdata = vertex.data();

	// Store the list of similar items into the recommended items
	vdata.recommended_items = gather_result;

	// TODO: Trim the result to have only topk entries using a heap

	// Increment the num_updates to the vertex by 1
	vdata.num_updates++;
}
Example #10
0
/*
* \brief Returns the sparse vector containing all the items rated by the user vertex.
*/
rated_type map_get_topk(graph_type::edge_type edge, graph_type::vertex_type other)
{
	// return the list of items rated by the user
	const rated_type& similar_items = other.data().rated_items;

	// To hold the similarity score
	rated_type similarity_score;

	// Get the id of the current item
	id_type current_id = get_other_vertex(edge, other).id();

	// Go through all the items rated by the other user, except for current item
	for(rated_type::const_iterator cit = similar_items.begin(); cit != similar_items.end(); cit++)
		if(cit->first != current_id)
		{
			// Get the score and add only if score is valid
			// Score is invalid if common users are less than MIN_ALLOWED_INTERSECTION			
			double score = adj_cosine_similarity(item_vector[cit->first], item_vector[current_id]);
			if(score != INVALID_SIMILARITY)
				similarity_score[cit->first] = score; 
		}

	return similarity_score;
}
Example #11
0
double map_rank(const graph_type::vertex_type& v) { return v.data().pagerank; }
Example #12
0
double pagerank_sum(graph_type::vertex_type v) {
  return v.data();
}
Example #13
0
/*
 * A simple function used by graph.transform_vertices(init_vertex);
 * to initialize the vertes data.
 */
void init_vertex(graph_type::vertex_type& vertex) { vertex.data() = 1; }
Example #14
0
bool select_in_range(const graph_type::vertex_type & vertex){
   return vertex.id() >= (uint)pcurrent->start && vertex.id() < (uint)pcurrent->end;
}
Example #15
0
 std::string save_vertex(graph_type::vertex_type v) {
   std::stringstream strm;
   strm << v.id() << "\t" << v.data() << "\n";
   return strm.str();
 }
Example #16
0
gather_type calc_norm(const graph_type::vertex_type & vertex){
  gather_type ret;
  assert(pcurrent && pcurrent->offset < vertex.data().pvec.size());
  ret.training_rmse = pow(vertex.data().pvec[pcurrent->offset], 2);
  return ret;
}
Example #17
0
void init_vertex(graph_type::vertex_type& vertex)
{

    vertex.data().dist = std::numeric_limits<distance_type>::max();
}
Example #18
0
float_max floatMaxAggregator(pagerank::icontext_type& context, const graph_type::vertex_type& vertex) {
	return float_max(vertex.data());
}
Example #19
0
 std::string save_vertex(graph_type::vertex_type v) {
   std::stringstream strm;
   strm << v.id() << "\t" << std::fixed << std::setprecision(17) << v.data() << "\n";
   return strm.str();
 }
Example #20
0
void assign_vec(graph_type::vertex_type & vertex){
  if (!info.is_square())
    assert(vertex.id() - pcurrent->start >= 0 && vertex.id() - pcurrent->start < curvec.size());
  vertex.data().pvec[pcurrent->offset] = curvec[vertex.id() - pcurrent->start];
}  
Example #21
0
void init_vertex(graph_type::vertex_type& vertex)
{
    vertex.data().color = vertex.id();
}
Example #22
0
max_deg_vertex_reducer find_max_deg_vertex(const graph_type::vertex_type vtx) {
    max_deg_vertex_reducer red;
    red.degree = vtx.num_in_edges() + vtx.num_out_edges();
    red.vid = vtx.id();
    return red;
}
Example #23
0
File: lda.cpp Project: SkTim/saedb
bool is_doc(const graph_type::vertex_type& vertex)//judge whether it is word and doc
{
	return vertex.num_out_edges() > 0 ? true:false;
}
Example #24
0
 gather_type map_reduce_sum_power(const graph_type::vertex_type & vertex){
   gather_type ret;
   assert(pcurrent->offset >= 0 && pcurrent->offset < vertex.data().pvec.size());
   ret.training_rmse = pow(vertex.data().pvec[pcurrent->offset], 2);
   return ret;
 }
Example #25
0
 void divide_by_sum(graph_type::vertex_type& vertex){
   assert(pcurrent->offset >= 0 && pcurrent->offset < vertex.data().pvec.size());
   vertex.data().pvec[pcurrent->offset] /= sum_alpha.training_rmse;
 }
Example #26
0
 bool selected_node(const graph_type::vertex_type& vertex){
   if (info.is_square())
     return true;
   else return ((vertex.id() >= (uint)info.get_start_node(!pcurrent->transpose)) &&
       (vertex.id() < (uint)info.get_end_node(!pcurrent->transpose)));
 }
Example #27
0
 std::string save_vertex(const graph_type::vertex_type& vtx) {
     std::stringstream strm;
     strm << vtx.id() << "\t" << vtx.data().dist << "\n";
     return strm.str();
 }
Example #28
0
ActiveNode ActiveNodeAggregator(Simulate::icontext_type& context, const graph_type::vertex_type& vertex){
	if (vertex.data().actived) return ActiveNode(1.0);
	return ActiveNode();
}
Example #29
0
/**
 * \brief Get the other vertex in the edge.
 */
inline graph_type::vertex_type
get_other_vertex(const graph_type::edge_type& edge,
                 const graph_type::vertex_type& vertex) {
    return vertex.id() == edge.source().id()? edge.target() : edge.source();
}
Example #30
0
void init_lanczos_mapr( graph_type::vertex_type& vertex) {
  assert(actual_vector_len > 0);
  vertex.data().pvec = zeros(actual_vector_len);
}