本文整理汇总了C++中graphchi_vertex::num_outedges方法的典型用法代码示例。如果您正苦于以下问题:C++ graphchi_vertex::num_outedges方法的具体用法?C++ graphchi_vertex::num_outedges怎么用?C++ graphchi_vertex::num_outedges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphchi_vertex
的用法示例。
在下文中一共展示了graphchi_vertex::num_outedges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType > &vertex, graphchi_context &gcontext) {
if (gcontext.iteration == 0) {
for(int i=0; i < vertex.num_outedges(); i++) {
chivector<vid_t> * evector = vertex.outedge(i)->get_vector();
evector->clear();
assert(evector->size() == 0);
evector->add(vertex.id());
assert(evector->size() == 1);
assert(evector->get(0) == vertex.id());
}
} else {
for(int i=0; i < vertex.num_inedges(); i++) {
graphchi_edge<EdgeDataType> * edge = vertex.inedge(i);
chivector<vid_t> * evector = edge->get_vector();
assert(evector->size() >= gcontext.iteration);
for(int j=0; j < evector->size(); j++) {
vid_t expected = edge->vertex_id() + j;
vid_t has = evector->get(j);
if (has != expected) {
std::cout << "Mismatch: " << has << " != " << expected << std::endl;
}
assert(has == expected);
}
}
for(int i=0; i < vertex.num_outedges(); i++) {
vertex.outedge(i)->get_vector()->add(vertex.id() + gcontext.iteration);
}
}
vertex.set_data(gcontext.iteration + 1);
}
示例2: update
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if(gcontext.iteration == 0){
VertexDataType vertexdata = vertex.get_data();
if(!vertexdata.confirmed || !vertexdata.reconfirmed)
return ;
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(edgedata.smaller_one != 0)
std::cout<<edgedata.smaller_one<<" \t"<<edgedata.larger_one<<"\t root="<<root<<std::endl;
*/
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();
*/
}
}
}
示例3: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
//go over all samples (rows)
if ( vertex.num_outedges() > 0){
assert(vertex.id() < M);
vertex_data & row = latent_factors_inmem[vertex.id()];
assert(row.y == -1 || row.y == 1);
if (debug)
std::cout<<"Entered item " << vertex.id() << " y: " << row.y << std::endl;
row.sigma = beta*beta;
row.xT_mu = 0;
//go over all features
for(int e=0; e < vertex.num_outedges(); e++) {
uint feature_id = vertex.edge(e)->vertex_id();
edge_data edge = vertex.edge(e)->get_data();
assert(sigma_ij[feature_id] > 0);
assert(edge.x_ij == 1);
/* compute equation (6) */
row.sigma += edge.x_ij * sigma_ij[feature_id];
/* compute the sum xT*w as needed in equations (7) and (8) */
row.xT_mu += edge.x_ij * mu_ij[feature_id];
}
double prediction;
double ret = ctr_predict(row, row, row.y, prediction);
double predicted_target = prediction < 0 ? -1: 1;
if ((predicted_target == -1 && row.y == 1) || (predicted_target == 1 && row.y == -1))
err_vec[omp_get_thread_num()] += 1.0;
if (debug)
std::cout<<"Prediction was: " << prediction << " real value: " << row.y << std::endl;
liklihood_vec[omp_get_thread_num()] += ret;
assert(row.sigma > 0);
//go over all features
for(int e=0; e < vertex.num_outedges(); e++) {
edge_data edge = vertex.edge(e)->get_data();
uint feature_id = vertex.edge(e)->vertex_id();
assert(row.sigma > 0);
double product = row.y * row.xT_mu / sqrt(row.sigma);
mu_ij[feature_id] += (row.y * edge.x_ij * sigma_ij[feature_id] / sqrt(row.sigma)) * v(product);
//if (debug)
// std::cout<<"Added to edge: "<< vertex.edge(e)->vertex_id() << " product: " << product << " v(product): " << v(product) << " value: " <<(row.y * edge.x_ij * edge.sigma_ij * edge.sigma_ij / sqrt(row.sigma)) * v(product) << std::endl;
double factor = 1.0 - (edge.x_ij * sigma_ij[feature_id] / row.sigma)*w(product);
//if (debug)
// std::cout<<"Added to edge: "<< vertex.edge(e)->vertex_id() << " product: " << product << " w(product): " << w(product) << " factor: " << (1.0 - (edge.x_ij * edge.sigma_ij / row.sigma)*w(product)) << " sigma_ij " << edge.sigma_ij << " product: " << edge.sigma_ij * factor << std::endl;
assert(factor > 0);
sigma_ij[feature_id] *= factor;
assert(sigma_ij[feature_id] > 0);
}
}
}
示例4: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (first_iteration) {
vertex.set_data(SCCinfo(vertex.id()));
}
if (vertex.get_data().confirmed) {
return;
}
/* Vertices with only in or out edges cannot be part of a SCC (Trimming) */
if (vertex.num_inedges() == 0 || vertex.num_outedges() == 0) {
if (vertex.num_edges() > 0) {
// TODO: check this logic!
vertex.set_data(SCCinfo(vertex.id()));
}
vertex.remove_alledges();
return;
}
remainingvertices = true;
VertexDataType vertexdata = vertex.get_data();
bool propagate = false;
if (gcontext.iteration == 0) {
vertexdata = vertex.id();
propagate = true;
/* Clean up in-edges. This would be nicer in the messaging abstraction... */
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);
}
} else {
/* Loop over in-edges and choose minimum color */
vid_t minid = vertexdata.color;
for(int i=0; i < vertex.num_inedges(); i++) {
minid = std::min(minid, vertex.inedge(i)->get_data().neighbor_label(vertex.id(), vertex.inedge(i)->vertexid));
}
if (minid != vertexdata.color) {
vertexdata.color = minid;
propagate = true;
}
}
vertex.set_data(vertexdata);
if (propagate) {
for(int i=0; i < vertex.num_outedges(); i++) {
bidirectional_label edgedata = vertex.outedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.outedge(i)->vertexid) = vertexdata.color;
vertex.outedge(i)->set_data(edgedata);
gcontext.scheduler->add_task(vertex.outedge(i)->vertexid, true);
}
}
}
示例5: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if ( vertex.num_outedges() > 0){
vertex_data & user = latent_factors_inmem[vertex.id()];
memset(&user.weight[0], 0, sizeof(double)*D);
for(int e=0; e < vertex.num_outedges(); e++) {
vertex_data & movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
user.weight += movie.weight;
}
// sqrt(|N(u)|)
float usrNorm = double(1.0/sqrt(vertex.num_outedges()));
//sqrt(|N(u)| * sum_j y_j
user.weight *= usrNorm;
vec step = zeros(D);
// main algorithm, see Koren's paper, just below below equation (16)
for(int e=0; e < vertex.num_outedges(); e++) {
vertex_data & movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
float observation = vertex.edge(e)->get_data();
double estScore;
rmse_vec[omp_get_thread_num()] += svdpp_predict(user, movie,observation, estScore);
// e_ui = r_ui - \hat{r_ui}
float err = observation - estScore;
assert(!std::isnan(rmse_vec[omp_get_thread_num()]));
vec itmFctr = movie.pvec;
vec usrFctr = user.pvec;
//q_i = q_i + gamma2 *(e_ui*(p_u + sqrt(N(U))\sum_j y_j) - gamma7 *q_i)
for (int j=0; j< D; j++)
movie.pvec[j] += svdpp.itmFctrStep*(err*(usrFctr[j] + user.weight[j]) - svdpp.itmFctrReg*itmFctr[j]);
//p_u = p_u + gamma2 *(e_ui*q_i -gamma7 *p_u)
for (int j=0; j< D; j++)
user.pvec[j] += svdpp.usrFctrStep*(err *itmFctr[j] - svdpp.usrFctrReg*usrFctr[j]);
step += err*itmFctr;
//b_i = b_i + gamma1*(e_ui - gmma6 * b_i)
movie.bias += svdpp.itmBiasStep*(err-svdpp.itmBiasReg* movie.bias);
//b_u = b_u + gamma1*(e_ui - gamma6 * b_u)
user.bias += svdpp.usrBiasStep*(err-svdpp.usrBiasReg* user.bias);
}
step *= float(svdpp.itmFctr2Step*usrNorm);
//gamma7
double mult = svdpp.itmFctr2Step*svdpp.itmFctr2Reg;
for(int e=0; e < vertex.num_edges(); e++) {
vertex_data& movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
//y_j = y_j + gamma2*sqrt|N(u)| * q_i - gamma7 * y_j
movie.weight += step - mult * movie.weight;
}
}
}
示例6: update
/**
* Vertex update function - computes the least square step
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
vertex_data & vdata = latent_factors_inmem[vertex.id()];
mat XtX = mat::Zero(D, D);
vec Xty = vec::Zero(D);
bool compute_rmse = (vertex.num_outedges() > 0);
// Compute XtX and Xty (NOTE: unweighted)
for(int e=0; e < vertex.num_edges(); e++) {
float observation = vertex.edge(e)->get_data();
vertex_data & nbr_latent = latent_factors_inmem[vertex.edge(e)->vertex_id()];
Xty += nbr_latent.pvec * observation;
XtX += nbr_latent.pvec * nbr_latent.pvec.transpose();
if (compute_rmse) {
double prediction;
rmse_vec[omp_get_thread_num()] += sparse_als_predict(vdata, nbr_latent, observation, prediction);
}
}
double regularization = lambda;
if (regnormal)
lambda *= vertex.num_edges();
for(int i=0; i < D; i++) XtX(i,i) += regularization;
bool isuser = vertex.id() < (uint)M;
if (algorithm == SPARSE_BOTH_FACTORS || (algorithm == SPARSE_USR_FACTOR && isuser) ||
(algorithm == SPARSE_ITM_FACTOR && !isuser)){
double sparsity_level = 1.0;
if (isuser)
sparsity_level -= user_sparsity;
else sparsity_level -= movie_sparsity;
vdata.pvec = CoSaMP(XtX, Xty, (int)ceil(sparsity_level*(double)D), 10, 1e-4, D);
}
else vdata.pvec = XtX.selfadjointView<Eigen::Upper>().ldlt().solve(Xty);
}
示例7: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
//go over all user nodes
if ( vertex.num_outedges() > 0){
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();
vertex_data & movie = latent_factors_inmem[vertex.edge(e)->vertex_id()];
double estScore;
rmse_vec[omp_get_thread_num()] += sgd_predict(user, movie, observation, estScore);
double err = observation - estScore;
if (std::isnan(err) || std::isinf(err))
logstream(LOG_FATAL)<<"SGD got into numerical error. Please tune step size using --sgd_gamma and sgd_lambda" << std::endl;
//NOTE: the following code is not thread safe, since potentially several
//user nodes may updates this item gradient vector concurrently. However in practice it
//did not matter in terms of accuracy on a multicore machine.
//if you like to defend the code, you can define a global variable
//mutex mymutex;
//
//and then do: mymutex.lock()
movie.pvec += sgd_gamma*(err*user.pvec - sgd_lambda*movie.pvec);
//and here add: mymutex.unlock();
user.pvec += sgd_gamma*(err*movie.pvec - sgd_lambda*user.pvec);
}
}
}
示例8: update
/**
* Vertex update function - computes the least square step
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
vertex_data & vdata = latent_factors_inmem[vertex.id()];
bool isuser = vertex.id() < M;
mat XtX = mat::Zero(D, D);
vec Xty = vec::Zero(D);
bool compute_rmse = (vertex.num_outedges() > 0);
// Compute XtX and Xty (NOTE: unweighted)
for(int e=0; e < vertex.num_edges(); e++) {
const edge_data & edge = vertex.edge(e)->get_data();
float observation = edge.weight;
vertex_data & nbr_latent = latent_factors_inmem[vertex.edge(e)->vertex_id()];
Xty += nbr_latent.pvec * observation;
XtX.triangularView<Eigen::Upper>() += nbr_latent.pvec * nbr_latent.pvec.transpose();
if (compute_rmse) {
double prediction;
rmse_vec[omp_get_thread_num()] += pmf_predict(vdata, nbr_latent, observation, prediction, (void*)&edge.avgprd);
vertex.edge(e)->set_data(edge);
}
}
double regularization = lambda;
if (regnormal)
lambda *= vertex.num_edges();
for(int i=0; i < D; i++) XtX(i,i) += regularization;
// Solve the least squares problem with eigen using Cholesky decomposition
mat iAi_;
bool ret =inv((isuser? A_U : A_V) + alpha * XtX, iAi_);
assert(ret);
vec mui_ = iAi_*((isuser? (A_U*mu_U) : (A_V*mu_V)) + alpha * Xty);
vdata.pvec = mvnrndex(mui_, iAi_, D, 0);
assert(vdata.pvec.size() == D);
}
示例9: 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();
}
}
示例10: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VType, EType> &v, graphchi_context &ginfo) {
//array[v.id()]++;
if(v.num_edges() == 0) return;
if (ginfo.iteration == 0) {
//int partid = getPId(v.id());
vid_t newid = getNewId(v.id());
v.set_data(newid);
for(int i=0; i<v.num_edges(); i++){
graphchi_edge<EType> * edge = v.edge(i);
EType edata = edge->get_data();
edata.my_label(v.id(), edge->vertex_id()) = newid;
edge->set_data(edata);
}
} else if(ginfo.iteration == 1){
/*
if(v.id() == 0){
fprintf(fp_list, "%u %u\n", num_vertices, num_edges);
}
*/
if(v.num_outedges() > 0){
vid_t mylabel = v.get_data();
for(int i=0; i<v.num_outedges(); i++){
graphchi_edge<EType> * edge = v.outedge(i);
EType edata = edge->get_data();
vid_t nblabel = edata.nb_label(v.id(), edge->vertex_id());
//vid_t nb_id = edge->vertex_id();
assert(mylabel != nblabel);
if(!flag_weight){
lock.lock();
fprintf(fp_list, "%u\t%u\n", mylabel, nblabel);
lock.unlock();
}else{
lock.lock();
fprintf(fp_list, "%u\t%u\t%.3f\n", mylabel, nblabel, edata.weight);
lock.unlock();
}
//edge->set_data(edata);
}
}/*else{
fprintf(fp_list, "\n");
}*/
}
}
示例11: 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);
}
}
示例12: update
/**
* Vertex update function - computes the least square step
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
vertex_data & vdata = latent_factors_inmem[vertex.id()];
if (debug)
logstream(LOG_DEBUG)<<"Entering node: " << vertex.id() << " seed? " << vdata.seed << " in vector: " << vdata.pvec << std::endl;
if (vdata.seed || vertex.num_outedges() == 0) //if this is a seed node, don't do anything
return;
vec ret = zeros(D);
for(int e=0; e < vertex.num_outedges(); e++) {
float weight = vertex.edge(e)->get_data();
assert(weight != 0);
vertex_data & nbr_latent = latent_factors_inmem[vertex.edge(e)->vertex_id()];
ret += weight * nbr_latent.pvec;
}
//normalize probabilities
assert(sum(ret) != 0);
ret = ret / sum(ret);
vdata.pvec = alpha * vdata.pvec + (1-alpha)*ret;
vdata.pvec/= sum(vdata.pvec);
}
示例13: update
/**
* compute validaton AP for a single user
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (user_nodes && vertex.id() >= M)
return;
else if (!user_nodes && vertex.id() < M)
return;
vertex_data & vdata = latent_factors_inmem[vertex.id()];
vec ratings = zeros(vertex.num_outedges());
vec real_vals = zeros(vertex.num_outedges());
if (ratings.size() > 0){
users_vec[omp_get_thread_num()]++;
int j=0;
int real_click_count = 0;
for(int e=0; e < vertex.num_outedges(); e++) {
const EdgeDataType & observation = vertex.edge(e)->get_data();
vertex_data & pdata = latent_factors_inmem[vertex.edge(e)->vertex_id()];
double prediction;
(*pprediction_func)(vdata, pdata, observation, prediction, NULL);
ratings[j] = prediction;
real_vals[j] = observation;
if (observation > 0)
real_click_count++;
j++;
}
int count = 0;
double ap = 0;
ivec pos = sort_index(ratings);
for (int j=0; j< std::min(ap_number, (int)ratings.size()); j++){
if (real_vals[pos[ratings.size() - j - 1]] > 0)
ap += (++count * 1.0/(j+1));
}
if (real_click_count > 0 )
ap /= real_click_count;
else ap = 0;
sum_ap_vec[omp_get_thread_num()] += ap;
}
}
示例14: 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);
}
}
}
}
示例15: update_edge_data
/**
* Update the weigthed edge chivector
* We first obtain the edge weight from the first element, sum them, then update the
* second item by eacg edge's weight
*/
void update_edge_data(graphchi_vertex<VertexDataType, EdgeDataType> &v, float quota, bool first){
float sum = 0.0;
//if(first)
for(int i=0; i < v.num_outedges(); i++) {
graphchi_edge<EdgeDataType> * edge = v.outedge(i);
if (edge != NULL) {
chivector<float> * evector = edge->get_vector();
//std::cout << evector->size() << std::endl;
/*if (first)
assert(evector->size() == 1);
else
assert(evector->size() == 2);
assert(evector->size() == 2);*/
std::cout << v.id() << " with data: " << evector->get(0) << std::endl;
sum += evector->get(0);
/*if (first){
evector->add(sum);
assert(evector->size() == 2);
}*/
}
}
for(int i=0; i < v.num_outedges(); i++) {
graphchi_edge<EdgeDataType> * edge = v.outedge(i);
if (edge != NULL) {
chivector<float> * evector = edge->get_vector();
// assert(evector->size() == 2);
float val = quota * evector->get(0) / sum;
//evector->set(1, val);
if(first && (evector->size() == 1))
evector->add(val);
evector->set(1, val);
//std::cout << v.id() << " with data: " << evector->get(0) << std::endl;
}
}
}