infomap_ecology_package icon indicating copy to clipboard operation
infomap_ecology_package copied to clipboard

Cannot use relax rates with extended format of intralayer edges.

Open PritchardAJP opened this issue 3 weeks ago • 1 comments

Hello,

Thank you for creating and supporting this package!

I had been running my code with no issues on my computer, but - when transferring my code to a new computer - I am getting a consistent error.


 MLNet <- create_multilayer_network(list_of_layers = UniAdj, layer_attributes = layer_attrib,
                                       interlayer_links = NULL, bipartite = F, directed = (flow == "directed"))

  listR <- list()
  MLNet$inter <- NULL
  relaxrate_modules <- NULL

  for (r in seq(0.001,1, by = 0.0999)){
   
   modules_relax_rate <- run_infomap_multilayer(MLNet, relax = T, flow_model = flow, silent = T, trials = 200, seed = 497294,  multilayer_relax_rate = r, multilayer_relax_limit_up = 1, multilayer_relax_limit_down = 0, temporal_network = T)

    listR[[length(listR) + 1]] <- modules_relax_rate
    names(listR)[length(listR)] <- r
    modules_relax_rate$modules$relax_rate <- r
    relaxrate_modules <- rbind(relaxrate_modules, modules_relax_rate$modules)
  }

This is the error, which breaks at the first step of the for loop:

[1] 0.001
Infomap version 2.7.1 compiled with OpenMP
See www.mapequation.org for terms of use.
Error in run_infomap_multilayer(NEE2017, relax = T, flow_model = flow,  : 
  Cannot use relax rates with extended format of intralayer edges.

It seems that the run_infomap_multilayer function is scanning my MLNet object to see if there are five columns. To be clear, I have no interlayer connections and am relying on the relax rate's 'teleportation' to toggle community flow through a temporal network.

> table(MLNet$extended_ids$layer_from == MLNet$extended_ids$layer_to)

TRUE 
 838

> head(MLNet$extended_ids)
# A tibble: 6 × 5
  layer_from node_from layer_to node_to weight
       <int>     <int>    <int>   <int>  <dbl>
1          1         1        1      14      2
2          1         1        1      15      3
3          1         1        1      16      1
4          1         1        1      35      1
5          1         2        1      11      1
6          1         2        1      26      1

I am not sure what version of InfoMapEcology I was using on my other computer, but this computer is using the most up to date version. My code was working on the other machine as of 6/20/2025. I can see what version of infomap that had, if necessary. Though the old version of create_multilayer_object() had an intra_output_extended=F argument, I cannot find where that would be applicable in the present code.

Please advise at your earliest convience.

Edited to remove italics formatting from code, as it just showed up in the code as double asterisks.

PritchardAJP avatar Nov 13 '25 20:11 PritchardAJP

I think that I have located the issue, but please confirm that I am not erroneously breaking something. Additionally, I think the function's code would need to be fixed on GitHub, if I am correct. So, I have not closed this issue.

In lines 21-27, the run_infomap_multilayer() function has:

  intra <- NULL
  if (relax == T) {
    intra <- M$extended_ids[M$extended_ids$layer_from == 
      M$extended_ids$layer_to, c("layer_from", "node_from", 
      "layer_to", "node_to", "weight")]
    colnames(intra)[1] <- "layer"
  }

The problem here is that the "layer_to" column is retained, which is flagged later in the code when screening for five columns. Specifically, lines 64-66:

    if (ncol(M$intra) == 5) {
      stop("Cannot use relax rates with extended format of intralayer edges.")
    }

I had been trying to fix the latter selection or the object I submitted in the function's arguments. I think, however, the fix is as simpled as adding a line to the above (L21-27) code to remove the "layer_to" column, which has been made defunct by confirming "later_to" and "layer_from" are equivalent (then, renaming "layer_from" to "layer").

  intra <- NULL
  if (relax == T) {
    intra <- M$extended_ids[M$extended_ids$layer_from == 
      M$extended_ids$layer_to, c("layer_from", "node_from", 
      "layer_to", "node_to", "weight")]
    colnames(intra)[1] <- "layer"
  intra <- intra[,-3]
  }

Editted to add: After the above change, I compared a couple of my temporal network plots and everything seems to visually agree. That is, the outcomes from this appended code matched outcomes from previous run throughs on a different computer, which did not use appended code.

PritchardAJP avatar Nov 14 '25 00:11 PritchardAJP

Hi, thank you for raising the issue. A quick look gives the impression that this really seems to be the problem. Still i would like to take a closer look. can you tell me what format are your layers in UniAdj that were given to create_multilayer_network? (matrices? edgelists?)

either way, I will make sure it is fixed in the next version.

Geutg avatar Nov 25 '25 19:11 Geutg

Thank you for your response!

UniAdj is a list of weighted adjacency matrices with node IDs as colnames and rownames.

> class(UniAdj[[1]])
[1] "matrix" "array" 

PritchardAJP avatar Nov 25 '25 20:11 PritchardAJP