Skip to content

refactor: cleaned and updated AlphaCore Python & R implementations#3

Open
prachics wants to merge 8 commits into
friedhelmvictor:masterfrom
prachics:update-alphaCore-implementations
Open

refactor: cleaned and updated AlphaCore Python & R implementations#3
prachics wants to merge 8 commits into
friedhelmvictor:masterfrom
prachics:update-alphaCore-implementations

Conversation

@prachics
Copy link
Copy Markdown

@prachics prachics commented Apr 21, 2025

Hello Friedhelm, I am a UCF graduate student working with Dr. Akcora. I’ve cleaned up and refactored both the Python and R versions of AlphaCore, there are no changes to the core algorithm logic.
In this update we:

  • Add an extractFeatures function that scans each node’s attributes for numeric values to use as features, falling back to computing in‑degree and strength if none are found.
  • Add a safe fallback to a pseudo‑inverse when the covariance matrix is singular
  • Remove the redundant computation of x_minus_center by computing it once and reusing its transpose, saving memory.

Please let me know if you’d like any further tweaks!

@friedhelmvictor
Copy link
Copy Markdown
Owner

Hi Prachi!

Thank you for the effort!

I've tried this new version but it seems in contrast to the old version, this produces an error:

Running:

library(igraph)
library(data.table)
source("algorithms/alphaCore.R")

set.seed(1)

g <- erdos.renyi.game(200, 2/200, directed = T)
E(g)$weight <- 1:ecount(g)
V(g)$name <- paste("v", 1:vcount(g), sep="")

alphaCore(g)

used to yield:

     node     alpha batch
  1:   v1 0.0000000    18
  2:   v2 0.0000000    10
  3:   v3 0.0000000    12
  4:   v4 0.0000000     6
  5:   v5 0.4193455    24
 ---
196: v196 0.4193455    25
197: v197 0.0000000    12
198: v198 0.4193455    24
199: v199 0.0000000    11
200: v200 0.4193455    23

but with your changes yields:

Error in simple_vs_index(x, lazy_eval(args[[1]]), na_ok) :
  Unknown vertex selected

I haven't reviewed the python code yet.

Perhaps, what could be nice is to additionally add a test suite? So that it's easier to verify that the changes still lead to the same outcome?
Also, the examples in the readme would need to be updated.

@prachics
Copy link
Copy Markdown
Author

Hello Friedhelm,
Thanks for testing this so thoroughly!
I'll fix the R error, add a regression test suite, and update the README examples. I’ll keep you posted as soon as it’s fixed, let me know if you have any other suggestions in the meantime.

@prachics
Copy link
Copy Markdown
Author

Hello Friedhelm,

I've fixed the R implementation error and added test suite for both Python and R versions. The tests validate that the output matches the expected structure and values from the README examples.

All implementations now produce expected results and the test suite ensures future changes maintain the same output.

Please let me know if you'd like any further improvements!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants