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

Possibility to build cumulative ranges #61

Closed
bockthom opened this issue Nov 15, 2017 · 7 comments
Closed

Possibility to build cumulative ranges #61

bockthom opened this issue Nov 15, 2017 · 7 comments

Comments

@bockthom
Copy link
Collaborator

It may be useful to be able to construct cumulative ranges when splitting data or networks.
For instance, the first range should contain the first three months, the second range the first six month, the third range the first nine month, and so on...

To achieve this, we should split the data into equal ranges (three months in the example above) and then combine subsequent ranges to get the cumulative ranges.

Therefore, we need some additional functions for combining data or networks, which we can collect in a new file called util-combine.R, for example.

A function for combining networks does already exist in another repository, which can be moved from the other repository into this one (see #11).

@clhunsen
Copy link
Collaborator

clhunsen commented Feb 16, 2018

We may use the function split.data.by.networks, introduced by PRs #67 and #93, in the file util-split.R as a start. Also it may be possible to extend the various split.* functions and the construct.ranges function with a corresponding parameter.

@ecklbarb
Copy link
Contributor

It may be useful to make the overlapping range by sliding window configurable. For example, when we have a sliding window size of one year, it could be interesting to have an overlapping range of 3 month or 25%. It is similar to cumulative ranges but without very old edges and nodes.
Example:
++++
.++++
..++++

@clhunsen
Copy link
Collaborator

It may be useful to make the overlapping range by sliding window configurable. For example, when we have a sliding window size of one year, it could be interesting to have an overlapping range of 3 month or 25%. It is similar to cumulative ranges but without very old edges and nodes.
Example:
++++
.++++
..++++

An idea to implement that would be to supply a function to construct overlapping ranges (similar to construct.ranges, either returning pairs or splittable string representations) and additional functions to split data/networks by ranges (e.g., split.data.by.ranges). There we just need to split the ranges, repeatedly call the split.*.time.based(..., bins = ...) functions, and return the result.

This way, we would not need to extend the existing functions by even more stuff...

@clhunsen
Copy link
Collaborator

I am currently constructing a function to construct overlapping ranges. I would like your opinion on the signature and the respective documentation. What are your thoughts on this?

#' Construct ranges based on the given start time, end time, time period, and overlap.
#'
#' With this function, it is possible to construct ranges like this:
#' > ++++
#' > .++++
#' > ..++++
#'
#' With \code{overlap} being the half of \code{time.period}, we basically obtain half-
#' overlapping ranges as in the function \code{construct.ranges} when \code{sliding.window}
#' is set to \code{TRUE}.
#'
#' Note: You may want to use the function \code{ProjectData$get.data.timestamps} with this
#' function here.
#'
#' @param start The start time as string or POSIXct object
#' @param end The start time as string or POSIXct object
#' @param time.period The time period describing the length of the ranges, a character
#'                    string, e.g., "3 mins" or "15 days"
#' @param overlap The time period describing the length of the overlap, a character string,
#'                    e.g., "3 mins" or "15 days". Needs to be more than 0 seconds and
#'                    smaller than the given \code{time.period}.
#' @param raw whether to return pairs of POSIXct objects or strings rather than
#'            formatted strings [default: FALSE]
#'
#' @return the constructed ranges, either formatted or raw
construct.overlapping.ranges = function(start, end, time.period, overlap, raw = FALSE) {

@bockthom
Copy link
Collaborator Author

@clhunsen Could you add an example here, please? It would be helpful to see the outcome of the function based on an example input.

In addition, according to Barbara's example, it may be useful to not only allow specifying the overlap as a time period, but also as a percentage dependent on the time.period parameter.

@clhunsen
Copy link
Collaborator

At the time of writing the previous post, I had not had implemented the function yet... 😉 So, here, the example now (analogous output as for the function construct.ranges):

rev1 = ("2015-01-01 00:00:00")
rev2 = ("2015-01-01 06:00:00")
construct.overlapping.ranges(rev1, rev2, time.period = "2 hours", overlap = "30 minutes")
# [1] "2015-01-01 00:00:00-2015-01-01 02:00:00"
# [2] "2015-01-01 01:30:00-2015-01-01 03:30:00"
# [3] "2015-01-01 03:00:00-2015-01-01 05:00:00"
# [4] "2015-01-01 04:30:00-2015-01-01 06:00:00"
construct.overlapping.ranges(rev1, rev2, time.period = "2 hours", overlap = " 0 minutes", raw = TRUE)
# $`2015-01-01 00:00:00-2015-01-01 02:00:00`
# [1] "2015-01-01 00:00:00 UTC" "2015-01-01 02:00:00 UTC"
# 
# $`2015-01-01 02:00:00-2015-01-01 04:00:00`
# [1] "2015-01-01 02:00:00 UTC" "2015-01-01 04:00:00 UTC"
#
# $`2015-01-01 04:00:00-2015-01-01 06:00:00`
# [1] "2015-01-01 04:00:00 UTC" "2015-01-01 06:00:00 UTC"

In addition, according to Barbara's example, it may be useful to not only allow specifying the overlap as a time period, but also as a percentage dependent on the time.period parameter.

What about a parameter overlap.percent, overriding the parameter overlap, specified as a numeric such as 1/4 or 0.2?

@bockthom
Copy link
Collaborator Author

As we can construct cumulative ranges and also overlapping ranges now, I will close this issue.

@clhunsen clhunsen mentioned this issue Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants