navigate: Limit which points are included in the nearest neighbor...

Description Usage Arguments Details Value Functions Examples

View source: R/navigate.R

Description

When seeking the next point in a space, search only among those points that fulfill a given function based on the previously-selected points.

Usage

1
2
3
4
5
6
7
8
9
navigate(.p, ...)

navigate_ordered(x, pi, p1, p2, n)

navigate_ordered_desc(x, pi, p1, p2, n)

navigate_unique(x, pi, p1, p2, n)

navigate_any(x, pi, p1, p2, n)

Arguments

.p

A function that returns a vector of indices

...

Additional arguments passed on to .p

x

The original matrix

pi

Indices of already-selected-nodes. During the first step of a pathway, pi will be NULL

p1

Start and end points used in pathway

p2

Start and end points used in pathway

n

Number of indices to be found

Details

The supplied functions navigate_ordered, navigate_unique, and navigate_any can be supplied directly to pathway.

navigate is a generator that takes an arbitrary user-supplied predicate function that will generate a vector of search indices when given x, pi, p1, and p2. This can be useful for drawing a path that, for example, only moves forward in time, or which introduces a selection probability based on attributes of the point supplied in another table.

Value

Integer. An integer vector of indices within x forming the search space for the next step of the nearest neighbor search.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
m <- matrix(runif(1000), nrow = 500, ncol = 2)
obs_types <- sample(c("setosa", "versicolor", "virginica"), 500, replace = TRUE)

# A custom predicate function must take the original matrix, the list of
# previously-selected pathway points, along with p1 and p2.
different_species <- function(x, pi, p1, p2, obs_types) {
  if (is.null(pi)) {
    search_space <- 1:nrow(x)
  } else {
    # Only search observations that do not have the same species as the immediately previous one.
    prev_type <- obs_types[tail(pi, 1)]
    search_space <- which(obs_types != prev_type)
  }

  # Don't forget to exclude p1 and p2
  setdiff(search_space, c(p1, p2))
}

p_species <- pathway(m, 2, 11, n = 8, navigator = navigate(different_species, obs_types))

mdlincoln/pathway documentation built on May 23, 2019, 1:13 p.m.