## Implementation of WM, OWA, WOWA in R (R-project) ## This software complements and extends the one in ## http://www.mdai.cat/ifao/prog.ifao.models.r ## References on aggregation functions: ## V. Torra, Y. Narukawa (2007) Modeling Decisions, Springer. ## References on the WOWA: ## V. Torra, The Weighted OWA operator, Int. J. of Intel. Systems, ## 12 (1997) 153-166. ## http://dx.doi.org/10.1002/(SICI)1098-111X(199702)12:2<153::AID-INT3>3.0.CO;2-P ## Original interpolation: ## V. Torra, The WOWA operator and the interpolation function W*: Chen and ## Otto's interpolation method revisited, Fuzzy Sets and Systems, 113:3 ## (2000) 389-396. http://dx.doi.org/10.1016/S0165-0114(98)00040-2 ## Discussion on intepolation functions ## V. Torra, Z. Lv, On the WOWA operator and its interpolation function. ## Int. J. Intell. Syst. 2:(1 (2009): 1039-105 ## http://dx.doi.org/10.1002/int.20371 ## An overview of the WOWA and related results: ## V. Torra, The WOWA Operator: A Review, in R. R. Yager, J. Kacprzyk, ## G. Beliakov (eds.) Recent Developments in the Ordered Weighted ## Averaging Operators, Springer 2011 17-28. ## http://link.springer.com/chapter/10.1007%2F978-3-642-17910-5_2 ## Function: ## Given a vector (x_1, x_2, ..., x_i, ..., x_n) ## returns the vector (x_1, x_1+x_2, ..., \sum_{j<=i} x_j, ..., \sum x_j) ## Input: ## v: a vector (x_1, ..., x_n) ## Output: ## a vector of partial sums ## Example: ## partialSum(c(1,2,3,4)) partialSum <- function (v) { acc <- 0 cpv <- v i <- 1 while (i<=length(v)) { acc <- acc + v[i] cpv[i] <- acc i<-i+1 } return(cpv) } ## Function: ## A function for linear interpolation and evaluation at a given point ## interpolates points {(0,0)} \cup {(i/n, \sum_{j<=i} x_j)}_{i=1, ..., n} ## This function is used to compute the function w* in WOWA ## Input: ## w: the vector (w_1, ..., w_n) ## in WOWA w_i should be positive and add to one ## x: a point where to evaluate the interpolation function ## in WOWA x \in [0,1] ## Output: ## the evaluation of the interpolated polynomial at x ## Example: ## evalLinearQ(c(0.1,0.2,0.3,0.4),0.2) evalLinearQ <- function(w, x) { if (x<=0) { 0 } else if (x>=1) { 1 } else { n <- length(w) accw <- partialSum(w) i<-1 while (x>i/n) { i<-i+1 } if (i>1) { ## Interpolation between i-1 and i ##print(c(w[i-1],w[i])) ##print(c(accw[i-1],accw[i])) res <- accw[i-1] + (x-(i-1)/n)*(accw[i]-accw[i-1])/((i/n)-(i-1)/n) ##print(res) return(res) } else { ## Interpolation between i=0 and i=1 ##print(accw[i]) res <- x*(accw[i])/(i/n) return(res) } } } ## Functions: linearQ and vectorizedLinearQ ## A function for linear interpolation and evaluation ## interpolates points {(0,0)} \cup {(i/n, \sum_{j<=i} x_j)}_{i=1, ..., n} ## This function is used to compute the function w* in WOWA ## The function returns another function that given a point evaluates it ## One function is vectorized so that it can be applied to a vector of values ## Input: ## w: the vector (w_1, ..., w_n) ## in WOWA w_i should be positive and add to one ## Output: ## the interpolated polynomial (a function) ## Example: ## linearQ(c(0.1,0.2,0.3,0.4))(0.5) ## Non vectorized ## sapply(c(0.1,0.2,0.3,0.4,0.5),linearQ(c(0.2,0.3,0.4,0.1))) ## sapply(c(0.1,0.2,0.3,0.4,0.5),vectorizedLinearQ(c(0.2,0.3,0.4,0.1))) ## To plot the interpolated function: ## plot(vectorizedLinearQ(c(0.1,0.2,0.3,0.4))) linearQ <- function (w) { function (x) { evalLinearQ(w,x) } } vectorizedLinearQ <- function (w) { Vectorize(linearQ(w),c("x")) } ## Function: ## A function that orders the data in decreasing order and applies ## the same ordering to the weights. ## It returns a matrix with two columns, first corresponds to the data ## and second to the weights. ## Input: ## data: vector of data elements (a_1, ..., a_n) ## weights: vector of weights (w_1, ..., w_n) ## Output: ## a matrix, ## first column: corresponds to a_1, ..., a_n in decreasing order ## second column: weights ordered according to the same permutation ## permutation applied to a_i ## Example: ## orderDataWeights(c(4,3,1,2),c(0.1,0.2,0.3,0.4)) orderDataWeights <- function (data, weights) { mat <- cbind(data,weights) i<-1 while (i<=length(data)) { j<-i+1 while (j<=length(data)) { if (mat[i,1]=a_{\sigma(i)} ## Example: ## WM(c(4,3,1,2),c(0.1,0.2,0.3,0.4)) ## OWA(c(4,3,1,2),c(0.1,0.2,0.3,0.4)) ## OWA(c(4,3,2,1),c(0.1,0.2,0.3,0.4)) ## OWA(c(1,4,3,2),c(0.1,0.2,0.3,0.4)) ## WM(c(4,3,2,1),c(0.1,0.2,0.3,0.4)) ## WM(c(1,4,3,2),c(0.1,0.2,0.3,0.4)) WM <- function (data, weightsVect) { return (data %*% weightsVect) } OWA <- function (data, owaWeightsVect) { return (sort(data, decreasing=TRUE) %*% owaWeightsVect) } ## Function: ## The WOWA operator (with w* defined by means of a linear interpolation) ## Lateral effect: The function can plot the function w* uncommenting ## the line plot(wStar) and the weights uncommenting print(weights) ## Input: ## data: vector of data elements (a_1, ..., a_n) ## owaWeightsVect: vector of OWA weights (w_1, ..., w_n) ## wmWeightsVect: vector of weights (p_1, ..., p_n) ## Output: ## \sum a_{\sigma(i)}*\omega_i ## (where \sigma is a permutation such that a_{\sigma(i-1)}>=a_{\sigma(i)} ## \omega_i=w*(\sum_{j\leq i}p_{\sigma(j)}) - w*(\sum_{j[0,1] ## wmWeightsVect: vector of weights (p_1, ..., p_n) ## Output: ## \sum a_{\sigma(i)}*\omega_i ## (where \sigma is a permutation such that a_{\sigma(i-1)}>=a_{\sigma(i)} ## \omega_i=w*(\sum_{j\leq i}p_{\sigma(j)}) - w*(\sum_{j