Skip to content

Commit

Permalink
i #229 Adds temporal_cum_sum checks
Browse files Browse the repository at this point in the history
When the weight scheme is used in the wrong function
combination, the code now throws an error advising
the user the correct way to combine them.

In the future, a saner function that only allow for
the correct weight scheme combinations should be
added.

Signed-off-by: Carlos Paradis <carlosviansi@gmail.com>
  • Loading branch information
carlosparadis committed Mar 3, 2024
1 parent e8a4310 commit c98f4a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ model_directed_graph <- function(edgelist,is_bipartite,color,aggregate_duplicate
#' @export
bipartite_graph_projection <- function(graph,mode,weight_scheme_function = NULL){

# If weight scheme is cum_temporal, then lag must be "all_lag":
if(identical(weight_scheme_function,kaiaulu::weight_scheme_cum_temporal)){
stop("The weight scheme for cumulative temporal should only be applied to the temporal_graph_projection
and lag = all_lag. See ?weight_scheme_cum_temporal.")

Check warning on line 157 in R/graph.R

View check run for this annotation

Codecov / codecov/patch

R/graph.R#L155-L157

Added lines #L155 - L157 were not covered by tests
}

get_combinations <- function(edgelist){
dt <- edgelist

Expand Down Expand Up @@ -260,12 +266,23 @@ bipartite_graph_projection <- function(graph,mode,weight_scheme_function = NULL)
#' doi: 10.1109/ICSE.2015.73.
temporal_graph_projection <- function(graph,mode,weight_scheme_function = NULL,timestamp_column,lag = c("one_lag","all_lag")){

# Check if the user specified a lag that doesn't exist
lag <- match.arg(lag)



# If weight scheme is cum_temporal, then lag must be "all_lag":
if(identical(weight_scheme_function,kaiaulu::weight_scheme_cum_temporal) &
lag != "all_lag"){
stop("The weight scheme for cumulative temporal should only be applied to all_lag. See ?weight_scheme_cum_temporal.")

Check warning on line 277 in R/graph.R

View check run for this annotation

Codecov / codecov/patch

R/graph.R#L277

Added line #L277 was not covered by tests
}

# We define the way the pair-wise edges are computed in two
# separate functions: one_lag_combinations and
# all_lag combinations.

# The remainder of this function is documented
# refering to developers and files, however the
# referring to developers and files, however the
# function can be applied to anything else
# (e.g. threads and authors, files and commits, etc)

Expand Down Expand Up @@ -403,7 +420,7 @@ temporal_graph_projection <- function(graph,mode,weight_scheme_function = NULL,t
new = c("to_edgeid","from_edgeid"))

# Because the function will not generate the final projection, but
# rather the intemediate step, showcasing what nodes were deleted, and
# rather the intermediate step, showcasing what nodes were deleted, and
# what weights the pairs of edges had pointing to the deleted node,
# we use the edge ID to add the information back. Without the edge id,
# we would be unable to determine which temporal edge the information
Expand Down Expand Up @@ -433,8 +450,7 @@ temporal_graph_projection <- function(graph,mode,weight_scheme_function = NULL,t



# Check if the user specified a lag that doesn't exist
lag <- match.arg(lag)


# Copy the graph, so column renames by reference doesn't overwrite parameter objects
graph <- copy(graph)
Expand Down Expand Up @@ -581,7 +597,7 @@ weight_scheme_count_deleted_nodes <- function(projected_graph){
#' Weight Cumulative Temporal Projection Scheme
#'
#' This weight scheme sums the deleted node adjacent edges when re-wired
#' in the projection graph that *occur before* the temporal edge and the
#' in the projection graph that *occur before* the temporal edge. See the
#' in line documentation for details.
#'
#' Note this function assumes the rows of `temporally_ordered_projected_graph`
Expand Down
2 changes: 1 addition & 1 deletion man/weight_scheme_cum_temporal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c98f4a6

Please sign in to comment.