int igraph_revolver_p_p(const igraph_t *graph, igraph_integer_t niter, const igraph_vector_t *vtime, const igraph_vector_t *etime, const igraph_vector_t *authors, const igraph_vector_t *eventsizes, igraph_matrix_t *kernel, igraph_matrix_t *sd, igraph_matrix_t *norm, igraph_matrix_t *cites, igraph_matrix_t *expected, igraph_real_t *logprob, igraph_real_t *lognull, const igraph_matrix_t *debug, igraph_vector_ptr_t *debugres) { igraph_integer_t no_of_events; igraph_vector_t st; long int i; igraph_integer_t maxpapers=0; igraph_vector_t vtimeidx, etimeidx; igraph_lazy_inclist_t inclist; igraph_vector_long_t papers; if (igraph_vector_size(vtime) != igraph_vcount(graph)) { IGRAPH_ERROR("Invalid vtime length", IGRAPH_EINVAL); } if (igraph_vector_size(etime) != igraph_ecount(graph)) { IGRAPH_ERROR("Invalid etime length", IGRAPH_EINVAL); } no_of_events=(igraph_integer_t) igraph_vector_size(eventsizes); IGRAPH_VECTOR_INIT_FINALLY(&st, no_of_events); for (i=0; i<no_of_events; i++) { VECTOR(st)[i]=1; } IGRAPH_CHECK(igraph_vector_long_init(&papers, igraph_vcount(graph))); IGRAPH_FINALLY(igraph_vector_long_destroy, &papers); for (i=0; i<igraph_vector_size(authors); i++) { long int author=(long int) VECTOR(*authors)[i]; VECTOR(papers)[author] += 1; if (VECTOR(papers)[author] > maxpapers) { maxpapers=(igraph_integer_t) VECTOR(papers)[author]; } } igraph_vector_long_destroy(&papers); IGRAPH_FINALLY_CLEAN(1); IGRAPH_VECTOR_INIT_FINALLY(&vtimeidx, 0); IGRAPH_VECTOR_INIT_FINALLY(&etimeidx, 0); IGRAPH_CHECK(igraph_vector_order1(vtime, &vtimeidx, no_of_events)); IGRAPH_CHECK(igraph_vector_order1(etime, &etimeidx, no_of_events)); IGRAPH_CHECK(igraph_lazy_inclist_init(graph, &inclist, IGRAPH_ALL)); IGRAPH_FINALLY(igraph_lazy_inclist_destroy, &inclist); IGRAPH_PROGRESS("Revolver p-p", 0, NULL); for (i=0; i<niter; i++) { IGRAPH_ALLOW_INTERRUPTION(); if (i+1 != niter) { /* not the last iteration */ /* measure */ IGRAPH_CHECK(igraph_revolver_mes_p_p(graph, &inclist, kernel, 0 /*sd*/, 0 /*norm*/, 0/*cites*/, 0/*debug*/, 0 /*debugres*/, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers)); /* normalize */ igraph_matrix_scale(kernel, 1/igraph_matrix_sum(kernel)); /* update st */ IGRAPH_CHECK(igraph_revolver_st_p_p(graph, &inclist, &st, kernel, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers)); } else { /* measure */ IGRAPH_CHECK(igraph_revolver_mes_p_p(graph, &inclist, kernel, sd, norm, cites, debug, debugres, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers)); /* normalize */ igraph_matrix_scale(kernel, 1/igraph_matrix_sum(kernel)); /* update st */ IGRAPH_CHECK(igraph_revolver_st_p_p(graph, &inclist, &st, kernel, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers)); /* expected number of citations */ if (expected) { IGRAPH_CHECK(igraph_revolver_exp_p_p(graph, &inclist, expected, kernel, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers)); } /* error calculation */ if (logprob || lognull) { IGRAPH_CHECK(igraph_revolver_error_p_p(graph, &inclist, kernel, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, authors, eventsizes, maxpapers, logprob, lognull)); } } IGRAPH_PROGRESS("Revolver p-p", 100.0*(i+1)/niter, NULL); } igraph_lazy_inclist_destroy(&inclist); igraph_vector_destroy(&etimeidx); igraph_vector_destroy(&vtimeidx); igraph_vector_destroy(&st); IGRAPH_FINALLY_CLEAN(4); return 0; }
double Matrix::sum() const noexcept { return igraph_matrix_sum(ptr()); }
int igraph_revolver_d_d(const igraph_t *graph, igraph_integer_t niter, const igraph_vector_t *vtime, const igraph_vector_t *etime, igraph_matrix_t *kernel, igraph_matrix_t *sd, igraph_matrix_t *norm, igraph_matrix_t *cites, igraph_matrix_t *expected, igraph_real_t *logprob, igraph_real_t *lognull, const igraph_matrix_t *debug, igraph_vector_ptr_t *debugres) { igraph_integer_t no_of_events, vnoev, enoev; igraph_vector_t st; long int i; igraph_integer_t maxdegree; igraph_vector_t vtimeidx, etimeidx; igraph_lazy_inclist_t inclist; if (igraph_vector_size(vtime) != igraph_vcount(graph)) { IGRAPH_ERROR("Invalid vtime length", IGRAPH_EINVAL); } if (igraph_vector_size(etime) != igraph_ecount(graph)) { IGRAPH_ERROR("Invalid etime length", IGRAPH_EINVAL); } vnoev=(igraph_integer_t) igraph_vector_max(vtime)+1; enoev=(igraph_integer_t) igraph_vector_max(etime)+1; no_of_events= vnoev > enoev ? vnoev : enoev; IGRAPH_VECTOR_INIT_FINALLY(&st, no_of_events); for (i=0; i<no_of_events; i++) { VECTOR(st)[i]=1; } IGRAPH_CHECK(igraph_maxdegree(graph, &maxdegree, igraph_vss_all(), IGRAPH_ALL, IGRAPH_LOOPS)); IGRAPH_VECTOR_INIT_FINALLY(&vtimeidx, 0); IGRAPH_VECTOR_INIT_FINALLY(&etimeidx, 0); IGRAPH_CHECK(igraph_vector_order1(vtime, &vtimeidx, no_of_events)); IGRAPH_CHECK(igraph_vector_order1(etime, &etimeidx, no_of_events)); IGRAPH_CHECK(igraph_lazy_inclist_init(graph, &inclist, IGRAPH_ALL)); IGRAPH_FINALLY(igraph_lazy_inclist_destroy, &inclist); IGRAPH_PROGRESS("Revolver d-d", 0, NULL); for (i=0; i<niter; i++) { IGRAPH_ALLOW_INTERRUPTION(); if (i+1 != niter) { /* not the last iteration */ /* measure */ IGRAPH_CHECK(igraph_revolver_mes_d_d(graph, &inclist, kernel, 0 /*sd*/, 0 /*norm*/, 0/*cites*/, 0/*debug*/, 0 /*debugres*/, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, maxdegree)); /* normalize */ igraph_matrix_scale(kernel, 1/igraph_matrix_sum(kernel)); /* update st */ IGRAPH_CHECK(igraph_revolver_st_d_d(graph, &inclist, &st, kernel, vtime, &vtimeidx, etime, &etimeidx, no_of_events)); } else { /* measure */ IGRAPH_CHECK(igraph_revolver_mes_d_d(graph, &inclist, kernel, sd, norm, cites, debug, debugres, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, maxdegree)); /* normalize */ igraph_matrix_scale(kernel, 1/igraph_matrix_sum(kernel)); /* update st */ IGRAPH_CHECK(igraph_revolver_st_d_d(graph, &inclist, &st, kernel, vtime, &vtimeidx, etime, &etimeidx, no_of_events)); /* expected number of citations */ if (expected) { IGRAPH_CHECK(igraph_revolver_exp_d_d(graph, &inclist, expected, kernel, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, maxdegree)); } /* error calculation */ if (logprob || lognull) { IGRAPH_CHECK(igraph_revolver_error_d_d(graph, &inclist, kernel, &st, vtime, &vtimeidx, etime, &etimeidx, no_of_events, maxdegree, logprob, lognull)); } } IGRAPH_PROGRESS("Revolver d-d", 100.0*(i+1)/niter, NULL); } igraph_lazy_inclist_destroy(&inclist); igraph_vector_destroy(&etimeidx); igraph_vector_destroy(&vtimeidx); igraph_vector_destroy(&st); IGRAPH_FINALLY_CLEAN(4); return 0; }