Learn R Programming

rPref (version 0.6)

pred_succ: Predecessor and Successor Functions

Description

Function for traversing the BTG (Better-Than-Graph) of a preference.

Usage

init_pred_succ(df, p)

hasse_pred(p, v, intersect = FALSE)

hasse_succ(p, v, intersect = FALSE)

all_pred(p, v, intersect = FALSE)

all_succ(p, v, intersect = FALSE)

Arguments

df
A data frame characterizing the set wherein predecessors/sucessors are searched.
p
A preference. Worse tuples in the induced order are succesors and better tuples are predecessors.
v
A numeric vector of indices in df. This represents the set of tuples for which predecessors/successors are searched.
intersect
Logical value. If FALSE (by default) the union of all predecessors/successors of v are returned. For intersect = TRUE the intersection of those values is returned.

Details

These functions return the predecessors and successors in the Better-Than-Graph of a preference. Note that the successors/predecessors can can be plotted via get_btg. Before any of the successor/predecessor functions can be used the initialization has to be called as follows:

init_pred_succ(p, df)

There p is a preference object and df a dataframe. This statement calculates the Better-Than-Relation on df w.r.t. p. Afterwards the subsequent predecessor and sucessor functions can be called. The value of v is a numeric vector within 1:nrow(df) and characerizes a subset of tuples in df. The return value of these functions is again a numeric vector refering to the row numbers in df and it is always ordered ascending, independent of the order of the indices in v.

[object Object],[object Object],[object Object],[object Object]

If v has length 1, then the value of intersect does not matter, as there is nothing to intersect or join. For scalar values x and y the following identities hold, where f is one of the predecessor/successor functions:

f(p, c(x, y), intersect = FALSE) == union(f(p, x), f(p, y))

f(p, c(x, y), intersect = TRUE) == intersect(f(p, x), f(p, y))

Examples

Run this code
# preference on mtcars for high mpg and low weight
p <- high(mpg) * low(wt)
init_pred_succ(mtcars, p)

# helper to show mpg/hp values
show_vals <- function(x) mtcars[x,c('mpg','wt')]

# pick some tuple "in the middle"
show_vals(10)

# show (direct) predecessors/successors of tuple 10
show_vals(hasse_pred(p, 10)) # Next better car
show_vals(hasse_succ(p, 10)) # Next worse car
show_vals(all_pred(p, 10))   # All better cars
show_vals(all_succ(p, 10))   # All worse cars

Run the code above in your browser using DataLab