DexiDiscretizeFunction-class {DEXiR} | R Documentation |
DexiDiscretizeFunction
is a RC class, derived from DexiFunction.
Functions of this type discretize numerical values of continuous attributes to qualitative
values of discrete attributes. More precisely, a DexiDiscretizeFunction
can be defined
only for a discrete attribute that has exactly one continuous input. Then, the function discretizes
numeric values of the input attribute and maps them to discrete values of the parent attribute.
Objects of class DexiDiscretizeFunction
define discretization rules in terms of three lists:
values
, bounds
and assoc
. Using n <- nvals()
to denote the length of
values
, the required lengths of bounds
and assoc
are n - 1
.
The list bounds
refers to values of the input attribute and partitions its scale in n
intervals
[-Inf, bound[[1]]]
, [bound[[1]], bound[[2]]],
..., [bound[[n - 1]]], +Inf]
.
The list values
then defines the output values for each interval.
The list assoc
contains strings "up"
or "down"
that indicate to which interval,
lower or higher, belong the corresponding bounds
.
attribute
DexiAttribute. The attribute this function is associated with.
Requirements: attribute
must be discrete (i.e., associated with a DexiDiscreteScale) and
must have exactly one continuous input attribute (i.e., associated with a DexiContinuousScale).
values
A list of output values corresponding to each interval defined by bounds
.
List elements are in general value sets, i.e., integer vectors of value indices w.r.t. attribute$scale
.
bounds
A vector of numeric values that partitions the input scale in intervals.
assoc
A vector of strings "up"
or "down"
.
For each i in 1:n-1
, assoc[[i]]
indicates how to map the value of
bounds[[i]]
: to value[[i]]
("down"
) or value[[i + 1]]
("up"
).
bound_assoc(idx, default = "down")
Given idx
, a bounds
index, return the corresponing association
("down"
or "up"
).
evaluate(x)
A silent wrapper around value(x)
; it returns NULL
when
value(x)
fails with an error.
nargs()
Return the number of function arguments.
nvals()
Return the length of values
.
to_string()
Return an informative string about this function's values
and bounds
.
value(x)
Return the function value for arguments x
, where arguments are
a numeric vector of length equal to att$inputs
.
Additionally, arguments of a DexiTabularFunctions$value()
must be integer numbers,
and the argument of DexiDiscretizeFunctions$value()
must be a single number.
verify()
Check the correctnes of this function object and its fields.
Result: error()
or TRUE
.
# Create a DexiDiscretizeFunction (without association to any attributes or scales)
fnc <- DexiDiscretizeFunction(bounds = c(-1, 2), values = list(1, 3, 5), assoc = c("up", "down"))
# Print fields and basic properties of fnc
fnc$verify()
fnc$nargs()
fnc$nvals()
fnc$to_string()
fnc$bound_assoc(1)
fnc$bound_assoc(2)
# Try some discretizations
sapply(c(-1.1, -1, 0, 1, 2, 3), fnc$evaluate)