Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing edge weights when rewiring with rewire(g, keeping_degseq()) #103

Closed
briatte opened this issue Jul 27, 2015 · 4 comments
Closed

Losing edge weights when rewiring with rewire(g, keeping_degseq()) #103

briatte opened this issue Jul 27, 2015 · 4 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@briatte
Copy link

briatte commented Jul 27, 2015

Hi,

I have this perfectly nice-looking igraph object of Austrian legislators at hand:

> n
IGRAPH DNW- 67 59 -- 
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
 [1] Andreas Wabl                     ->Karl Smolle                 
 [2] DDr. Erwin Niederwieser          ->Dipl.-Vw. Dr. Dieter Lukesch
 [3] DDr. Erwin Niederwieser          ->Mag. Dr. Josef Höchtl       
 [4] Dipl.-Ing. Dr. Peter Keppelmüller->Johannes Zweytick           
 [5] Dipl.-Ing. Dr. Peter Keppelmüller->Karlheinz Kopf              
 [6] Dipl.-Ing. Dr. Peter Keppelmüller->Matthias Ellmauer           
 [7] Dipl.-Kfm. Dr. Günter Stummvoll  ->Dr. Ewald Nowotny           
 [8] Dipl.-Kfm. Dr. Günter Stummvoll  ->Friedrich Verzetnitsch      
+ ... omitted several edges

The object has edge weights assigned to the E(n)$weight attribute, as expected by many igraph functions:

> E(n)$weight
 [1]  1  1  1  1  1  1 18  1  1  2  1  2 24  1  1  1  1  1 17  1  1  1  2  1  1  1  2  1  2  1  1  1  1  1  1  1  5
[38]  1  1  1  1  1  1  1  2  1  1  6  1  1  2  1  1  1  1  2  1  1  1

I'd like to randomly rewire the edges while keeping the degree distribution fixed, so this is what I do:

r <- rewire(n, keeping_degseq())

The result looks nice at first sight…

> r
IGRAPH DNW- 67 59 -- 
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
 [1] Dipl.-Kfm. Dr. Günter Stummvoll  ->Kurt Eder                        
 [2] Mag. Dr. Heide Schmidt           ->Mag. Terezija Stoisits           
 [3] Mag. Dr. Maria Theresia Fekter   ->Dr. Peter Kostelka               
 [4] Mag. Helmut Kukacka              ->Franz Hums                       
 [5] MMag. Dr. Madeleine Petrovic     ->Sonja Ablinger                   
 [6] Dipl.-Ing. Dr. Peter Keppelmüller->Friedrich Verzetnitsch           
 [7] Karlheinz Kopf                   ->Arnold Grabner                   
 [8] Dr. Alexander Van der Bellen     ->Mag. Helmut Peter                
+ ... omitted several edges

… but many of the edge weights seem to get lost in translation:

> E(r)$weight
 [1]  1  1  2  1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[38] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I have reproduced the same issue on several similar graphs.

Am I doing something wrong here?

@gaborcsardi
Copy link
Contributor

Looks like and igraph bug. Thanks for reporting it!

library(igraph)
g <- sample_gnm(10, 20)
E(g)$weight <- seq_len(gsize(g))
g2 <- rewire(g, keeping_degseq())
E(g2)$weight
#>  [1] 11 13 18 20 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

@briatte
Copy link
Author

briatte commented Jul 27, 2015

No problem. If it helps, the number of edges weights set to NA seem to be completely random.

@ntamas ntamas added the bug an unexpected problem or unintended behavior label Sep 29, 2021
@ntamas
Copy link
Member

ntamas commented Oct 29, 2022

The C core currently implements rewiring by removing edges and adding them in a new configuration. Edge attributes are lost in the process; newly added edges will get a default value of NA. Currently this cannot be fixed in the R interface alone; the C core would need to be adjusted to provide support for rewiring while keeping attributes.

@szhorvat
Copy link
Member

Tracked here: igraph/igraph#2151

@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants