/** * Grab pivot's adjacency list into memory. */ int load_edges_into_memory(graphchi_vertex<uint32_t, edge_data> &v) { assert(is_pivot(v.id())); assert(is_user(v.id())); int num_edges = v.num_edges(); dense_adj dadj; for(int i=0; i<num_edges; i++) set_new( dadj.edges, v.edge(i)->vertex_id(), v.edge(i)->get_data().up_weight); //dadj.ratings = zeros(N); dadj.vid = v.id(); adjs[v.id() - pivot_st] = dadj; assert(v.id() - pivot_st < adjs.size()); __sync_add_and_fetch(&grabbed_edges, num_edges /*edges_to_larger_id*/); return num_edges; }
/** * add weighted ratings for each linked item * */ double compute_ratings(graphchi_vertex<uint32_t, edge_data> &item, vid_t user_pivot, float user_item_edge_weight) { assert(is_pivot(user_pivot)); if (!allow_zeros) assert(user_item_edge_weight != 0); else { if (user_item_edge_weight == 0) return 0; } dense_adj &pivot_edges = adjs[user_pivot - pivot_st]; if (!get_val(pivot_edges.edges, item.id())){ if (debug) std::cout<<"Skipping item pivot pair since not connected!" << item.id() << std::endl; return 0; } int num_edges = item.num_edges(); if (debug) std::cout<<"Found " << num_edges << " edges from item : " << item.id()-M+1 << std::endl; //if there are not enough neighboring user nodes to those two items there is no need //to actually count the intersection if (num_edges < min_allowed_intersection || nnz(pivot_edges.edges) < min_allowed_intersection){ if (debug) std::cout<<"skipping item pivot pair since < min_allowed_intersection" << std::endl; return 0; } for(int i=0; i < num_edges; i++){ vid_t other_item = item.edge(i)->vertex_id(); //user node, continue if (other_item < M ){ if (debug) std::cout<<"skipping an edge to item " << other_item << std::endl; continue; } //other item node assert(is_item(other_item)); assert(other_item != item.id()); bool up = item.id() < other_item; if (debug) std::cout<<"Checking now edge number " << i << " " << item.id()-M+1 << " -> " << other_item-M+1 << " weight: " << item.edge(i)->get_data().up_weight + item.edge(i)->get_data().down_weight << std::endl; if ((up && item.edge(i)->get_data().up_weight == 0) || (!up && item.edge(i)->get_data().down_weight == 0)){ if (debug) std::cout<<"skipping edge with wrong direction to " << other_item-M+1 << std::endl; continue; } if (get_val(pivot_edges.edges, other_item)){ if (debug) std::cout<<"skipping edge to " << other_item << " because alrteady connected to pivot" << std::endl; continue; } assert(get_val(pivot_edges.edges, item.id()) != 0); double weight = item.edge(i)->get_data().up_weight+ item.edge(i)->get_data().down_weight; if (weight == 0) logstream(LOG_FATAL)<<"Bug: found zero edge weight between: " << item.id()-M+input_file_offset << " -> " << other_item-M+input_file_offset <<std::endl; if (weight <= 1){ if (debug) std::cout<<"skipping edge to " << item.id()-M+1 << " -> " << other_item-M+1 << " because of similarity is smaller or equal to one: " << weight << std::endl; continue; } pivot_edges.mymutex.lock(); //add weight according to equation (15) in the probabalistic item similarity paper set_val(pivot_edges.ratings, other_item-M, get_val(pivot_edges.ratings, other_item-M) + ((user_item_edge_weight-0.5)/0.5)* (weight- 1)); if (debug){ std::cout<<"Adding weight: " << (((user_item_edge_weight-0.5)/0.5)* (weight- 1)) << " to item: " << other_item-M+1 << " for user: "******" weight-1: " << weight-1<<std::endl; std::cout<<pivot_edges.ratings<<std::endl; } pivot_edges.mymutex.unlock(); } if (debug) std::cout<<"Finished user pivot " << user_pivot << std::endl; return 0; }
/** * add weighted ratings for each linked item * */ double compute_ratings(graphchi_vertex<uint32_t, edge_data> &item, vid_t user_pivot, float edge_weight) { assert(is_pivot(user_pivot)); if (!allow_zeros) assert(edge_weight != 0); else if (edge_weight == 0) { zero_edges++; return 0; } dense_adj &pivot_edges = adjs[user_pivot - pivot_st]; if (!get_val(pivot_edges.edges, item.id())) { if (debug) Rcpp::Rcerr<<"Skipping item pivot pair since not connected!" << item.id() << std::endl; return 0; } int num_edges = item.num_edges(); if (debug) Rcpp::Rcerr<<"Found " << num_edges << " edges from item : " << item.id() << std::endl; //if there are not enough neighboring user nodes to those two items there is no need //to actually count the intersection if (num_edges < min_allowed_intersection || nnz(pivot_edges.edges) < min_allowed_intersection) { if (debug) Rcpp::Rcerr<<"skipping item pivot pair since < min_allowed_intersection" << std::endl; return 0; } for(int i=0; i < num_edges; i++) { vid_t other_item = item.edge(i)->vertex_id(); assert(other_item - M >= 0); bool up = item.id() < other_item; if (debug) Rcpp::Rcerr<<"Checking now edge: " << other_item << std::endl; if (is_user(other_item)) { if (debug) Rcpp::Rcerr<<"skipping edge to user " << other_item << std::endl; continue; } if (!undirected && ((up && item.edge(i)->get_data().up_weight == 0) || (!up && item.edge(i)->get_data().down_weight == 0))) { if (debug) Rcpp::Rcerr<<"skipping edge with wrong direction to " << other_item << std::endl; continue; } if (get_val(pivot_edges.edges, other_item)) { if (debug) Rcpp::Rcerr<<"skipping edge to " << other_item << " because alrteady connected to pivot" << std::endl; continue; } assert(get_val(pivot_edges.edges, item.id()) != 0); float weight = std::max(item.edge(i)->get_data().down_weight, item.edge(i)->get_data().up_weight); if (!allow_zeros) assert(weight != 0); else if (weight == 0) continue; pivot_edges.mymutex.lock(); set_val(pivot_edges.ratings, other_item-M, get_val(pivot_edges.ratings, other_item-M) + edge_weight * pow(weight,Q)); pivot_edges.mymutex.unlock(); if (debug) Rcpp::Rcerr<<"Adding weight: " << weight << " to item: " << other_item-M+1 << " for user: "******"Finished user pivot " << user_pivot << std::endl; return 0; }