# NOT RUN {
R <- matrix(c(0.1, 0.6, 1, 0, 0, 0,
0, 0.3, 0.7, 0.9, 1, 1,
0, 0, 0.6, 0.8, 1, 0,
0, 1, 0.5, 0, 0, 0,
0, 0, 1, 1, 0, 0), byrow=TRUE, nrow=5)
S <- matrix(c(0.9, 1, 0.9, 1,
1, 1, 1, 1,
0.1, 0.2, 0, 0.2,
0, 0, 0, 0,
0.7, 0.6, 0.5, 0.4,
1, 0.9, 0.7, 0.6), byrow=TRUE, nrow=6)
RS <- matrix(c(0.6, 0.6, 0.6, 0.6,
1, 0.9, 0.7, 0.6,
0.7, 0.6, 0.5, 0.4,
1, 1, 1, 1,
0.1, 0.2, 0, 0.2), byrow=TRUE, nrow=5)
compose(R, S, alg='goedel', type='basic') # should be equal to RS
# Now define the quantifier "at least 2" meaning that at least 2 features are required
atLeast2n <- function(relcard) {
ifelse(relcard < 2 / length(relcard), 0, 1)
}
compose(R, S, alg='goedel', type='basic', quantifier=atLeast2n)
# Now define the quantifier "at least 20%" meaning that at least 20% of features are required
atLeast20p <- function(relcard) {
y <- attr(relcard, 'y')
a <- ceiling(0.2 * sum(y))
ifelse(relcard < a / length(relcard), 0, 1)
}
compose(R, S, alg='goedel', type='basic', quantifier=atLeast20p)
# }
Run the code above in your browser using DataLab