Learn R Programming

rPref (version 0.5)

base_pref: Base preferences

Description

Base preferences are used to describe the different goals of a preference query.

Usage

low(expr)

low_(expr)

high(expr)

high_(expr)

true(expr)

true_(expr)

Arguments

expr
A numerical/logical expression which is the term to evaluate for the current preference. The objective is to search for minimal/maximal values of this expression (for low/high) or for logical TRUE values

Using expressions in preferences

The low_(e), high_(e) and true_(e) preferences have the same functionality, but expect an expression e or symbol e as argument. For example, low(a) is equivalent to low(expression(a)) or low(as.symbol("a")).

This is very helpful for developing your own base preferences. Assume you want to define a base Preference false as the dual of true. A definition like false <- function(x) -true(x) is the wrong approach, as psel(data.frame(a = c(1,2)), false(a == 1)) will result in the error object 'a' not found. This is because a is considered as a variable and not as an (abstract) symbol to be evaluated later on the data set. By defining

false <- function(x) -true_(substitute(x))

one gets a preference which behaves like a "built-in" preference. The object false(a == 1) will output [Preference] -true(a == 1) on the console and psel(data.frame(a = c(1,2)), false(a==1)) returns correctly the second tuple with a==2.

Details

Mathematically, all base preferences are strict weak orders (irreflexive, transitive and negative transitive).

The three fundamental base preferences are:

[object Object],[object Object]

The term expr may be just a single attribute or may contain an arbitrary expression, e.g., low(a+2*b+f(c)). There a, b and c are columns of the addressed dataset and f is a previously defined function.

Functions contained in expr are evaluated over the entire dataset, i.e., it is possible to use aggregate functions (min, mean, etc.). Note that all functions (and also variables which are not columns of the dataset, where expr will be evaluated on) must be defined in the same environment (e.g. environment of a function or global scope) as the base preference.

See Also

See complex_pref how to compose complex preferences to retrieve e.g. the Skyline.

See base_pref_macros for more base preferences.

Examples

Run this code
# Define a preference with a score value combining mpg and hp
p1 <- high(4 * mpg + hp)
# Perform the preference selection
psel(mtcars, p1)

# Define a preference with a given function
f <- function(x, y) (abs(x - mean(x))/max(x) + abs(y - mean(y))/max(y))
p2 <- low(f(mpg, hp))
psel(mtcars, p2)

Run the code above in your browser using DataLab