mbojan / d3net

Shiny application for interactive network data visualization and exploration
7 stars 2 forks source link

Optimalization issue: forming edge activity matrix #10

Closed pawluczuk closed 10 years ago

pawluczuk commented 10 years ago

Is there a way to optimize code that is going through edge activity matrix, to get rid of all of the (-)Inf values? To see how long this works: onlineNet sample data set. (~/network-app/server.R)

edges acitivity matrix

connectionsIdx <- get.edge.activity(data, as.spellList = TRUE)[c("onset", "terminus", "tail", "head")]
for (i in 1:nrow(connectionsIdx)) 
{
  # remove onset -infitiy values
  if (connectionsIdx[i,]$onset == -Inf)
    connectionsIdx[i,]$onset <-
      max(nodesActivity[which(nodesActivity$vertex.id == connectionsIdx[i,]$tail),]$onset, 
        nodesActivity[which(nodesActivity$vertex.id == connectionsIdx[i,]$head),]$onset)

  # remove terminus infitiy values
  if (connectionsIdx[i,]$terminus == Inf)
    connectionsIdx[i,]$terminus <-
      min(nodesActivity[which(nodesActivity$vertex.id == connectionsIdx[i,]$tail),]$terminus, 
        nodesActivity[which(nodesActivity$vertex.id == connectionsIdx[i,]$head),]$terminus)

  # decrement indexes as javascript counts from 0, not 1
  connectionsIdx[i,]$tail <- connectionsIdx[i,]$tail - 1
  connectionsIdx[i,]$head <- connectionsIdx[i,]$head - 1
}
mbojan commented 10 years ago

R is vectorized! This will probably be two lines of vectorized code...

What are we replacing Infs with?

Let's talk this through tomorrow.

mbojan commented 10 years ago

Fixed in aea421958b3a391cec36f24832e386f53bb170c5