| Title: | Using the Theory of Belief Functions |
|---|---|
| Description: | Using the Theory of Belief Functions for evidence calculus. Basic probability assignments, or mass functions, can be defined on the subsets of a set of possible values and combined. A mass function can be extended to a larger frame. Marginalization, i.e. reduction to a smaller frame can also be done. These features can be combined to analyze small belief networks and take into account situations where information cannot be satisfactorily described by probability distributions. |
| Authors: | Peiyuan Zhu [aut, cre], Claude Boivin [aut] |
| Maintainer: | Peiyuan Zhu <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.9.0 |
| Built: | 2026-06-07 07:26:01 UTC |
| Source: | https://github.com/rapler/dst-1 |
You may want to add to a previously defined DSM some elements or some subsets of the state space (the set of possible values). The mass of these additional elements or subsets may be set to zero. This feature is useful when one wants to examine the plausibility measure of elements or subsets of zero mass.
addToDSM(x, tt) addTobca(x, tt)addToDSM(x, tt) addTobca(x, tt)
x |
A DSM (see |
tt |
A matrix constructed in a boolean style (0,1) or a boolean matrix. The number of columns of the matrix |
x The original DSM x augmented with the added subsets defined by tt.
Claude Boivin
y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow=2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), idvar = 1) addToDSM(y, matrix(c(0,1,0,0,0,1, 0,1,1), nrow = 3, byrow = TRUE)) x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow=3, byrow = TRUE), m=c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1) xy <- dsrwon(x,y) xy1 <- addToDSM(nzdsr(xy), matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) xy1 # add all singletons to a DSM addToDSM(x, tt = diag(rep(1, ncol(x$tt) ) ) )y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow=2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), idvar = 1) addToDSM(y, matrix(c(0,1,0,0,0,1, 0,1,1), nrow = 3, byrow = TRUE)) x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow=3, byrow = TRUE), m=c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1) xy <- dsrwon(x,y) xy1 <- addToDSM(nzdsr(xy), matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) xy1 # add all singletons to a DSM addToDSM(x, tt = diag(rep(1, ncol(x$tt) ) ) )
ads: Relation between variables Arrival (A), Departure delay (D) and Sailing delay (S)This dataset is the tt matrix establishing the relation A = D + S, where A = 0:6, D = 0:3 and S = 0:3. The subset made of all the triplets (a,d,s) of (A x D x S) where a = d + s is true has a mass value of 1. To construct the tt matrix, we put the variables A, D, S side by side, as in a truth table representation. Each triplet of the subset is described by a row of the matrix as a vector of zeros and ones.
adsads
An integer matrix with 18 rows and 17 columns
value = 0, not used
Identification numbers of the three variables. Column 3 to 9: variable 1; column 10 to 13: variable 2; column 14 to 17: variable 3.
identification number of the specification
the value of the specification, a number between 0 and 1
1 if 6 is part of the specification, 0 otherwise
1 if 5 is part of the specification, 0 otherwise
1 if 4 is part of the specification, 0 otherwise
1 if 3 is part of the specification, 0 otherwise
1 if 2 is part of the specification, 0 otherwise
1 if 1 is part of the specification, 0 otherwise
1 if 0 is part of the specification, 0 otherwise
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
swr: Result of the evaluation of the Hypergraph at node Arrival (A)This dataset is the tt bca resulting from the combination of the relations of the hypergraph and marginalization at node Arrival (A).
captain_resultcaptain_result
A list of 8 elements, of class bcaspec.
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
qq is the commonality function as a set function from the subsets of the frame to . To evaluate it, input a set encoded in binary vector, so the commonality number at that set can be returned.
commonality(tt, m, method = NULL)commonality(tt, m, method = NULL)
tt |
Bolean description matrix |
m |
Mass assignment vector of probabilities |
method |
= NULL: Use Fast Zeta Transform ("fzt") or Efficient Zeta Transform ("ezt") or Efficient Zeta Transform on a meet-closed subset ("ezt-m") |
f Commonality function
Peiyuan Zhu
x <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) qq <- commonality(x$tt,x$spec[,2], method = "ezt") qq qq1 <- commonality(x$tt,x$spec[,2]) qq1x <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) qq <- commonality(x$tt,x$spec[,2], method = "ezt") qq qq1 <- commonality(x$tt,x$spec[,2]) qq1
The aplDecode function of the project APL in R (https://rpubs.com/deleeuw/158476) has been adapted to follow the standard implementation of the APL decode function.
decode(base, ind)decode(base, ind)
base |
A scalar or a numeric vector which describes the number system in which the data is coded. |
ind |
The value to decode represented by a numeric vector in the |
If the base value is a number system, e.g. base 2, we need only to enter it as a scalar, which is then processed to match the length of the expression to decode. If length(ind) is less than length(base), zeroes are added to the left of the vector ind to match the length of the two vectors. And vice-versa.
A scalar representing the conversion of the coded number ind to its decimal representation.
Claude Boivin
Jan de Leeuw and Masanao Yajima (March 07, 2016) APL in R (Version 009), Source code. https://rpubs.com/deleeuw/158476
L. Gilman and A. J. Rose.(1974): APL an Interactive Approach, Second Edition, John Wiley, New York.
APL 68000 Level II language manual. MicroAPL Ltd. 1990.
decode(c(2,2,2,2), c(1,0,1,1)) # Find the base 10 value of the base 2 number 1011. decode(2, c(1,0,1,1)) # left argument is extended to vector c(2,2,2,2) decode(c(365,24,60), c(2,1,57)) # transform 2 days 1 h 57 min in minutes decode(c(365,24,60), c(1,57)) # right vector extended decode(c(24,60), c(2,1,57)) # left vector extended decode(1.5, c(1,2,3)) # polynomial 1*x^2 +2*x +3 evaluated at x=1.5decode(c(2,2,2,2), c(1,0,1,1)) # Find the base 10 value of the base 2 number 1011. decode(2, c(1,0,1,1)) # left argument is extended to vector c(2,2,2,2) decode(c(365,24,60), c(2,1,57)) # transform 2 days 1 h 57 min in minutes decode(c(365,24,60), c(1,57)) # right vector extended decode(c(24,60), c(2,1,57)) # left vector extended decode(1.5, c(1,2,3)) # polynomial 1*x^2 +2*x +3 evaluated at x=1.5
dlfm: Relation between variables Departure delay (D), Loading delay (L), Forecast of the weather (F), Maintenance delay (M)This dataset is the tt matrix establishing the relation between the four variables. Each event (loading = true, forecast = foul, Maintenance = true) adds one day of Departure Delay. The elements (d,l, f, m) of (D x L x F x M) satisfying the relation form a subset with a mass value of 1. To construct the tt matrix, we put the variables D,L,F,M side by side, as in a truth table representation. Each 4-tuple of the subset is described by a row of the matrix as a vector of zeros and ones.
dlfmdlfm
An integer matrix with 10 rows and 12 columns.
value = 0, not used
Identification numbers of the four variables. Column 3 to 6: variable 2; columns 7,8: variable 4; columns 9, 10: variable 5: columns 11,12: variable 6.
identification number of the specification
the value of the specification, a number between 0 and 1
1 if d3 is part of the specification, 0 otherwise
1 if d2 is part of the specification, 0 otherwise
1 if d1 is part of the specification, 0 otherwise
1 if d0 is part of the specification, 0 otherwise
1 if true is part of the specification, 0 otherwise
1 if false is part of the specification, 0 otherwise
1 if foul is part of the specification, 0 otherwise
1 if fair is part of the specification, 0 otherwise
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
Construct subsets names from column names of a tt matrix
DoSSnames(tt)DoSSnames(tt)
tt |
A description matrix with column names |
subsets_names A list of names.
Claude Boivin
y1 <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DoSSnames(y1$tt)y1 <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DoSSnames(y1$tt)
The generalized inner product of two matrices combines two operators in the same manner as the classical inner product defined for the multiplication of two matrices. The number of rows of the second matrix must be equal the number of columns of the first matrix.
dotprod(x, y, g, f)dotprod(x, y, g, f)
x |
A matrix of M rows by K columns. |
y |
A matrix of K rows by N columns. |
g |
Any operator: +, -, *, /, &, |, ==, <=, paste etc. |
f |
Any operator: +, -, *, /, &, |, ==, <=, paste etc. |
The result of the generalized inner product is returned.
Claude Boivin
print("Standard matrix product") x <- y <- matrix(c(1:6), nrow = 2, byrow = TRUE) dotprod(x, t(y), g = "+", f = "*") ## same as x %*% t(y) print("Find some data x2 in the rows of a larger matrix y2") x2 <- matrix(c(1,0,0,1,1,1), nrow = 2, byrow = TRUE) y2 <- matrix(c(1,0,0,0,1,0,1,1,0,0,1,1,1,1,1), nrow = 5, byrow = TRUE) (1:nrow(y2)) * dotprod(x2, t(y2), g = "&", f = "==") print("Find some names in a long list") team_names <- matrix(c("Patrick", "Dole", "Amanda", "Dole", "Robert", "Calvin", "Alvina", "Klein", "Robert", "Gariepy", "Nellie", "Arcand"), ncol = 2, byrow = TRUE) colnames(team_names) <- c("First_name", "Last_name") print("Where in the list are the person with first name Robert and where are the Doles?") BobandDoles <- matrix(c("Robert", "", "", "Dole"), ncol = 2, byrow = TRUE) dotprod(team_names, t(BobandDoles),g="|",f="==") * (1:nrow(team_names))print("Standard matrix product") x <- y <- matrix(c(1:6), nrow = 2, byrow = TRUE) dotprod(x, t(y), g = "+", f = "*") ## same as x %*% t(y) print("Find some data x2 in the rows of a larger matrix y2") x2 <- matrix(c(1,0,0,1,1,1), nrow = 2, byrow = TRUE) y2 <- matrix(c(1,0,0,0,1,0,1,1,0,0,1,1,1,1,1), nrow = 5, byrow = TRUE) (1:nrow(y2)) * dotprod(x2, t(y2), g = "&", f = "==") print("Find some names in a long list") team_names <- matrix(c("Patrick", "Dole", "Amanda", "Dole", "Robert", "Calvin", "Alvina", "Klein", "Robert", "Gariepy", "Nellie", "Arcand"), ncol = 2, byrow = TRUE) colnames(team_names) <- c("First_name", "Last_name") print("Where in the list are the person with first name Robert and where are the Doles?") BobandDoles <- matrix(c("Robert", "", "", "Dole"), ncol = 2, byrow = TRUE) dotprod(team_names, t(BobandDoles),g="|",f="==") * (1:nrow(team_names))
This function works on a jointDSM defined on a product of two variables or more. Having fixed a variable to eliminate from the jointDSM, the reduced product space is determined and the corresponding reduced bca is computed.This operation is also called "marginalization".
dproj(rel, xnb) elim(rel, xnb)dproj(rel, xnb) elim(rel, xnb)
rel |
The jointDSM to reduce, an object of class DSMspec. |
xnb |
Identification number of the variable to eliminate. |
r The reduced jointDSM
Claude Boivin
# We construct a jointDSM between two variables to show marginalization. wr_tt <- matrix(c(1,rep(0,3),rep(c(1,0),3),0,1,1,1,0,0, 1,0,rep(1,5),0,1,1,0,rep(1,5)), ncol = 4, byrow = TRUE) colnames(wr_tt) <- c("Wy Ry", "Wy Rn", "Wn Ry", "Wn Rn") rownames(wr_tt) <- nameRows(wr_tt) wr_spec = matrix(c(1:8, 0.017344, 0.046656, 0.004336, 0.199456,0.011664,0.536544,0.049864, 0.134136), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) wr_infovar = matrix(c(4,5,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) wr_rel <- list(tt = wr_tt, con = 0.16, spec=wr_spec, infovar = wr_infovar, varnames = c("Roadworks","Rain"), valuenames = list( RdWorks = c("Wy", "Wn"), Rain=c("Ry", "Rn") )) class(wr_rel) <- "DSMspec" DSMprint(dproj(wr_rel, xnb = 5)) DSMprint(dproj(wr_rel, xnb = 4))# We construct a jointDSM between two variables to show marginalization. wr_tt <- matrix(c(1,rep(0,3),rep(c(1,0),3),0,1,1,1,0,0, 1,0,rep(1,5),0,1,1,0,rep(1,5)), ncol = 4, byrow = TRUE) colnames(wr_tt) <- c("Wy Ry", "Wy Rn", "Wn Ry", "Wn Rn") rownames(wr_tt) <- nameRows(wr_tt) wr_spec = matrix(c(1:8, 0.017344, 0.046656, 0.004336, 0.199456,0.011664,0.536544,0.049864, 0.134136), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) wr_infovar = matrix(c(4,5,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) wr_rel <- list(tt = wr_tt, con = 0.16, spec=wr_spec, infovar = wr_infovar, varnames = c("Roadworks","Rain"), valuenames = list( RdWorks = c("Wy", "Wn"), Rain=c("Ry", "Rn") )) class(wr_rel) <- "DSMspec" DSMprint(dproj(wr_rel, xnb = 5)) DSMprint(dproj(wr_rel, xnb = 4))
Degrees of unambiguous support p and unambiguous contradiction q of the focal sets of a DSM are computed. The ratio of the plausibility of a focal set against the plausibility of its contrary is also computed. Subsets with zero mass can be excluded from the calculations.
DSA(x, remove = FALSE, h = NULL) belplau(x, remove = FALSE, h = NULL)DSA(x, remove = FALSE, h = NULL) belplau(x, remove = FALSE, h = NULL)
x |
A DSM (see |
remove |
= TRUE: Exclude subsets with zero mass. |
h |
= NULL: Hypothesis to be tested. Description matrix in the same format than |
The degree of unambiguous support (belief) p is defined by:
for every subset B of A.
The degree of non-contradiction (plausibility) plau is defined by:
for every subset B of the state-space model.
The plausibility ratio of a focal set A versus its contrary not A is defined by: .
A matrix of M rows by 3 columns is returned, where M is the number of focal sets:
Column 1: the degree of unambiguous support (Belief) p;
Column 2: the degree of unambiguous contradiction (Disbelief) q;
Column 3: the degree of ambiguity (Epistemic uncertainty) r;
Column 4: the degree of non-contradiction (Plausibility) plau;
Column 5: the Plausibility ratio rplau.
Claude Boivin, Peiyuan Zhu
Shafer, G., (1976). A Mathematical Theory of Evidence. Princeton University Press, Princeton, New Jersey, p. 39-43.
Williams, P., (1990). An interpretation of Shenoy and Shafer's axioms for local computation. International Journal of Approximate Reasoning 4, pp. 225-232.
Dempster, A., (2008). The Dempster–Shafer calculus for statisticians. International Journal of approximate reasoning, 48(2), 365-377.
x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DSA(x) y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "y", idvar = 1) xy <- normalize(DSC(x,y)) DSA(xy) print("compare all elementary events") xy1 <- addToDSM(x = xy, tt = matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) DSA(xy1) DSA(xy1, remove = TRUE) DSA(xy1, h = matrix(c(1,0,0,0,1,1), nrow = 2, byrow = TRUE))x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DSA(x) y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "y", idvar = 1) xy <- normalize(DSC(x,y)) DSA(xy) print("compare all elementary events") xy1 <- addToDSM(x = xy, tt = matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) DSA(xy1) DSA(xy1, remove = TRUE) DSA(xy1, h = matrix(c(1,0,0,0,1,1), nrow = 2, byrow = TRUE))
Calculate degree of unambiguous support (p), unambiguous contradiction (q), ambiguity (r), plausibility, and plausibility ratio
DSAh(MACC, W2, h) belplauH(MACC, W2, h)DSAh(MACC, W2, h) belplauH(MACC, W2, h)
MACC |
Vector of masses e.g. x$spec[,2] |
W2 |
Description matrix e.g. x$tt |
h |
Hypotheses to be tested, same format as x$tt |
A matrix of M rows by 5 columns is returned, where M is the number of hypothesis tested:
Column 1: the degree of unambiguous support p;
Column 2: the degree of unambiguous contradiction q;
Column 3: the degree of ambiguity r;
Column 4: the degree of Plausibility plau;
Column 5: the Plausibility ratio rplau.
Peiyuan Zhu
x <- DSM(tt = matrix(c(1,1,0,1,1,1), nrow = 2, byrow = TRUE), m = c(0.8, 0.2), cnames = c(1,2,3)) DSAh(MACC = x$spec[,2], W2 = x$tt, h = x$tt) hyp <- matrix(c(0,1,0,0,1,1), nrow = 2, byrow = TRUE) rownames(hyp) <- nameRows(hyp) DSAh(MACC = x$spec[,2], W2 = x$tt, h = hyp)x <- DSM(tt = matrix(c(1,1,0,1,1,1), nrow = 2, byrow = TRUE), m = c(0.8, 0.2), cnames = c(1,2,3)) DSAh(MACC = x$spec[,2], W2 = x$tt, h = x$tt) hyp <- matrix(c(0,1,0,0,1,1), nrow = 2, byrow = TRUE) rownames(hyp) <- nameRows(hyp) DSAh(MACC = x$spec[,2], W2 = x$tt, h = hyp)
The unnormalized Dempster's rule is used to combine two mass functions mx and my defined on the same state-space representation (SSR) and described by their respective basic mass assignments x and y. Dempster's rule of combination is applied. The normalization is not done, leaving the choice to the user to normalize the results or not (for the normalization operation, see function normalize).
DSC( x, y, mcores = "no", use_ssnames = FALSE, use_sparse = "no", varnames = NULL, skpt_tt = FALSE, relnb = NULL, infovarnames ) dsrwon( x, y, mcores = "no", use_ssnames = FALSE, use_sparse = "no", varnames = NULL, skpt_tt = FALSE, relnb = NULL, infovarnames )DSC( x, y, mcores = "no", use_ssnames = FALSE, use_sparse = "no", varnames = NULL, skpt_tt = FALSE, relnb = NULL, infovarnames ) dsrwon( x, y, mcores = "no", use_ssnames = FALSE, use_sparse = "no", varnames = NULL, skpt_tt = FALSE, relnb = NULL, infovarnames )
x |
A Dempster-Shafer model (see |
y |
A Dempster-Shafer model (see |
mcores |
Make use of multiple cores ("yes") or not ("no"). Default = "no". |
use_ssnames |
= TRUE to use ssnames instead of tt matrix to do the intersections. Default = FALSE |
use_sparse |
Make use of sparse matrices ("yes") or not ("no"). Default = "no". |
varnames |
A character string to name the resulting variable. named "z" if omitted. |
skpt_tt |
Skip reconstruction of tt matrix. Default = FALSE. |
relnb |
Identification number of the jointDSM. Can be omitted. |
infovarnames |
Deprecated. Old name for |
The two DSM's x and y must be defined on the same SSR for the combination to take place. The jointDSM number of the x input is given to the output result.
A Dempster-Shafer model with these two components added:
I12 Intersection table of subsets.
Sort_order Sort order of subsets.
Claude Boivin, Peiyuan Zhu
Shafer, G., (1976). A Mathematical Theory of Evidence. Princeton University Press, Princeton, New Jersey, p. 38: Basic probability assignment.
Guan, J. W. and Bell, D. A., (1991). Evidence Theory and its Applications. Elsevier Science Publishing company inc., New York, N.Y., p. 29: Mass functions and belief functions
Dempster, A., (2008). The Dempster–Shafer calculus for statisticians. International Journal of approximate reasoning, 48(2), 365-377.
y1 <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y2 <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DSC(y1,y2) # Sparse matrices y1s <- y1 y2s <- y2 y1s$tt <- methods::as(y1$tt, "RsparseMatrix") y2s$tt <- methods::as(y2$tt, "RsparseMatrix") y1y2s <- DSC(y1s, y2s, use_ssnames = TRUE) vacuous <- DSM(matrix(c(1,1,1), nrow = 1), m = 1, cnames = c("a","b","c")) DSC(vacuous, vacuous)y1 <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y2 <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) DSC(y1,y2) # Sparse matrices y1s <- y1 y2s <- y2 y1s$tt <- methods::as(y1$tt, "RsparseMatrix") y2s$tt <- methods::as(y2$tt, "RsparseMatrix") y1y2s <- DSC(y1s, y2s, use_ssnames = TRUE) vacuous <- DSM(matrix(c(1,1,1), nrow = 1), m = 1, cnames = c("a","b","c")) DSC(vacuous, vacuous)
Function DSM is used to define subsets of a finite set of possible values and to assign their corresponding mass value.
The set is called the state-space representation (SSR) or "frame of discernment". Each subset of with a positive mass value is called a focal set. The associated mass value is a number of the (0,1] interval, called "basic mass assignment" (the basic probability assignment of Shafer's book). All other subsets that have not received a positive mass value are assumed to have a mass value of zero.
DSM( tt = NULL, m, include_all = FALSE, ssr = NULL, cnames = NULL, con = NULL, ssnames = NULL, idvar = NULL, infovar = NULL, varnames = NULL, valuenames = NULL, inforel = NULL ) bca( tt = NULL, m, include_all = FALSE, ssr = NULL, cnames = NULL, con = NULL, ssnames = NULL, idvar = NULL, infovar = NULL, varnames = NULL, valuenames = NULL, inforel = NULL )DSM( tt = NULL, m, include_all = FALSE, ssr = NULL, cnames = NULL, con = NULL, ssnames = NULL, idvar = NULL, infovar = NULL, varnames = NULL, valuenames = NULL, inforel = NULL ) bca( tt = NULL, m, include_all = FALSE, ssr = NULL, cnames = NULL, con = NULL, ssnames = NULL, idvar = NULL, infovar = NULL, varnames = NULL, valuenames = NULL, inforel = NULL )
tt |
Mandatory. A (0,1)-matrix or a boolean matrix. The number of columns must match the number of elements (values) of the SSR |
m |
A numeric vector of length equal to the number of rows of the matrix |
include_all |
Default = FALSE. Put TRUE to include all elements with 0 mass in the DSM. |
ssr |
State space representation. Contains all the information pertaining to the underlying state space. See |
cnames |
A character vector containing the names of the elements of the SSR |
con |
The measure of conflict can be provided. 0 by default. |
ssnames |
A list of subsets names which will be obtained from the column names of the tt matrix. |
idvar |
The number given to the variable. A number is necessary to manage relations between variables of multidimensional state spaces and enable computations on a graph. 0 if omitted. |
infovar |
A two-column matrix containing variable identification number and the number of elements of the variable. Generated if omitted. |
varnames |
The name of the variable. Generated if omitted. |
valuenames |
A list of the names of the variables with the name of the elements of their SSR. |
inforel |
Not used here. Defined within function |
There is two ways of defining the DSM: a (0,1) matrix or a list of subsets labels.
y An object of class DSMspec called a DSM for "Dempster-Shafer model":
tt The table of focal sets. Rownames of the matrix of focal sets are generated from the column names of the elements of the frame. See nameRows for details.
spec A two column matrix. First column contains numbers given to the subsets, 1 to nrow(tt). Second column contains the mass values of the subsets.
con The measure of conflict.
infovar The number of the variable and the size of the SSM.
varnames The name of the variable.
valuenames A list of length 1 consisting of the name of the variable with the names of the elements of the SSM (the column names of the tt matrix).
ssnames A list of subsets names done from the column names of the tt matrix.
inforel Set at 0. used in function jointDSM.
Claude Boivin
Shafer, G., (1976). A Mathematical Theory of Evidence. Princeton University Press, Princeton, New Jersey, p. 38: Basic probability assignment.
Guan, J. W. and Bell, D. A., (1991). Evidence Theory and its Applications. Elsevier Science Publishing company inc., New York, N.Y., p. 29: Mass functions and belief functions
Dempster, A., (2008). The Dempster–Shafer calculus for statisticians. International Journal of approximate reasoning, 48(2), 365-377.
tt<- t(matrix(c(1,0,1,1),ncol = 2)) m<- c(.9,.1) cnames <- c("yes","no") DSM(tt, m) DSM(tt, m, cnames=cnames) tt1<- t(matrix(c(1,0,1,1),ncol = 2)) colnames(tt1) <- c("yes", "no") m <- c(.9, .1) DSM(tt=tt1, m, idvar = 1) y <- DSM(tt=matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), include_all = TRUE, cnames = c("a", "b", "c"),varnames = "y", idvar = 1) printDSM(y) vacuous <- DSM(matrix(c(1,1,1), nrow = 1), m = 1, cnames = c("a","b","c"), ssnames = c("a","b","c")) printDSM(vacuous) ss_Theta <- SSR(varnames = "x", idvar = 1, size = 3, cnames = c("a", "b", "c")) X <- DSM(tt=matrix(c(1,0,0,0,1,0,0,0,1), nrow = 3, byrow = TRUE), m = c(0.2, 0.3, 0.5), ssr = ss_Theta) printDSM(X)tt<- t(matrix(c(1,0,1,1),ncol = 2)) m<- c(.9,.1) cnames <- c("yes","no") DSM(tt, m) DSM(tt, m, cnames=cnames) tt1<- t(matrix(c(1,0,1,1),ncol = 2)) colnames(tt1) <- c("yes", "no") m <- c(.9, .1) DSM(tt=tt1, m, idvar = 1) y <- DSM(tt=matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), include_all = TRUE, cnames = c("a", "b", "c"),varnames = "y", idvar = 1) printDSM(y) vacuous <- DSM(matrix(c(1,1,1), nrow = 1), m = 1, cnames = c("a","b","c"), ssnames = c("a","b","c")) printDSM(vacuous) ss_Theta <- SSR(varnames = "x", idvar = 1, size = 3, cnames = c("a", "b", "c")) X <- DSM(tt=matrix(c(1,0,0,0,1,0,0,0,1), nrow = 3, byrow = TRUE), m = c(0.2, 0.3, 0.5), ssr = ss_Theta) printDSM(X)
The aplEncode function of the project APL in R (https://rpubs.com/deleeuw/158476) has been adapted to follow the standard implementation of the APL encode function.
encode(base, ind)encode(base, ind)
base |
A numeric vector which describes the number system in which we want to recode the data. |
ind |
The value to convert represented by a number or a numeric vector. |
A vector or a matrix of the data converted.
Claude Boivin
Jan de Leeuw and Masanao Yajima (March 07, 2016) APL in R (Version 009), Source code. https://rpubs.com/deleeuw/158476
L. Gilman and A. J. Rose.(1974): APL an Interactive Approach, Second Edition, John Wiley, New York.
APL 68000 Level II language manual. MicroAPL Ltd. 1990.
encode(c(2,2,2,2), 11) # find the base 2 representation of number 11 encode(c(365,24,60), 2997) # convert 2997 minutes to days-hrs-min.encode(c(2,2,2,2), 11) # find the base 2 representation of number 11 encode(c(365,24,60), 2997) # convert 2997 minutes to days-hrs-min.
This function works on a marginal DSM x defined on a single variable. It allows the addition of new values to the SSR.
extSSR(x, use_ssnames = FALSE, lab = NULL) extFrame(x, use_ssnames = FALSE, lab = NULL)extSSR(x, use_ssnames = FALSE, lab = NULL) extFrame(x, use_ssnames = FALSE, lab = NULL)
x |
An object of DSM class, i.e. a basic chance assignment defined on one SSR. |
use_ssnames |
Default= FALSE. Put TRUE if use of subset names is wanted. |
lab |
A character vector containing the names of the elements to add to the SSR. |
zxtnd The DSM within its SSR extended.
Claude Boivin
s1_e1 <- DSM(tt = matrix(c(1,0,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), cnames = c("S1","S2"), varnames = "v1", idvar = 1) s13_names <- extSSR(s1_e1, lab = "S3", use_ssnames =TRUE) s13 <- extSSR(s1_e1, lab = "S3") s13$valuenamess1_e1 <- DSM(tt = matrix(c(1,0,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), cnames = c("S1","S2"), varnames = "v1", idvar = 1) s13_names <- extSSR(s1_e1, lab = "S3", use_ssnames =TRUE) s13 <- extSSR(s1_e1, lab = "S3") s13$valuenames
fw: Relation between variables Forecast of the weather (F) and Weather at sea (W)This dataset is the tt matrix establishing the relation between the two variables. An accurate forecast is described by this subset of two event: (Forecast = foul, Weather = foul) and (Forecast = fair, Weather = fair). We assign a mass value of 0.8 to this subset. The remaining mass of 0.2 is allotted to the frame. To construct the tt matrix, we put the variables F and W side by side, as in a truth table representation. Each pair of the subset is described by a row of the matrix as a vector of zeros and ones.
fwfw
An integer matrix with 4 rows and 6 columns.
value = 0, not used
Identification numbers of the two variables. Column 3,6: variable 5; columns 5,6: variable 7.
identification number of the specification
the value of the specification, a number between 0 and 1
1 if foul is part of the specification, 0 otherwise
1 if fair is part of the specification, 0 otherwise
Claude Boivin
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
Function inters returns a table of the intersection between two (0,1) or boolean matrices or two vectors. The two matrices must have the same number of columns. The two vectors must be of the same length. This function generalizes the intersection of two subsets represented by boolean vectors to the intersection of two matrices of subsets.
inters(x, y)inters(x, y)
x |
A (0,1)-matrix or a boolean matrix of M rows by K columns, or a vector of length K. |
y |
A (0,1)-matrix or a boolean matrix of N rows by K columns or a vector of length K. |
The result is a (0,1)-table of dimensions (M x K) x N). In the case of vectors, the result is a (0,1)-table of dimensions (1 x K) x 1)
Claude Boivin
mx <- matrix(c(0,1,0,0,1,1,1,1,1),nrow = 3, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c"))) rownames(mx) <- nameRows(mx) my<-matrix(c(0,0,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c"))) rownames(my) <- nameRows(my) inters(mx,my) b1 <- matrix(c(FALSE, TRUE, TRUE), nrow=1) b2 <- matrix(c(TRUE, TRUE, FALSE), nrow=1) colnames(b1) <- colnames(b2) <- c("c1","c2","c3") inters(b1,b2) x3<-matrix(c(1,1,0,1), ncol = 2, dimnames = list(NULL, c("a","b"))) y3<-matrix(c(0,1,1,1), ncol = 2, dimnames = list(NULL, c("a","b"))) inters(x3,y3) x4 <-matrix(c(1,0,1,1,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c","d"))) y4 <-matrix(c(1,0,0,1,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c","d"))) inters(x4,y4) # Sparse matrices stt1 <- Matrix::sparseMatrix(i= c(1,1,2,2,3,3,3), j= c(2,3,1,2,1,2,3), x = 1, dims = c(3,3)) y1 <- bca(tt = stt1, m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) stt2 <- Matrix::sparseMatrix(i= c(1,2,2,2), j= c(1,1,2,3), x = 1, dims = c(2,3)) y2 <- bca(tt = stt2, m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) sr <-inters(y1$tt, y2$tt) sr class(sr)mx <- matrix(c(0,1,0,0,1,1,1,1,1),nrow = 3, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c"))) rownames(mx) <- nameRows(mx) my<-matrix(c(0,0,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c"))) rownames(my) <- nameRows(my) inters(mx,my) b1 <- matrix(c(FALSE, TRUE, TRUE), nrow=1) b2 <- matrix(c(TRUE, TRUE, FALSE), nrow=1) colnames(b1) <- colnames(b2) <- c("c1","c2","c3") inters(b1,b2) x3<-matrix(c(1,1,0,1), ncol = 2, dimnames = list(NULL, c("a","b"))) y3<-matrix(c(0,1,1,1), ncol = 2, dimnames = list(NULL, c("a","b"))) inters(x3,y3) x4 <-matrix(c(1,0,1,1,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c","d"))) y4 <-matrix(c(1,0,0,1,1,1,1,1),nrow = 2, byrow = TRUE, dimnames = list(NULL, c("a", "b", "c","d"))) inters(x4,y4) # Sparse matrices stt1 <- Matrix::sparseMatrix(i= c(1,1,2,2,3,3,3), j= c(2,3,1,2,1,2,3), x = 1, dims = c(3,3)) y1 <- bca(tt = stt1, m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) stt2 <- Matrix::sparseMatrix(i= c(1,2,2,2), j= c(1,1,2,3), x = 1, dims = c(2,3)) y2 <- bca(tt = stt2, m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) sr <-inters(y1$tt, y2$tt) sr class(sr)
Intersect two vectors of ssnames
intersBySSName(zx, yz)intersBySSName(zx, yz)
zx |
a vector of ssnames from one bca |
yz |
a vector of ssnames from another bca |
ssnames in the intersection of the two bcas
Peiyuan Zhu
y1 <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y2 <- bca(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) intersBySSName(y1$ssnames[[1]], y2$ssnames[[2]])y1 <- bca(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y2 <- bca(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) intersBySSName(y1$ssnames[[1]], y2$ssnames[[2]])
Function jointDSM is used to assign mass values to subsets defined in a finite multidimensional state space , which is the product space of unidimensional spaces , , ..., . To achieve the definition of the joint DSM of a focal element, a relation between two or more unidimensional SSR is described by one or more subsets of , , ..., . Hence each subset can possibly include more than one element. Complete disjunctive coding is used to represent a subset in the input matrix of the function.
jointDSM( tt, spec, infovar = NULL, ssrlist = NULL, varnames, valuenames, relnb = NULL ) bcaRel( tt, spec, infovar = NULL, ssrlist = NULL, varnames, valuenames, relnb = NULL )jointDSM( tt, spec, infovar = NULL, ssrlist = NULL, varnames, valuenames, relnb = NULL ) bcaRel( tt, spec, infovar = NULL, ssrlist = NULL, varnames, valuenames, relnb = NULL )
tt |
The description matrix of the subsets establishing the relation between |
spec |
A two column matrix. First column: numbers assigned to the subsets. Second column: the mass values of the subsets. If a subset has more than one element (row), the number of the subset and its associated mass value are repeated to match the number of elements (rows) of the subset. |
infovar |
A two column matrix containing SSR identification numbers and the number of elements of each SSR. The identification numbers must be ordered in increasing number. May be omitted if the state space list is given (parameter *ssrlist*). |
ssrlist |
The list of 1D state spaces to use. |
varnames |
The names of the SSR. May be omitted if the state space list is given (parameter *ssrlist*). |
valuenames |
A list of the names of the SSR with the name of the elements of their SSR. May be omitted if the state space list is given (parameter *ssrlist*). |
relnb |
A number given to the jointDSM. Set at 0 if omitted. |
An object of class DSMspec called a DSM or "basic mass assignment". This is a list containing the following components:
con The measure of conflict.
tt The resulting table of subsets in its joint statte Space representation. Rownames of the matrix of subsets are generated from the column names of the elements of the product space. See nameRows for details.
spec The resulting two-column matrix of specification numbers with associated mass values.
infovar The two-column matrix of SSR number and size.
valuenames A list of the names of the SSR with the name of their elements.
inforel A two-column matrix containing the relation number and the number of SSRs of the relation.
Claude Boivin
# A logical implication rule # A typical relation between two variables is the # logical implication a -> b. Let us suppose # that a stands for Rain: {yes, no} and b stands for # Roadworks: {yes, no}. From experience, # I am 75 % sure that there will be RoadWorks if there is no rain. # 0. Define State space representations ssWorks <- SSR(varnames = "W", idvar = 4, size = 2, cnames = c("Wy", "Wn") ) ssRain <- SSR(varnames = "R", idvar = 5, size = 2, cnames = c("Ry", "Rn") ) ssrWR <- list(ssWorks, ssRain) # 1. The tt table of the logical implication ttrwf <- matrix(c(0,1,1,0,1,0,1,0,1,0,0,1,1,1,1,1), nrow = 4, byrow = TRUE, dimnames = list(NULL, unlist(sapply(ssrWR, `[[`,4))) ) # 2. The mass distribution specrw <- matrix(c(1,1,1,2,0.75,0.75,0.75,0.25), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) rel <- jointDSM(tt = ttrwf, spec = specrw, ssrlist = ssrWR, relnb = 6)# A logical implication rule # A typical relation between two variables is the # logical implication a -> b. Let us suppose # that a stands for Rain: {yes, no} and b stands for # Roadworks: {yes, no}. From experience, # I am 75 % sure that there will be RoadWorks if there is no rain. # 0. Define State space representations ssWorks <- SSR(varnames = "W", idvar = 4, size = 2, cnames = c("Wy", "Wn") ) ssRain <- SSR(varnames = "R", idvar = 5, size = 2, cnames = c("Ry", "Rn") ) ssrWR <- list(ssWorks, ssRain) # 1. The tt table of the logical implication ttrwf <- matrix(c(0,1,1,0,1,0,1,0,1,0,0,1,1,1,1,1), nrow = 4, byrow = TRUE, dimnames = list(NULL, unlist(sapply(ssrWR, `[[`,4))) ) # 2. The mass distribution specrw <- matrix(c(1,1,1,2,0.75,0.75,0.75,0.25), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) rel <- jointDSM(tt = ttrwf, spec = specrw, ssrlist = ssrWR, relnb = 6)
The array representation or product space representation is converted to the matrix representation of the corresponding relation.
marrayToMatrix(mtt)marrayToMatrix(mtt)
mtt |
The matrix |
The matrix representation of the data.
Claude Boivin
mtt <- array(c(1,0,0,0,1,1,0,0,1,0,0,1,1,0,1,0,1,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1), c(2,2,8), dimnames = list( RdWorks=c("Wy", "Wn") , Rain = c("Ry", "Rn"), ev=1:8) ) print(z <- marrayToMatrix(mtt))mtt <- array(c(1,0,0,0,1,1,0,0,1,0,0,1,1,0,1,0,1,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1), c(2,2,8), dimnames = list( RdWorks=c("Wy", "Wn") , Rain = c("Ry", "Rn"), ev=1:8) ) print(z <- marrayToMatrix(mtt))
The matrix representation of a relation is converted to the array representation or product space representation.
matrixToMarray(tt, valuenames)matrixToMarray(tt, valuenames)
tt |
A (0,1)-matrix or a boolean matrix establishing the relation between two or more variables. The matrix is constructed by placing the variables side by side, as in a truth table representation. |
valuenames |
A list of the names of the variables with the name of each value of their frame of discernment. |
mtt The array (product space) representation of the tt matrix.
Claude Boivin
# Define wr_tt, a matrix describing the relation between two variables wr_tt <- matrix(c(1,rep(0,3),rep(c(1,0),3),0,1,1,1,0,0, 1,0,rep(1,5),0,1,1,0,rep(1,5)), ncol=4, byrow = TRUE) colnames(wr_tt) <- c("Wy Ry", "Wy Rn", "Wn Ry", "Wn Rn") rownames(wr_tt) <- nameRows(wr_tt) vars = list( RdWorks = c("Wy", "Wn") , Rain = c("Ry", "Rn")) print(zmToa <- matrixToMarray(tt = wr_tt, valuenames = vars ) )# Define wr_tt, a matrix describing the relation between two variables wr_tt <- matrix(c(1,rep(0,3),rep(c(1,0),3),0,1,1,1,0,0, 1,0,rep(1,5),0,1,1,0,rep(1,5)), ncol=4, byrow = TRUE) colnames(wr_tt) <- c("Wy Ry", "Wy Rn", "Wn Ry", "Wn Rn") rownames(wr_tt) <- nameRows(wr_tt) vars = list( RdWorks = c("Wy", "Wn") , Rain = c("Ry", "Rn")) print(zmToa <- matrixToMarray(tt = wr_tt, valuenames = vars ) )
mrf: Relation between variables No Maintenance (M = false) and Repairs at sea (R)This dataset is the tt matrix establishing a set of two relations between the two variables. First, Repairs = true if Maintenance = false in (M x R). We are 20% sure that there will be Repairs if no maintenance. Second, Repairs = false if Maintenance = false in (M x R). We are 20% sure that there will be no repairs if no maintenance.
mrfmrf
A (0,1) matrix with 4 rows and 6 columns.
value = 0, not used
Identification numbers of the two variables. Column 3,4: variable 6; columns 5,6: variable 8
identification number of the specification
the value of the specification, a number between 0 and 1
1 if true is part of the specification, 0 otherwise
1 if false is part of the specification, 0 otherwise
These two relations are implication rules. The remaining mass of 0.6 is allotted to the frame. To construct the tt matrix, we put the variables M and R side by side, as in a truth table representation. Each pair of the subset is described by a row of the matrix as a vector of zeros and ones.
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
mrt: Relation between variables Maintenance done (M = true) and Repairs at sea (R)This dataset is the tt matrix establishing a set of two relations between the two variables. First, Repairs = true if Maintenance = true in (M x R). We are 10% sure that there will be Repairs if maintenance is done. Second, Repairs = false if Maintenance = true in (M x R). We are 70% sure that there will be no repairs if maintenance is done.
mrtmrt
A (0,1) matrix with 4 rows and 6 columns.
value = 0, not used
Identification numbers of the two variables. Column 3,4: variable 6; columns 5,6: variable 8
identification number of the specification
the value of the specification, a number between 0 and 1
1 if true is part of the specification, 0 otherwise
1 if false is part of the specification, 0 otherwise
These two relations are implication rules. The remaining mass of 0.2 is allotted to the frame. To construct the tt matrix, we put the variables M and R side by side, as in a truth table representation. Each pair of the subset is described by a row of the matrix as a vector of zeros and ones.
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
tt matrixThis utility function makes use of the valuenames and size parameters of a set of variables to assign values names to the columns of a tt matrix.
nameCols(valuenames, size)nameCols(valuenames, size)
valuenames |
A list of the names of the variables with the name of the elements of their frame of discernment. |
size |
A vector of the size of the variables. |
A character vector of length equal to the sum of the sizes of the variables.
Claude Boivin
infoval <- list(A = c("a1", "a2"), B = c("b1", "b2", "b3")) sizes <- c(2,3) print(nameCols(valuenames = infoval, size = sizes) )infoval <- list(A = c("a1", "a2"), B = c("b1", "b2", "b3")) sizes <- c(2,3) print(nameCols(valuenames = infoval, size = sizes) )
tt matrix of a product spaceThis utility function makes use of the valuenames and size parameters of a set of variables to assign values names to the columns of the tt matrix of their product space.
nameCols_prod(valuenames, size)nameCols_prod(valuenames, size)
valuenames |
A list of the names of the variables with the name of the elements of their frame of discernment. |
size |
A vector of the size of the variables. |
A character vector of length equal to the product of the sizes of the variables.
Claude Boivin
infoval <- list(A = c("a1", "a2"), B = c("b1", "b2", "b3")) sizes <- c(2,3) print(nameCols_prod(valuenames = infoval, size = sizes) )infoval <- list(A = c("a1", "a2"), B = c("b1", "b2", "b3")) sizes <- c(2,3) print(nameCols_prod(valuenames = infoval, size = sizes) )
This function determines the name of a row from all the columns of the tt that show 1 for that row.
nameRows(tt, f)nameRows(tt, f)
tt |
A (0,1)-matrix or a boolean matrix. |
f |
Deprecated. Old name for |
The row containing only 1s is called "frame", to avoid too long a label. The empty set is identified by its code "u00f8". The "+" sign is used to represent the logical "or" operator. The space " " is used to represent the logical "and" operator. Note that in the case of a product space defined on many variables, row labels can become very long.
A character vector of labels obtained for the rows of the tt matrix. The length of the result is nrow(tt).
Claude Boivin
tt <- matrix(c(0,0,0,1,0,0,0,0,1,1,0,1,1,1,1),ncol = 3, byrow = TRUE) colnames(tt) <- c("A","B","C") rownames(tt) <-nameRows(tt) tttt <- matrix(c(0,0,0,1,0,0,0,0,1,1,0,1,1,1,1),ncol = 3, byrow = TRUE) colnames(tt) <- c("A","B","C") rownames(tt) <-nameRows(tt) tt
It may occur that the result of the combination of two basic chance assignments with Dempster's Rule of combination contains a non-zero mass allocated to the empty set. The function nzdsr normalizes the result of function dsrwon by dividing the mass value of the non-empty subsets by 1 minus the mass of the empty set.
normalize(x, sparse = "no", comm = "no") nzdsr(x, sparse = "no", comm = "no")normalize(x, sparse = "no", comm = "no") nzdsr(x, sparse = "no", comm = "no")
x |
A basic chance assignment, i.e. a object of class bcaspec. |
sparse |
Put "yes" to use sparse matrix. Default = "no". |
comm |
Put "yes" to use commonality function. Default = "no". |
z The normalized basic chance assignment.
Claude Boivin, Peiyuan Zhu
Shafer, G., (1976). A Mathematical Theory of Evidence. Princeton University Press, Princeton, New Jersey, pp. 57-61: Dempster's rule of combination.
x1 <- bca(tt= matrix(c(1,0,1,1),nrow = 2, byrow = TRUE), m = c(0.9,0.1), cnames = c("yes", "no"), varnames = "x", idvar = 1) x2 <- bca(tt = matrix(c(0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.5,0.5), cnames = c("yes", "no"), varnames = "x", idvar = 1) print("combination of x1 and x2") x1x2 <- dsrwon(x1,x2, varname = "x") nzdsr(x1x2) # Test with sparse matrices x1s=x1 x2s=x2 x1s$tt <- methods::as(x1$tt, "RsparseMatrix") x2s$tt <- methods::as(x2$tt, "RsparseMatrix") x1x2s <- dsrwon(x1s, x2s, use_ssnames = TRUE) nzdsr(x1x2s) print("normalization of a bca definition.") y2 <- bca(tt = matrix(c(0,0,0,1,0,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5,0.3), cnames = c("a", "b", "c"), idvar = 1) cat("y2") cat("\ ") y2 nzdsr(y2)x1 <- bca(tt= matrix(c(1,0,1,1),nrow = 2, byrow = TRUE), m = c(0.9,0.1), cnames = c("yes", "no"), varnames = "x", idvar = 1) x2 <- bca(tt = matrix(c(0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.5,0.5), cnames = c("yes", "no"), varnames = "x", idvar = 1) print("combination of x1 and x2") x1x2 <- dsrwon(x1,x2, varname = "x") nzdsr(x1x2) # Test with sparse matrices x1s=x1 x2s=x2 x1s$tt <- methods::as(x1$tt, "RsparseMatrix") x2s$tt <- methods::as(x2$tt, "RsparseMatrix") x1x2s <- dsrwon(x1s, x2s, use_ssnames = TRUE) nzdsr(x1x2s) print("normalization of a bca definition.") y2 <- bca(tt = matrix(c(0,0,0,1,0,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5,0.3), cnames = c("a", "b", "c"), idvar = 1) cat("y2") cat("\ ") y2 nzdsr(y2)
An implementation of the peeling algorithm based on its description in terms of hypergraphs by R. Almond [1989].
peeling(vars_def, hgm, hg_rel_names, elim_order, verbose = FALSE)peeling(vars_def, hgm, hg_rel_names, elim_order, verbose = FALSE)
vars_def |
A list of variables and their possible values. Concatenate the valuenames parameter of all the variables of the hypergraph to obtain this list. |
hgm |
The incidence matrix of the hypergraph (bipartite graph), which is the description of the relations between the variables. The variables are the nodes of the hypergraph, and the relations are the edges. Each column describes a relation between the variables by a (0,1) vector. A "1" indicates that a variable belongs to the relation and a "0" not. This matrix must have row and column names. These names are used to show the graph eventually. They need not be the same as variables and relations names of the set of bca's to be analyzed. Use short names to obtain a clear graph. |
hg_rel_names |
The names of the relations, which are objects of class "bcaspec". |
elim_order |
The order of elimination of the variables. A vector of length |
verbose |
= TRUE: print steps on the console. Default = FALSE. |
The peeling algorithm works on an undirected graph. Nodes of the graph (variables) are removed one by one until only the variable of interest remains. An order of elimination (peeling) of the variables must be chosen by the user. No algorithm is provided for that matter. At each step, a procedure of extension is applied to the bca's to merge, and marginalization is applied to eliminate a variable. The marginalization has the effect to integrate in the remaining nodes the information of the eliminated variable.
A bca class object.
Claude Boivin
Almond, R. G. (1989) Fusion and Propagation of Graphical Belief Models: An Implementation and an Example. Ph. D. Thesis, the Department of Statistics, Harvard University. 288 pages (for the description of the peeling algorithm, see pages 52-53).
# Zadeh's Example # 1. Defining variables and relations # (for details, see vignette: Zadeh_Example) e1 <- bca(tt = matrix(c(1,0,0,1,1,1), ncol = 2, byrow = TRUE), m = c(0.99, 0.01, 0), cnames = c("M", "T"), varnames = "D1", idvar = 1) e2 <- bca(tt = matrix(c(1,0,0,1,1,1), ncol = 2, byrow = TRUE), m = c(0.99, 0.01, 0), cnames = c("C", "T"), varnames = "D2", idvar = 2) p_diag <- bca(tt = matrix(c(1,1,1), ncol = 3, byrow = TRUE), m = 1, cnames = c("M", "T", "C"), varnames = "D", idvar = 3) # Defining the relation between the variables # tt matrix tt_r1 <- matrix(c(1,0,1,0,1,0,0,1,0,1,0,0,0,1, 1,0,0,1,1,0,0,1,0,0,1,0,1,0,0,1,1,0,0,1,0, 0,1,1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1), ncol = 7,byrow = TRUE) colnames(tt_r1) = c("M", "T", "C", "T", "M", "T", "C") # The mass function spec_r1 <- matrix(c(rep(1,7),2, rep(1,7), 0), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) # Variables numbers and dimension of their frame info_r1 <- matrix(c(1:3, 2,2,3), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) # The relation between e1, e2 and a patient p r1 <- bcaRel(tt = tt_r1, spec = spec_r1, infovar = info_r1, varnames = c("D1", "D2", "D"), relnb = 1) # 2. Setting the incidence matrix of the grapph rel1 <- 1*1:3 %in% r1$infovar[,1] ev1 <- 1*1:3 %in% e1$infovar[,1] ev2 <- 1*1:3 %in% e2$infovar[,1] meddiag_hgm <- matrix(c(ev1,ev2, rel1), ncol = 3, dimnames = list(c("D1", "D2", "D"), c("e1","e2", "r1"))) # 3. Setting the names of the variables and their frame of discernment meddiag_vars1 <- c(e1$valuenames, e2$valuenames, p_diag$valuenames) # 4. Names of bca specifications (evidence and relations) meddiag_rel_names <- c("e1", "e2", "r1") # 5. Order of elimination of variables elim_order <- c(1,2,3) tabresul(peeling(vars_def = meddiag_vars1, hgm = meddiag_hgm, hg_rel_names = meddiag_rel_names, elim_order = c(1, 2, 3)) )# Zadeh's Example # 1. Defining variables and relations # (for details, see vignette: Zadeh_Example) e1 <- bca(tt = matrix(c(1,0,0,1,1,1), ncol = 2, byrow = TRUE), m = c(0.99, 0.01, 0), cnames = c("M", "T"), varnames = "D1", idvar = 1) e2 <- bca(tt = matrix(c(1,0,0,1,1,1), ncol = 2, byrow = TRUE), m = c(0.99, 0.01, 0), cnames = c("C", "T"), varnames = "D2", idvar = 2) p_diag <- bca(tt = matrix(c(1,1,1), ncol = 3, byrow = TRUE), m = 1, cnames = c("M", "T", "C"), varnames = "D", idvar = 3) # Defining the relation between the variables # tt matrix tt_r1 <- matrix(c(1,0,1,0,1,0,0,1,0,1,0,0,0,1, 1,0,0,1,1,0,0,1,0,0,1,0,1,0,0,1,1,0,0,1,0, 0,1,1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1), ncol = 7,byrow = TRUE) colnames(tt_r1) = c("M", "T", "C", "T", "M", "T", "C") # The mass function spec_r1 <- matrix(c(rep(1,7),2, rep(1,7), 0), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) # Variables numbers and dimension of their frame info_r1 <- matrix(c(1:3, 2,2,3), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) # The relation between e1, e2 and a patient p r1 <- bcaRel(tt = tt_r1, spec = spec_r1, infovar = info_r1, varnames = c("D1", "D2", "D"), relnb = 1) # 2. Setting the incidence matrix of the grapph rel1 <- 1*1:3 %in% r1$infovar[,1] ev1 <- 1*1:3 %in% e1$infovar[,1] ev2 <- 1*1:3 %in% e2$infovar[,1] meddiag_hgm <- matrix(c(ev1,ev2, rel1), ncol = 3, dimnames = list(c("D1", "D2", "D"), c("e1","e2", "r1"))) # 3. Setting the names of the variables and their frame of discernment meddiag_vars1 <- c(e1$valuenames, e2$valuenames, p_diag$valuenames) # 4. Names of bca specifications (evidence and relations) meddiag_rel_names <- c("e1", "e2", "r1") # 5. Order of elimination of variables elim_order <- c(1,2,3) tabresul(peeling(vars_def = meddiag_vars1, hgm = meddiag_hgm, hg_rel_names = meddiag_rel_names, elim_order = c(1, 2, 3)) )
tt matrix and mass values of a Dempster-Shafer ModelThis utility function does a simple printing of a DSM (basic chance assignment).
printDSM(x, remove = FALSE) bcaPrint(x, remove = FALSE)printDSM(x, remove = FALSE) bcaPrint(x, remove = FALSE)
x |
A list of class DSMspec. |
remove |
Default = FALSE. Put = TRUE to exclude subsets with zero mass. |
A table of subsets with their associated mass. Subsets are identified by row names.
Claude Boivin
z <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1) printDSM(z) y <- DSM(tt=matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), include_all = TRUE, cnames = c("a", "b", "c"),varnames = "y", idvar = 1) printDSM(y) printDSM(y, remove = TRUE) x <- DSM(tt=matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1, method = "ezt-m") printDSM(x)z <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1) printDSM(z) y <- DSM(tt=matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6,0.4), include_all = TRUE, cnames = c("a", "b", "c"),varnames = "y", idvar = 1) printDSM(y) printDSM(y, remove = TRUE) x <- DSM(tt=matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), idvar = 1, method = "ezt-m") printDSM(x)
This utility function takes the input matrix of a relation between two or more variables and yields its product space representation.
productSpace(tt, specnb, infovar)productSpace(tt, specnb, infovar)
tt |
A (0,1) or boolean matrix, where the variables are set side by side, as in a truth table. Each variable has a number of columns equal to the number of possible values. |
specnb |
A vector of integers ranging from 1 to |
infovar |
A two-column matrix containing identification numbers of the variables and the number of elements of each variable (size of the frame). |
The matrix of the product space representation of the relation.
Claude Boivin
ttfw <- matrix(c(1,0,1,0,0,1,0,1,1,1,1,1),nrow = 3, byrow = TRUE, dimnames = list(NULL, c("foul", "fair", "foul", "fair")) ) specfw <- c(1,1,2) infovarfw <- matrix(c(5,7,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) rownames(ttfw) <- nameRows(ttfw) ttfw productSpace(tt = ttfw, specnb = specfw, infovar = infovarfw)ttfw <- matrix(c(1,0,1,0,0,1,0,1,1,1,1,1),nrow = 3, byrow = TRUE, dimnames = list(NULL, c("foul", "fair", "foul", "fair")) ) specfw <- c(1,1,2) infovarfw <- matrix(c(5,7,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) rownames(ttfw) <- nameRows(ttfw) ttfw productSpace(tt = ttfw, specnb = specfw, infovar = infovarfw)
Given a mass function defined on some subsets of a frame , the application of the plausibility transformation to the singletons of yields the probability distribution associated with this mass function.
PT(x) plautrans(x)PT(x) plautrans(x)
x |
A DSM. |
We compute the plausibility measure of all the singletons of the frame of discernment. The probability distribution of the singletons is obtained from their plausibility measures.
The matrix of singletons with their plausibility transformation added in the last column.
Claude Boivin
Cobb, B. R. and Shenoy, P.P. (2006). On the plausibility transformation method for translating belief function models to probability models. Journal of Approximate Reasoning, 41(3), April 2006, 314–330.
x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) PT(x)x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) PT(x)
Performs the plausibility transform on the combination of multiple simple Dempster-Shafer models (simDSMs) defined over a large state-space representation (SSR).
PTsimDSM(x, y, a, y0 = 0, flip = TRUE)PTsimDSM(x, y, a, y0 = 0, flip = TRUE)
x |
A binary matrix where each row represents a focal element that is not the full SSR. |
y |
A logical column matrix indicating which rows of |
a |
A numeric value (0 ≤ |
y0 |
A reference value (default = 0 or |
flip |
Logical; whether to perform row inversion where applicable (default = |
This function handles the case where several simple Dempster-Shafer models are combined on a very large SSR.
Each row of the binary matrix x represents a focal element from one simDSM that is *not* the entire SSR.
These focal elements can be specified directly or as complements, depending on which is more efficient to encode.
A logical column matrix y identifies which rows of x need to be inverted (using the value y0 as the check).
A numeric plausibility vector plau.
Peiyuan Zhu
Shafer, G., (1976). A Mathematical Theory of Evidence. Princeton University Press, Princeton, New Jersey, p. 38: Basic probability assignment.
Barnett, J. A. (1991). Calculating dempster-shafer plausibility. IEEE transactions on pattern analysis and machine intelligence, 13(6), 599-602.
Cobb, B. R. and Shenoy, P.P. (2006). On the plausibility transformation method for translating belief function models to probability models. Journal of Approximate Reasoning, 41(3), April 2006, 314–330.
# Example usage: x <- matrix(c(1, 0, 1, 1, 0, 0), nrow = 2, byrow = TRUE) y <- matrix(c(TRUE, FALSE)) PTsimDSM(x, y, a = 0.3)# Example usage: x <- matrix(c(1, 0, 1, 1, 0, 0), nrow = 2, byrow = TRUE) y <- matrix(c(TRUE, FALSE)) PTsimDSM(x, y, a = 0.3)
shape returns the dimension of given array or returns the length of a given vector. The function is taken from the project APL in R (https://rpubs.com/deleeuw/158476).
shape(a)shape(a)
a |
An array or a vector. |
The dimension of the array a or the length of the vector a.
Claude Boivin
Jan de Leeuw and Masanao Yajima (March 07, 2016) APL in R (Version 009), Source code. https://rpubs.com/deleeuw/158476
G. Helzer. (1989): An Encyclopedia of APL, second edition, I-APL LTD, St. Albans, G.B.
L. Gilman and A. J. Rose.(1974): APL an Interactive Approach, Second Edition, John Wiley, New-York.
shape(array(c(1:6), c(2,3))) shape(c("a", "b"))shape(array(c(1:6), c(2,3))) shape(c("a", "b"))
Function SSR is used to specify a set of possible values.
The set is called the state space.
SSR(varnames = NULL, idvar = NULL, size = NULL, cnames = NULL)SSR(varnames = NULL, idvar = NULL, size = NULL, cnames = NULL)
varnames |
The name of the variable. Generated if omitted. |
idvar |
The number given to the state space. A number is necessary to manage relations between variables of multidimensional state spaces and enable computations on a graph. 0 if omitted. |
size |
The number of elements of the state space representation |
cnames |
A character vector containing the names (labels) of the elements of the state space |
y A list called a SSR for "State Space Representation":
infovar The number of the variable and the size of the state space.
varnames The name of the variable.
valuenames A list of length 1 consisting of the name of the variable with the names (labels) of the elements of the state space.
Claude Boivin
dDmpster (2007)...
Gonng (2024)...
ss1 <- SSR("x1", 1,4,c("a","b","c","d"))ss1 <- SSR("x1", 1,4,c("a","b","c","d"))
swr: Relation between variables Sailing delay (S), Weather at sea (W), and Repairs at sea (R)This dataset is the tt matrix establishing a relation between S, W and R, where S = 0:3, W = (foul, fair) and R = (true, false). The goal of this relation is to account for other causes of sailing delay. All the elements (s,w,r) of (S x W x R) where W or R is true add one day of sailing delay. We put a mass value of 0.9 to this subset. The remaining mass of 0.1 is allotted to the frame.
swrswr
An integer matrix with 6 rows and 10 columns.
value = 0, not used
Identification numbers of the three variables. Column 3 to 6: variable 3; columns 7,8: variable 7, columns 9,10: variable 8
identification number of the specification
the value of the specification, a number between 0 and 1
1 if 3 is part of the specification, 0 otherwise
1 if 2 is part of the specification, 0 otherwise
1 if 1 is part of the specification, 0 otherwise
1 if 0 is part of the specification, 0 otherwise
1 if foul is part of the specification, 0 otherwise
1 if fair is part of the specification, 0 otherwise
1 if true is part of the specification, 0 otherwise
1 if false is part of the specification, 0 otherwise
To construct the tt matrix, we put the variables S, W, R side by side, as in a truth table representation. Each triplet of the subset is described by a row of the matrix as a vector of zeros and ones.
Claude Boivin, Stat.ASSQ
Almond, R.G. [1988] Fusion and Propagation in Graphical Belief Models. Computing Science and Statistics: Proceedings of the 20th Symposium on the Interface. Wegman, Edward J., Gantz, Donald T. and Miller, John J. (ed.). American Statistical Association, Alexandria, Virginia. pp 365–370.
This utility function is a more detailed version of the DSA function. Different tables of measures of belief, plausibility and of the plausibility ratio can be obtained, namely by removing subsets with zero mass if present, or by asking for singletons only. Unlike function DSA, function tabresul does not reconstruct the row names from the column names. You can assign short rownames of your choice to the tt matrix of your resulting DSM before calling function tabresul.
tabresul(x, singletonsOnly = FALSE, removeZeroes = FALSE)tabresul(x, singletonsOnly = FALSE, removeZeroes = FALSE)
x |
A basic chance assignment (DSM) |
singletonsOnly |
= TRUE reduces the table of results to elementary events (singletons). |
removeZeroes |
= TRUE removes subsets with 0 mass. |
A list of two elements:
mbp The table of focal elements with the addition of their associated mass, degree of belief, plausibility and the plausibility ratio.
con The measure of conflict between subsets.
Claude Boivin
x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "y", idvar = 1) xy <- DSC(x,y) xyNorm <- normalize(xy) tabresul(xyNorm) ## print("Show all elementary events") xy1 <- addToDSM(normalize(DSC(x,y)), matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) tabresul(xy1) ## print("Remove focal elements with 0 mass") tabresul(xy1, removeZeroes = TRUE) print("Retain singletons only") tabresul(xy1, singletonsOnly = TRUE)x <- DSM(tt = matrix(c(0,1,1,1,1,0,1,1,1),nrow = 3, byrow = TRUE), m = c(0.2,0.5, 0.3), cnames = c("a", "b", "c"), varnames = "x", idvar = 1) y <- DSM(tt = matrix(c(1,0,0,1,1,1),nrow = 2, byrow = TRUE), m = c(0.6, 0.4), cnames = c("a", "b", "c"), varnames = "y", idvar = 1) xy <- DSC(x,y) xyNorm <- normalize(xy) tabresul(xyNorm) ## print("Show all elementary events") xy1 <- addToDSM(normalize(DSC(x,y)), matrix(c(0,1,0,0,0,1), nrow = 2, byrow = TRUE)) tabresul(xy1) ## print("Remove focal elements with 0 mass") tabresul(xy1, removeZeroes = TRUE) print("Retain singletons only") tabresul(xy1, singletonsOnly = TRUE)
When working with large frames of discernment, the DSM resulting of repeated application of Dempster's Rule of Combination can become quite large. One way to handle this situation is to group together subsets whose mass is less than a small threshold value. The function DSMtrunc is used for this purpose.
truncateDSM(x, seuil, use_ssnames = FALSE) bcaTrunc(x, seuil, use_ssnames = FALSE)truncateDSM(x, seuil, use_ssnames = FALSE) bcaTrunc(x, seuil, use_ssnames = FALSE)
x |
A DSM to truncate. |
seuil |
A treshold value |
use_ssnames |
Put TRUE to use ssnames parameteer instead of description matrix. Default = FALSE. |
tr_x The DSM object truncated.
Claude Boivin
x <- DSM(tt = matrix(c(0,1,0,0, 0,0,1,1, 1,1,0,0, 1,0,1,0, 0,1,1,0, 1,1,1,1),ncol=4, byrow = TRUE), m = c(0.2, 0.5, 0.06, 0.04, 0.03, 0.17), cnames = c("a", "b", "c", "d")) printDSM(x) tr_x <- truncateDSM(x, seuil = 0.1) printDSM(tr_x)x <- DSM(tt = matrix(c(0,1,0,0, 0,0,1,1, 1,1,0,0, 1,0,1,0, 0,1,1,0, 1,1,1,1),ncol=4, byrow = TRUE), m = c(0.2, 0.5, 0.06, 0.04, 0.03, 0.17), cnames = c("a", "b", "c", "d")) printDSM(x) tr_x <- truncateDSM(x, seuil = 0.1) printDSM(tr_x)
Construct a description matrix from a list of subsets names.
ttmatrix(x, sparse = "no")ttmatrix(x, sparse = "no")
x |
A list of names |
sparse |
= c("yes","no") whether to use sparse matrix. Default = "no". |
ttmat A corresponding logical description matrix
Claude Boivin
subsets_names <- list(c("b", "c"), "b", c("a", "b", "c")) ttmatrix(subsets_names) znames <- list("empty", "a", c("b", "c"), c("a", "b"), c("a", "b", "c") ) print(ttmatrix(znames) ) print(ttmatrix(znames, sparse = "yes") )subsets_names <- list(c("b", "c"), "b", c("a", "b", "c")) ttmatrix(subsets_names) znames <- list("empty", "a", c("b", "c"), c("a", "b"), c("a", "b", "c") ) print(ttmatrix(znames) ) print(ttmatrix(znames, sparse = "yes") )
This function works on a basic chance assignment (bca) x defined on a single variable or more. A relation of reference is given, and an extension of the space of x is made to the larger product space of the relation of reference. The basic chance assignment to extend and the relation of reference must have at least one common variable for the extension to occur.
uproj(rel1, relRef) extmin(rel1, relRef)uproj(rel1, relRef) extmin(rel1, relRef)
rel1 |
An object of class DSMspec, i.e. a basic chance assignment defined on one variable or a relation. |
relRef |
The relation of reference. It can be an existing relation, or it can be constructed as a vacuous function. |
The relRef parameter is used to extract all the information on the variables, namely their identification numbers and the number of elements of each variable, variables names and columns names of the tt matrix. The relation of reference relRef may be a relation already existing or simply the the vacuous relation defined on the product set of variables of interest.
the resulting extended bca.
Claude Boivin
G. Shafer and P. P. Shenoy. Local Computations in Hypertrees. School of Business, University of Kansas, Lawrence, KS, 1991. See p. 78, vacuous extension of a belief function.
# Making a vacuous reference relation and extending a DSM to its space. init_tt = matrix(rep(1,10),nrow = 1, dimnames = list(NULL, c("3", "2", "1", "0", "true", "false", "foul", "fair", "true", "false")) ) init_spec <- matrix(c(1,1), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) init_info <- matrix(c(3,4,7,8,4,2,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) relRef <- jointDSM(tt = init_tt, spec = init_spec, infovar = init_info, varnames = c("Sail", "Loading", "Weather", "Repairs"), relnb = 0) # a DSMspec defined on one variable l_rel <- DSM(tt = matrix(c(1,0,1,0,1,1), ncol = 2), m = c(0.3,0.5,0.2), cnames = c("true", "false"), infovar = matrix(c(4,2), ncol = 2, dimnames = list(NULL, c("varnb", "size"))), varnames = c("Loading"), inforel = matrix(c(7,1), ncol = 2, dimnames = list(NULL, c("relnb", "depth")))) z <- uproj(l_rel, relRef) prmatrix(t(z$tt), collab = rep("", nrow(z$tt)))# Making a vacuous reference relation and extending a DSM to its space. init_tt = matrix(rep(1,10),nrow = 1, dimnames = list(NULL, c("3", "2", "1", "0", "true", "false", "foul", "fair", "true", "false")) ) init_spec <- matrix(c(1,1), ncol = 2, dimnames = list(NULL, c("specnb", "mass"))) init_info <- matrix(c(3,4,7,8,4,2,2,2), ncol = 2, dimnames = list(NULL, c("varnb", "size")) ) relRef <- jointDSM(tt = init_tt, spec = init_spec, infovar = init_info, varnames = c("Sail", "Loading", "Weather", "Repairs"), relnb = 0) # a DSMspec defined on one variable l_rel <- DSM(tt = matrix(c(1,0,1,0,1,1), ncol = 2), m = c(0.3,0.5,0.2), cnames = c("true", "false"), infovar = matrix(c(4,2), ncol = 2, dimnames = list(NULL, c("varnb", "size"))), varnames = c("Loading"), inforel = matrix(c(7,1), ncol = 2, dimnames = list(NULL, c("relnb", "depth")))) z <- uproj(l_rel, relRef) prmatrix(t(z$tt), collab = rep("", nrow(z$tt)))