本文整理汇总了C++中graphchi_vertex::num_inedges方法的典型用法代码示例。如果您正苦于以下问题:C++ graphchi_vertex::num_inedges方法的具体用法?C++ graphchi_vertex::num_inedges怎么用?C++ graphchi_vertex::num_inedges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphchi_vertex
的用法示例。
在下文中一共展示了graphchi_vertex::num_inedges方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
int ninedges = 0;
if (gcontext.iteration == 0) {
for(int i=0; i < vertex.num_inedges(); i++) {
vertex.inedge(i)->set_data(vertex.id());
ninedges++;
}
} else {
// Keep track of the number of edegs to ensure that
// deletion works fine.
if (vertex.get_data() != vertex.num_inedges()) {
logstream(LOG_ERROR) << "Discrepancy in edge counts: " << vertex.get_data() << " != " << vertex.num_inedges() << std::endl;
}
assert(vertex.get_data() == vertex.num_inedges());
for(int i=0; i < vertex.num_outedges(); i++) {
graphchi_edge<vid_t> * edge = vertex.outedge(i);
vid_t outedgedata = edge->get_data();
vid_t expected = edge->vertex_id() + gcontext.iteration - (edge->vertex_id() > vertex.id());
if (!is_deleted_edge_value(edge->get_data())) {
if (outedgedata != expected) {
logstream(LOG_ERROR) << outedgedata << " != " << expected << std::endl;
assert(false);
}
}
}
for(int i=0; i < vertex.num_inedges(); i++) {
vertex.inedge(i)->set_data(vertex.id() + gcontext.iteration);
if (std::rand() % 4 == 1) {
vertex.remove_inedge(i);
__sync_add_and_fetch(&ndeleted, 1);
} else {
ninedges++;
}
}
}
if (gcontext.iteration == gcontext.num_iterations - 1) {
vertex.set_data(gcontext.iteration + 1);
} else {
vertex.set_data(ninedges);
}
}
示例2: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (vertex.get_data().confirmed) {
return;
}
VertexDataType vertexdata = vertex.get_data();
bool propagate = false;
if (gcontext.iteration == 0) {
/* "Leader" of the SCC */
if (vertexdata.color == vertex.id()) {
propagate = true;
vertex.remove_alloutedges();
}
} else {
/* Loop over in-edges and see if there is a match */
bool match = false;
for(int i=0; i < vertex.num_outedges(); i++) {
if (!vertex.outedge(i)->get_data().deleted()) {
if (vertex.outedge(i)->get_data().neighbor_label(vertex.id(), vertex.outedge(i)->vertexid) == vertexdata.color) {
match = true;
break;
}
}
}
if (match) {
propagate = true;
vertex.remove_alloutedges();
vertex.set_data(SCCinfo(vertexdata.color, true));
} else {
vertex.set_data(SCCinfo(vertex.id(), false));
}
}
if (propagate) {
for(int i=0; i < vertex.num_inedges(); i++) {
bidirectional_label edgedata = vertex.inedge(i)->get_data();
if (!edgedata.deleted()) {
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = vertexdata.color;
vertex.inedge(i)->set_data(edgedata);
gcontext.scheduler->add_task(vertex.inedge(i)->vertexid, true);
}
}
}
}
示例3: update
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
assert(vertex.num_inedges() * vertex.num_outedges() <= product);
for(int i=0; i<vertex.num_outedges(); i++){
bidirectional_label edgedata = vertex.outedge(i)->get_data();
if(edgedata.is_equal()){
if(root == edgedata.my_label(vertex.id(), vertex.outedge(i)->vertexid)){
lock.lock();
fprintf(fpout, "%u\t%u\n", vertex.id(), vertex.outedge(i)->vertexid);
lock.unlock();
continue;
}
}
lock.lock();
fprintf(fpout1, "%u\t%u\n", vertex.id(), vertex.outedge(i)->vertexid);
lock.unlock();
}
}
示例4: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
//go over all user nodes
if ( vertex.num_outedges() > 0 && (algo == GLOBAL_MEAN || algo == USER_MEAN)){
vertex_data & user = latent_factors_inmem[vertex.id()];
//go over all ratings
if (algo == USER_MEAN){
for(int e=0; e < vertex.num_edges(); e++) {
float observation = vertex.edge(e)->get_data();
user.mean_rating += observation;
}
if (vertex.num_edges() > 0)
user.mean_rating /= vertex.num_edges();
}
//go over all ratings
for(int e=0; e < vertex.num_edges(); e++) {
double prediction;
float observation = vertex.edge(e)->get_data();
vertex_data & movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
rmse_vec[omp_get_thread_num()] += baseline_predict(user, movie, observation, prediction);
}
}
else if (vertex.num_inedges() > 0 && algo == ITEM_MEAN){
vertex_data & user = latent_factors_inmem[vertex.id()];
//go over all ratings
for(int e=0; e < vertex.num_edges(); e++) {
float observation = vertex.edge(e)->get_data();
user.mean_rating += observation;
}
if (vertex.num_edges() > 0)
user.mean_rating /= vertex.num_edges();
for(int e=0; e < vertex.num_edges(); e++) {
float observation = vertex.edge(e)->get_data();
double prediction;
vertex_data & movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
rmse_vec[omp_get_thread_num()] += baseline_predict(movie, user, observation, prediction);
}
}
}
示例5: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &ginfo) {
float sum=0;
if (ginfo.iteration == 0) {
/* On first iteration, initialize vertex and out-edges.
The initialization is important,
because on every run, GraphChi will modify the data in the edges on disk.
*/
for(int i=0; i < v.num_outedges(); i++) {
graphchi_edge<float> * edge = v.outedge(i);
edge->set_data(1.0 / v.num_outedges());
}
v.set_data(RANDOMRESETPROB);
} else {
/* Compute the sum of neighbors' weighted pageranks by
reading from the in-edges. */
for(int i=0; i < v.num_inedges(); i++) {
float val = v.inedge(i)->get_data();
sum += val;
}
/* Compute my pagerank */
float pagerank = RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum;
/* Write my pagerank divided by the number of out-edges to
each of my out-edges. */
if (v.num_outedges() > 0) {
float pagerankcont = pagerank / v.num_outedges();
for(int i=0; i < v.num_outedges(); i++) {
graphchi_edge<float> * edge = v.outedge(i);
edge->set_data(pagerankcont);
}
}
/* Keep track of the progression of the computation.
GraphChi engine writes a file filename.deltalog. */
ginfo.log_change(std::abs(pagerank - v.get_data()));
/* Set my new pagerank as the vertex value */
v.set_data(pagerank);
}
}
示例6: update
void update(graphchi_vertex<VertexDataType, EdgeDataType>& v, graphchi_context& ginfo)
{
if (ginfo.iteration > 0) {
float sum = 0;
for (int i = 0; i < v.num_inedges(); i++) {
sum += pr[v.inedge(i)->vertexid];
}
if (v.outc > 0) {
pr[v.id()] = (RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum) / v.outc;
} else {
pr[v.id()] = (RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum);
}
} else if (ginfo.iteration == 0) {
if (v.outc > 0)
pr[v.id()] = 1.0f / v.outc;
}
if (ginfo.iteration == ginfo.num_iterations - 1) {
/* On last iteration, multiply pr by degree and store the result */
v.set_data(v.outc > 0 ? pr[v.id()] * v.outc : pr[v.id()]);
}
}
示例7: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &ginfo) {
float sum=0;
float prv = 0.0;
float pagerankcont = 0.0;
if (ginfo.iteration == 0) {
/* On first iteration, initialize vertex and out-edges.
The initialization is important,
because on every run, GraphChi will modify the data in the edges on disk.
*/
/* For the weighted version */
update_edge_data(v, 1.0, true);
v.set_data(RANDOMRESETPROB);
//v.set_data(1.0);
} else {
/* We need to come up with the weighted version */
for(int i=0; i < v.num_inedges(); i++) {
chivector<float> * evector = v.inedge(i)->get_vector();
assert(evector->size() >= 2);
sum += evector->get(1);
//std::cout << v.id() << " with data: " << evector->get(1) << " with weight " << evector->get(0) << std::endl;
//std::cout << v.id() << " edge endpoint: " << v.inedge(i)->vertex_id() << std::endl;
//evector->clear();
}
/* Compute my pagerank */
prv = RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum;
//std::cout << "sum" << sum << "pagerank: " << prv << std::endl;
update_edge_data(v, prv, false);
/* Keep track of the progression of the computation.
GraphChi engine writes a file filename.deltalog. */
double delta = std::abs(prv - v.get_data());
//std::cout << "pagerank: " << prv << "v.data" << v.get_data() << "delta: " << delta << std::endl;
ginfo.log_change(delta);
/* Set my new pagerank as the vertex value */
v.set_data(prv);
}
}
示例8: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (gcontext.iteration == 0) {
if (is_user(vertex.id()) && vertex.num_outedges() > 0) {
vertex_data& user = latent_factors_inmem[vertex.id()];
user.pvec = zeros(D*3);
for(int e=0; e < vertex.num_outedges(); e++) {
rbm_movie mov = latent_factors_inmem[vertex.edge(e)->vertex_id()];
float observation = vertex.edge(e)->get_data();
int r = (int)(observation/rbm_scaling);
assert(r < rbm_bins);
mov.bi[r]++;
}
}
return;
} else if (gcontext.iteration == 1) {
if (vertex.num_inedges() > 0) {
rbm_movie mov = latent_factors_inmem[vertex.id()];
setRand2(mov.w, D*rbm_bins, 0.001);
for(int r = 0; r < rbm_bins; ++r) {
mov.bi[r] /= (double)vertex.num_inedges();
mov.bi[r] = log(1E-9 + mov.bi[r]);
if (mov.bi[r] > 1000) {
assert(false);
Rcpp::Rcerr<<"Numerical overflow" <<std::endl;
}
}
}
return; //done with initialization
}
//go over all user nodes
if (is_user(vertex.id()) && vertex.num_outedges()) {
vertex_data & user = latent_factors_inmem[vertex.id()];
user.pvec = zeros(3*D);
rbm_user usr(user);
vec v1 = zeros(vertex.num_outedges());
//go over all ratings
for(int e=0; e < vertex.num_outedges(); e++) {
float observation = vertex.edge(e)->get_data();
rbm_movie mov = latent_factors_inmem[vertex.edge(e)->vertex_id()];
int r = (int)(observation / rbm_scaling);
assert(r < rbm_bins);
for(int k=0; k < D; k++) {
usr.h[k] += mov.w[D*r + k];
assert(!std::isnan(usr.h[k]));
}
}
for(int k=0; k < D; k++) {
usr.h[k] = sigmoid(usr.h[k]);
if (drand48() < usr.h[k])
usr.h0[k] = 1;
else usr.h0[k] = 0;
}
int i = 0;
double prediction;
for(int e=0; e < vertex.num_outedges(); e++) {
rbm_movie mov = latent_factors_inmem[vertex.edge(e)->vertex_id()];
float observation = vertex.edge(e)->get_data();
predict1(usr, mov, observation, prediction);
int vi = (int)(prediction / rbm_scaling);
v1[i] = vi;
i++;
}
i = 0;
for(int e=0; e < vertex.num_outedges(); e++) {
rbm_movie mov = latent_factors_inmem[vertex.edge(e)->vertex_id()];
int r = (int)v1[i];
for (int k=0; k< D; k++) {
usr.h1[k] += mov.w[r*D+k];
}
i++;
}
for (int k=0; k < D; k++) {
usr.h1[k] = sigmoid(usr.h1[k]);
if (drand48() < usr.h1[k])
usr.h1[k] = 1;
else usr.h1[k] = 0;
}
i = 0;
for(int e=0; e < vertex.num_outedges(); e++) {
rbm_movie mov = latent_factors_inmem[vertex.edge(e)->vertex_id()];
float observation = vertex.edge(e)->get_data();
double prediction;
rbm_predict(user, mov, observation, prediction, NULL);
double pui = prediction / rbm_scaling;
double rui = observation / rbm_scaling;
rmse_vec[omp_get_thread_num()] += (pui - rui) * (pui - rui);
//.........这里部分代码省略.........
示例9: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
VertexDataType vertexdata; //= vertex.get_data();
//bool propagate = false;
if (gcontext.iteration == 0) {
//vertex.set_data(SCCinfo(vertex.id()));
vertexdata = vertex.get_data();
/* vertices that is not visited in Fw phase is not in the giant SCC!
* minor improve by mzj 2016/3/13
*/
if(!vertexdata.confirmed)
return;
//assert(vertexdata.color == root);
if(vertex.id() == root){
//vertexdata.confirmed = true;
vertexdata.color = vertex.id();
vertexdata.reconfirmed = true;
for(int i=0; i<vertex.num_inedges(); i++){
bidirectional_label edgedata = vertex.inedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = vertex.id();
vertex.inedge(i)->set_data(edgedata);
if(scheduler) gcontext.scheduler->add_task(vertex.inedge(i)->vertexid);
vertex.inedge(i)->set_data(edgedata);
}
vertex.set_data(vertexdata);
}else{
vertexdata.reconfirmed = false;
vertexdata.color = vertex.id();
for(int i=0; i<vertex.num_inedges(); i++){
bidirectional_label edgedata = vertex.inedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = vertex.id();
vertex.inedge(i)->set_data(edgedata);
//if(scheduler) gcontext.scheduler->add_task(vertex.outedge(i)->vertexid);
}
vertex.set_data(vertexdata);
}
//vertex.set_data(vertexdata);
} else {
vertexdata = vertex.get_data();
if(!vertexdata.confirmed)
return ;
vid_t min_color = vertexdata.color;
for(int i=0; i<vertex.num_outedges(); i++){
//min_color = std::min(min_color, vertexdata.inedge(i)->get_data().neighbor_label(vertex.id(), vertex.inedge(i)->vertexid));
if(root == (vertex.outedge(i)->get_data()).neighbor_label(vertex.id(), vertex.outedge(i)->vertexid)){
min_color = root;
break;
}
}
if(min_color != vertexdata.color){
converged = false;
//vertexdata.confirmed = true;
vertexdata.reconfirmed = true;
vertexdata.color = min_color;
for(int i=0; i<vertex.num_inedges(); i++){
bidirectional_label edgedata = vertex.inedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = min_color;
if(scheduler) gcontext.scheduler->add_task(vertex.inedge(i)->vertexid);
vertex.inedge(i)->set_data(edgedata);
}
vertex.set_data(vertexdata);
}
}
}
示例10: update
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
//For iteration 0
if (gcontext.iteration == 0) {
chivector<vid_t> * v_vector = vertex.get_vector();
v_vector->clear();
/* Initialize a json object, rvec to maintain the result vector of the current node.
* Maintain the list of outedges of the current vector.
* These outedges are the children and must match the children of the query node.
* Maintain a vector for all the nodes set to false in the current iteraion.
*/
nlohmann::json rvec;
std::vector<vid_t> vertex_outedges;
std::vector<vid_t> vertex_false;
for (int i = 0; i < vertex.num_outedges(); i++) {
vertex_outedges.push_back(vertex.outedge(i)->vertex_id());
}
/*
* Iterate through all the query nodes, and check the equality with the current node.
* If the current node matches the query node, add the dependencies of the query node to the rvec.
* If the query node does not have any dependencies, set rvec[i] as true. (This implies a direct match)
* If the query node and the current node don't match, set rvec[i] to false and add i to vertex_false.
*/
for(unsigned int i=0; i < query_json["node"].size(); i++) {
if(check_equal(vertex_json[vertex.id()],query_json["node"][i])) {
unsigned int out_d = query_json["node"][i]["out_degree"];
if(out_d == 0){
rvec[i] = true;
v_vector->add(i);
}
else if(vertex_outedges.size() == 0)
{
rvec[i] = false;
vertex_false.push_back(i);
}
else
{ for(unsigned int j=0; j <query_json["edge"].size(); j++){
unsigned int source = query_json["edge"][j]["source"], target = query_json["edge"][j]["target"];
if(i == source )
rvec[i][target] = vertex_outedges;
}
v_vector->add(i);
}
}
else
{
rvec[i] = false;
vertex_false.push_back(i);
}
}
// Access the element of rvec_map with key equal to current vertex id.
// Assign rvec as the value for current vertex id.
tbb::concurrent_hash_map<unsigned int, nlohmann::json>::accessor ac;
rvec_map.insert(ac,vertex.id());
ac->second = rvec;
ac.release();
/*
* If the size of vertex_false is not zero, changes have been made in the current iteration.
* For all the inedges, add the all the elements of vertex_false to the edge vector.
* Schedule all the inedges for the next iteration.
*
*/
if(vertex_false.size() != 0) {
for(int i = 0; i < vertex.num_inedges(); i++) {
chivector<vid_t> * e_vector = vertex.inedge(i)->get_vector();
e_vector->clear();
for(unsigned int j = 0; j< vertex_false.size(); j++){
e_vector->add(vertex_false[j]);
}
gcontext.scheduler->add_task(vertex.inedge(i)->vertex_id());
}
}
}
//For iteration 1..n
else{
/*
* Retrieve the rvec for the current node from the rvec_map.
* Intialize vertex_false to maintain the vertices set to false.
*/
tbb::concurrent_hash_map<unsigned int, nlohmann::json>::accessor ac;
rvec_map.find(ac,vertex.id());
nlohmann::json rvec = ac->second;
std::vector<vid_t> vertex_false;
chivector<vid_t> * v_vector = vertex.get_vector();
//.........这里部分代码省略.........
示例11: update
//.........这里部分代码省略.........
rvec[i][target] = vertex.num_outedges();
}
dependencies++;
}
}
else
{
rvec[i] = false;
vertex_false.push_back(i);
}
}
/*
* If the vertex has dependencies, schedule the children of the current vertex (outedges).
*/
if(dependencies != 0){
for(int i = 0; i <vertex.num_outedges();i++)
gcontext.scheduler->add_task(vertex.outedge(i)->vertex_id());
}
/*
* Vertex data is set to the number of dependencies.
* If the vertex data is greater than 0, then it is processed whenever it is scheduled in the subsequent iterations.
* If the vertex data is 0, it is not processed in the subsequent iterations.
*/
vertex.set_data(dependencies);
}
dependencies = vertex.get_data();
/*
* If the current vertex has dependencies, it has to be processed.
* Collect the edge data of all it's outgoing edges and for each outgoing edge which is updated, update the corresponding dependency.
* Else, clear all the outedges.
*/
if(dependencies != 0 ) {
nlohmann::json updates;
for(int i = 0; i < vertex.num_outedges(); i++){
chivector<vid_t> * e_vector = vertex.outedge(i)->get_vector();
int evector_size = e_vector->size();
for( int j =0; j < evector_size; j++){
vid_t t = e_vector->get(j);
if(updates[t].is_null())
updates[t] = 1;
else {
int n = updates[t];
updates[t] = n +1;
}
}
e_vector->clear();
}
for(vid_t i = 0; i < updates.size(); i++ ) {
if(updates[i].is_null())
continue;
int cur_updates = updates[i];
for(size_t j = 0; j < rvec.size(); j++){
if(rvec[j].is_boolean())
continue;
if(rvec[j][i].is_number()){
int prev_dep = rvec[j][i];
if(prev_dep <= cur_updates) {
rvec[j] = false;
vertex_false.push_back(j);
dependencies --;
}
else
rvec[j][i] = prev_dep - cur_updates;
}
}
}
vertex.set_data(dependencies);
} else {
for(int i = 0; i < vertex.num_outedges(); i++){
chivector<vid_t> * e_vector = vertex.outedge(i)->get_vector();
if(e_vector->size())
e_vector ->clear();
}
}
/*
* If a node has been set to false in the current iteration, propagate the update through all the inedges.
*/
if(vertex_false.size() != 0){
for(int i=0; i < vertex.num_inedges(); i++){
chivector<vid_t> * e_vector = vertex.inedge(i) -> get_vector();
for(unsigned int j = 0; j < vertex_false.size(); j++)
e_vector->add(vertex_false[j]);
gcontext.scheduler->add_task(vertex.inedge(i)->vertex_id());
}
}
// Update the result vector and release the accsessor.
ac->second = rvec;
ac.release();
}