From 9a79a452651a4065ccd45af1b3a6080d5c31bf48 Mon Sep 17 00:00:00 2001 From: Brian Pentland Date: Mon, 24 Jun 2019 20:43:11 +0000 Subject: [PATCH 1/3] Added in estimated number of paths for circle network --- Inst/ThreadNet/server/visualize.R | 9 +++++++++ Inst/ThreadNet/ui/visualize.R | 2 ++ R/ThreadNet_Metrics.R | 17 ++++++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Inst/ThreadNet/server/visualize.R b/Inst/ThreadNet/server/visualize.R index e93418d..d67c604 100644 --- a/Inst/ThreadNet/server/visualize.R +++ b/Inst/ThreadNet/server/visualize.R @@ -94,6 +94,15 @@ output$Circle_Network_Tab_Controls <- renderUI({ ) }) +output$Circle_Network_Path_Estimate <- renderText({ + paste0('Estimated paths = ', + estimate_network_complexity(viz_net()) ) +}) + +output$Network_Nodes_Edges <- renderText({ + paste0( print_network_nodes_edges(viz_net()) ) +}) + # Create the network to be exported and also displayed viz_net <<- reactive({ req(input$circleEdgeTheshold) diff --git a/Inst/ThreadNet/ui/visualize.R b/Inst/ThreadNet/ui/visualize.R index a2adf11..ad0c4e3 100644 --- a/Inst/ThreadNet/ui/visualize.R +++ b/Inst/ThreadNet/ui/visualize.R @@ -40,6 +40,8 @@ tabPanel(value = "visualize", tabPanel( "Event network (circle)", uiOutput("Circle_Network_Tab_Controls"), + textOutput("Circle_Network_Path_Estimate"), + textOutput("Network_Nodes_Edges"), visNetworkOutput("circleVisNetwork", width = "100%", height = "1200px") ), tabPanel( diff --git a/R/ThreadNet_Metrics.R b/R/ThreadNet_Metrics.R index 5a92e6d..ee16a5b 100644 --- a/R/ThreadNet_Metrics.R +++ b/R/ThreadNet_Metrics.R @@ -1,4 +1,4 @@ -########################################################################################################## + ########################################################################################################## # THREADNET: Metrics # This software may be used according to the terms provided in the @@ -17,6 +17,9 @@ #' @export estimate_network_complexity <- function(net){ return(estimate_task_complexity_index( nrow(net$nodeDF), nrow(net$edgeDF)) ) } +# returns a string with the number of nodes and edges in the network +print_network_nodes_edges <- function(net){ return(paste0('Number of nodes = ', nrow(net$nodeDF),' Number of edges = ', nrow(net$edgeDF) ) ) } + #' @title Estimates the number of paths in a directed graph #' @description Same as estimate_network_complexity, but takes this version takes vertices and edges as parameters @@ -32,17 +35,17 @@ estimate_task_complexity_index <- function(v,e){ # v = number of vertices # tested for range of 10 < v < 100 # e = number of edges - print("edges") - print(e) - print("vertices") - print(v) + # print("edges") + # print(e) + # print("vertices") + # print(v) # # OUTPUT ARG: # cidx correlates with Log10(simple paths) with r>= 0.8 # from ORM paper analysis, constant is 0.12. # For boundary condition of 2 nodes and 1 edge, complexity index=0, constant = 0.08 - return( 0.08 + 0.08*e - 0.08*v ) + return( 10^( 0.08 + 0.08*e - 0.08*v) ) } @@ -84,7 +87,7 @@ compression_index <- function(df,CF){ return( length(paste0(as.character(df[[CF]]))) ) } -####################################################################### +#######################################################################es #compute entropy for a set of observations in a column from a data frame #' @title Compute the entropy of a contextual factor #' @description Each column in the raw data represents a contextual factor. This function computes the entropy of each factor that is selected for use in the From 4553576cc1a12d3171735fe40d7e4eebef6e07fe Mon Sep 17 00:00:00 2001 From: Brian Pentland Date: Thu, 18 Jul 2019 22:03:30 +0000 Subject: [PATCH 2/3] Stopped filtering selfies for the networks. --- Inst/ThreadNet/server/visualize.R | 2 +- R/ThreadNet_Core.R | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Inst/ThreadNet/server/visualize.R b/Inst/ThreadNet/server/visualize.R index d67c604..0a012ed 100644 --- a/Inst/ThreadNet/server/visualize.R +++ b/Inst/ThreadNet/server/visualize.R @@ -96,7 +96,7 @@ output$Circle_Network_Tab_Controls <- renderUI({ output$Circle_Network_Path_Estimate <- renderText({ paste0('Estimated paths = ', - estimate_network_complexity(viz_net()) ) + round(estimate_network_complexity(viz_net()) ),1) }) output$Network_Nodes_Edges <- renderText({ diff --git a/R/ThreadNet_Core.R b/R/ThreadNet_Core.R index 55607df..6fc381e 100644 --- a/R/ThreadNet_Core.R +++ b/R/ThreadNet_Core.R @@ -75,14 +75,16 @@ threads_to_network_original <- function(et,TN,CF,grp='threadNum'){ to[i] = match(to_labels[i], nodes$label) } + # Stopped filtering out selfies July 20, 2019 for Kerstin Sailer bug report edges = data.frame( from, to, label = ngdf$freq, - Value =ngdf$freq) %>% filter(!from==to) + Value =ngdf$freq) # %>% filter(!from==to) # print(paste("T2N nodes:",nodes)) - # print(paste("T2N edges:",edges)) + # print(paste("ngdf = :",ngdf)) + # print(paste("edges= :",edges)) return(list(nodeDF = nodes, edgeDF = edges)) } @@ -163,10 +165,13 @@ count_ngrams <- function(o,TN,CF,n){ # Need a vector of strings, one for each thread, delimited by spaces # the function long_enough filters out the threads that are shorter than n # use space for the delimiter here - text_vector = long_enough( thread_text_vector(o,TN,CF,' '), n, ' ') + text_vector = long_enough( thread_text_vector(o,TN,CF,' '), n, ' ') + # text_vector = thread_text_vector(o,TN,CF,' ') + + + # print(paste0("thread=", o[1,TN] ,", text_vector")) + # print(text_vector) - # print("text_vector") - # print(text_vector) ng = get.phrasetable(ngram(text_vector,n)) From cf7ffc3dc649fa1092be10dd48e9757344beb4e6 Mon Sep 17 00:00:00 2001 From: Brian Pentland Date: Fri, 26 Jul 2019 11:11:06 -0400 Subject: [PATCH 3/3] fixed bug in visualize network --- R/ThreadNet_Metrics.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/ThreadNet_Metrics.R b/R/ThreadNet_Metrics.R index ee16a5b..1f5b1c6 100644 --- a/R/ThreadNet_Metrics.R +++ b/R/ThreadNet_Metrics.R @@ -18,6 +18,12 @@ estimate_network_complexity <- function(net){ return(estimate_task_complexity_index( nrow(net$nodeDF), nrow(net$edgeDF)) ) } # returns a string with the number of nodes and edges in the network +#' @title returns a string with the number of nodes and edges in the network +#' @description returns a string with the number of nodes and edges +#' @name print_network_nodes_edges +#' @param net Object with dataframe for nodes and edges +#' @return string +#' @export print_network_nodes_edges <- function(net){ return(paste0('Number of nodes = ', nrow(net$nodeDF),' Number of edges = ', nrow(net$edgeDF) ) ) }