Re: [R] Fwd: NaN-result from fuzzy_inference (package "sets") with certain input
The problem is a numeric issue. As a quick (and dirty!) fix, you can use FUN <- matchfun(function(x,y) isTRUE(all.equal(x,y))) `%is%` <- function(x, y) cset_charfun(cset(x, matchfun = FUN))(y) before calling fuzzy_inference(). I will probably have to change the fuzzy stuff to csets with FUN as default matching function for fuzzy variables. Best David On 2013-05-10 09:49, Johannes Radinger wrote: Hi, @David: thank you for your fast response. I changed the universe to cover the at least the total range of the values in the dataframe. However, this does not save the problem for several combination of depth and velocity. I attached the same example as before but with a dataframe of such combinations that don't work. Is the problem caused by the definition of the membership classes? How can the problem bis solved? ## set universe sets_options("universe", seq(from = 0, to = 5, by = 0.001)) ## set up fuzzy variables variables <- set(depth = fuzzy_variable(verylow = fuzzy_trapezoid(corners = c(-3,0,0.2,0.5)), medium = fuzzy_trapezoid(corners =c(0.45,0.55,0.7,0.9)), veryhigh = fuzzy_trapezoid(corners = c(0.85,1,15,20))), velocity = fuzzy_variable(verylow = fuzzy_trapezoid(corners = c(-3,0,0.2,0.5)), medium = fuzzy_trapezoid(corners = c(0.35,0.55,0.65,0.8)), veryhigh = fuzzy_trapezoid(corners = c(0.7,0.9,15,20))), suitability = fuzzy_partition(varnames = c(none = 0.2, low = 0.4, medium = 0.6, high = 0.8),FUN = fuzzy_cone, radius = 0.2)) ## set up rules rules <- set( fuzzy_rule(depth %is% verylow && velocity %is% verylow, suitability %is% low), fuzzy_rule(depth %is% medium && velocity %is% verylow, suitability %is% medium), fuzzy_rule(depth %is% veryhigh && velocity %is% verylow, suitability %is% low), fuzzy_rule(depth %is% verylow && velocity %is% medium, suitability %is% medium), fuzzy_rule(depth %is% medium && velocity %is% medium, suitability %is% high), fuzzy_rule(depth %is% veryhigh && velocity %is% medium, suitability %is% medium), fuzzy_rule(depth %is% verylow && velocity %is% veryhigh, suitability %is% none), fuzzy_rule(depth %is% medium && velocity %is% veryhigh, suitability %is% low), fuzzy_rule(depth %is% veryhigh && velocity %is% veryhigh, suitability %is% none) ) ## combine to a system system <- fuzzy_system(variables, rules) print(system) plot(system) ## plots variables # test df test_df <- data.frame(depth=c(1.71,0.61,1.56,0.47,0.70,0.42,1.90),velocity=c(0.70,1.40,0.95,0.65,0.58,0.47,1.24),suitability=NA) # do inference on test_df fuzzy_result <- function(df){ gset_defuzzify(fuzzy_inference(system, list(depth = df["depth"], velocity = df["velocity"])),"centroid") } apply(test_df,1,fuzzy_result) /Johannes On Thu, May 9, 2013 at 12:35 AM, David Meyer mailto:david.me...@wu.ac.at>> wrote: It's because you restricted the universe to [0,1], so the fuzzy inference returns empty sets for those entries in your df with values larger than 1 ... David On 2013-05-08 14:53, Johannes Radinger wrote: This email has already been sent to the R-mailing list, but maybe you as the author of the package "sets" can help here best Hi, I am trying to use the fuzzy_inference system on multiple input values. Basically I combine two variables (depth, velocity) into the variable suitability. Both depth and velocity have 3 trapezoid classes (verylow,medium,high) each. The consequent (suitability) has 4 fuzzy levels (none,low,medium,high) and should finally range between 0 and 1. I already set up the level definitions (trapez-corners) and the rules (a combination of all depth-levels with all velocity-levels and the consequent suitability). Now I wanted to test the system on a dataframe with dummy variables (in the range of values I will supply), but some how I get for some combinations of depth and velocity no resulting suitablilty. I provide here now some code (simpler than my actual) that produces also this NaN values: # Load "sets" library(sets) ## set universe sets_options("universe", seq(from = 0, to = 1, by = 0.001)) ## set up fuzzy variables variables <- set(depth = fuzzy_variable(verylow = fuzzy_trapezoid(corners = c(-3,0,0.2,0.5)), medium = fuzzy_trapezoid(corners =c(0.45,0.55,0.7,0.9)),
Re: [R] color query in mosaic in package vcd
Thanks, fixed upstream. David On 2013-02-08 07:20, Achim Zeileis wrote: On Fri, 8 Feb 2013, Richard M. Heiberger wrote: require(vcd) mosaic(matrix(1:6, 2, 3), gp=gpar(fill=c("red","gray","blue")), main="three colors in each row") mosaic(matrix(1:3, 1, 3), gp=gpar(fill=c("red","gray","blue")), main="only one color in each row") I anticipated three colors in the second plot. My guess is that there is a matrix subscript without drop=FALSE somewhere on the inside of one of the functions. No, it's more subtle. If the dimension of the data (1, 3) is not the same as that of the fill (NULL), they are recycled along the last dimension (see Section 3 of vignette("strucplot", package = "vcd")). Thus supplying a suitable fill matrix works: mosaic(matrix(1:3, 1, 3), gp = gpar(fill=matrix(c("red","gray","blue"), 1, 3))) David: The reason why Rich's original code does not work properly is that the recycling is not triggered properly. In line 160 of strucplot.R we check if(length(par) < size) which is not the case here and hence the dimension is not added. I think we could do if (length(par) < size | is.null(dim(par))) aperm(array(par, dim = rev(d))) else par That fixes the problem. Best, Z This is with Package: vcd Version: 1.2-13 Date: 2012-02-19 on version.string R Under development (unstable) (2013-02-02 r61822) platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Priv.-Doz. Dr. David Meyer Department of Information Systems and Operations WU Wirtschaftsuniversität Wien Vienna University of Economics and Business Augasse 2-6, 1090 Vienna, Austria Tel: +43-1-313-36-4393 Fax: +43-1-313-36-90-4393 HP: http://ec.wu.ac.at/~meyer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] standardized residuals / adjusted residuals
If I call chisq.test(x)$residuals ; I get the *standardized* residuals (even though it's called residuals) chisq.test(x)$stdres ; I get the *adjusted* standardized residuals (even though it's called stdres) Is this correct? I think, yes - as documented on the man page. Best David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write.matrix.csr data conversion
Dear Sam, there is C-code related to *reading* in such a file, but in the internal libsvm-format, not the matrix.csr format. There is no C-code for *writing* this to a file. There is certainly a way to speed this up, but I am not likely to do this in the near future. Best David On 2012-11-06 19:15, Sam Steingold wrote: David, thanks for adding the feature. read.matrix.csr and, especially, write.matrix.csr are extremely slow: usersystem elapsed 8381.988 3810.396 12345.349 for a 2797634 x 224 matrix I have to deal with. The help page http://rss.acs.unt.edu/Rdoc/library/e1071/html/read.matrix.csr.html says David Meyer (based on C/C++-code by Chih-Chung Chang and Chih-Jen Lin) is there any chance that you might consider replacing the R code with the original C/C++? Thanks a lot! * David Meyer [2012-08-27 22:57:17 +0200]: done, thanks for the suggestion. David On 2012-08-27 21:15, Sam Steingold wrote: * jim holtman [2012-08-27 14:55:08 -0400]: Most likely when 'y' is converted to a dataframe (not sure what the function 'write.matrix.csr' does since you did not say where you got it), sorry, library(e1071) '0' and '1' are converted to factors which probably show up as 1 and 2 in the file. sounds reasonable, thanks. David, could you please add an option `fac' to `write.matrix.csr', similar to `read.matrix.csr' which already accepts `fac'? thanks! -- Priv.-Doz. Dr. David Meyer Institut für Wirtschaftsinformatik Fachhochschule Technikum Wien Höchstädtplatz 5, 1200 Wien T: +43 1 333 40 77-394 F: +43 1 333 40 77-99 394 E: david.me...@technikum-wien.at I: www.technikum-wien.at __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot - bclust
These are warnings and I think that you can safely ignore them. It looks like the code should replace the line if (x$datamean) with something like if (!is.null(x$datamean)) Yes, I think so too - thanks for reporting this. David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write.matrix.csr data conversion
Yes, it seems that Prof Meyer hasn't pushed the changes to R forge yet. I now did. (There are no other repositories). David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write.matrix.csr data conversion
done, thanks for the suggestion. David On 2012-08-27 21:15, Sam Steingold wrote: * jim holtman [2012-08-27 14:55:08 -0400]: Most likely when 'y' is converted to a dataframe (not sure what the function 'write.matrix.csr' does since you did not say where you got it), sorry, library(e1071) '0' and '1' are converted to factors which probably show up as 1 and 2 in the file. sounds reasonable, thanks. David, could you please add an option `fac' to `write.matrix.csr', similar to `read.matrix.csr' which already accepts `fac'? thanks! -- Priv.-Doz. Dr. David Meyer Department of Information Systems and Operations WU Wirtschaftsuniversität Wien Vienna University of Economics and Business Augasse 2-6, 1090 Vienna, Austria Tel: +43-1-313-36-4393 Fax: +43-1-313-36-90-4393 HP: http://ec.wu.ac.at/~meyer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SparseM buglet
Thanks to all for routing this to me - fixed upstream. David Original Message Subject: forwarded message from Roger Koenker Date: Sat, 25 Aug 2012 17:12:04 +0200 From: Kurt Hornik Reply-To: kurt.hor...@wu.ac.at To: David Meyer --- Begin Message --- Sam, Thanks for pointing this out, but I have to point out in turn that this isn't a SparseM function, it is part of the package e1071, maintained by David Meyer. Roger Roger Koenker rkoen...@illinois.edu On Aug 24, 2012, at 3:07 PM, Sam Steingold wrote: > read.matrix.csr does not close the connection: > >> library('SparseM') > Package SparseM (0.96) loaded. >> read.matrix.csr(foo) > ... > Warning message: > closing unused connection 3 (foo) >> > > > -- > Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X > 11.0.11103000 > http://www.childpsy.net/ http://truepeace.org http://camera.org > http://pmw.org.il http://think-israel.org http://dhimmi.com > My other CAR is a CDR. --- End Message --- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict.naiveBayes() bug in e1071 package
Confirmed & fixed upstream. Thanks, David On 2012-02-07 18:43, Ali Tofigh wrote: Hi, I'm currently using the R package e1071 to train naive bayes classifiers and came across a bug: When the posterior probabilities of all classes are small, the result from the predict.naiveBayes function become NaNs. This is an issue with the treatment of the log-transformed probabilities inside the predict.naiveBayes function. Here is an example to demonstrate the problem (you might need to increase 'nvar' depending on your machine): 8< N<- 100 nvar<- 60 varnames<- paste("v", 1:nvar, sep="") dat<- sapply(1:nvar, function(dummy) {c(rnorm(N/2, 0, 1), rnorm(N/2, 10, 1))}) colnames(dat)<- varnames out<- rep(c("a","b"), each=N/2) names(dat)<- varnames nb<- naiveBayes(x=dat, y=out) new.dat<- t(rnorm(nvar, 5, 0.1)) colnames(new.dat)<- varnames predict(nb, new.dat, type="raw") 8< the results of the last line is usually NaNs. As for the solution: To protect agains very small numbers, the e1071:::predict.naiveBayes function takes the probabilities into log-space and adds instead of multiplying probabilities. However, when calculating the posterior probabilities of each class (when type = "raw"), the log of the probabilities are exponentiated, which defeats the purpose of the logspace transformation. I suggest the following change to the code: Towards the end of the predict.naiveBayes function, you currently do: L<- exp(L) L / sum(L) # this is what is returned you can instead use sapply(L, function(lp) {1 / sum(exp(L - lp))}) the above comes from the following equality: x / (x + y + z) = 1 / (1 + exp(log(y) - log(x)) + exp(log(z) - log(x))) Best wishes, /Ali Tofigh -- Priv.-Doz. Dr. David Meyer Department of Information Systems and Operations WU Wirtschaftsuniversität Wien Vienna University of Economics and Business Augasse 2-6, 1090 Vienna, Austria Tel: +43-1-313-36-4393 Fax: +43-1-313-36-90-4393 HP: http://ec.wu.ac.at/~meyer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] The "Sets" package and element equality test
By going through the code, I came to a similar conclusion also: it seems the match.2.list function must be modified in the following way to make it work: match.2.list <- function(l1,l2){ if (class(l1)=="element"){ l1 <- l1[[1]] l2 <- l2[[1]] } length(l1)==length(l2) } because depending whether it is called from the constructor or from the %e% function, the assumptions about the input types are not the same. No, this is not not the problem, it's really the hashing code which makes this fail. If you turn hashing off, then the original match.2.list function will work as expected: > sets_options("hash", FALSE) > match.2.list <- function(l1,l2){ + length(l1)==length(l2) + } > s <- set(list(1,2),list(3,4)) > lset <- cset(s,matchfun = matchfun(match.2.list)) > lset {<>} > list(1,8) %e% lset [1] TRUE And also, if instead of working with "standard" objects, I want to work with S4 / refClass objects, I cannot build cset objects, because I have to go first with the set construction which prompts an error: Currently, S4 objects are not supported at all as set elements. I will have a look on this. Best David Error in as.vector(x, "character") : cannot coerce type 'environment' to vector of type 'character' So far, I don't know how to work around this latter issue. Thanks again for the package and your help. Regards Johnny On Sat, Oct 8, 2011 at 2:40 PM, David Meyer <mailto:mey...@technikum-wien.at>> wrote: Dear Johnny, this is a bug in the hashing-code of sets. Use: sets_options("hash", FALSE) lset <- cset(s, matchfun = matchfun(match.2.list)) which will work. Thanks for pointing this out! David Hi, I tried to use the sets package yesterday, which seems to be a very powerful package: thanks to the developers. I wanted to define sets of lists where 2 lists are considered equal if they have the same length. So, I implemented: match.2.list <- function(l1,l2){ length(l1)==length(l2) } and then defined my cset as: s <- set(list(1,2),list(3,4)) lset <- cset(s,matchfun(match.2.list)) so if I now do: y <- list(3,4) y %e% lset I get the correct answer, which is TRUE. But if I do: x <- list(1,8) x %e% lset I now get FALSE, even though x is a list of length 2, and should thus match any of the 2 lists in lset. I must be doing something wrong; I checked with the doc, but I don't understand. -- Priv.-Doz. Dr. David Meyer Institut für Wirtschaftsinformatik Fachhochschule Technikum Wien Höchstädtplatz 5, 1200 Wien T: +43 1 333 40 77-394 F: +43 1 333 40 77-99 394 E: david.me...@technikum-wien.at <mailto:david.me...@technikum-wien.at> I: www.technikum-wien.at <http://www.technikum-wien.at> -- Priv.-Doz. Dr. David Meyer Institut für Wirtschaftsinformatik Fachhochschule Technikum Wien Höchstädtplatz 5, 1200 Wien T: +43 1 333 40 77-394 F: +43 1 333 40 77-99 394 E: david.me...@technikum-wien.at I: www.technikum-wien.at __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] The "Sets" package and element equality test
Dear Johnny, this is a bug in the hashing-code of sets. Use: sets_options("hash", FALSE) lset <- cset(s, matchfun = matchfun(match.2.list)) which will work. Thanks for pointing this out! David Hi, I tried to use the sets package yesterday, which seems to be a very powerful package: thanks to the developers. I wanted to define sets of lists where 2 lists are considered equal if they have the same length. So, I implemented: match.2.list <- function(l1,l2){ length(l1)==length(l2) } and then defined my cset as: s <- set(list(1,2),list(3,4)) lset <- cset(s,matchfun(match.2.list)) so if I now do: y <- list(3,4) y %e% lset I get the correct answer, which is TRUE. But if I do: x <- list(1,8) x %e% lset I now get FALSE, even though x is a list of length 2, and should thus match any of the 2 lists in lset. I must be doing something wrong; I checked with the doc, but I don't understand. -- Priv.-Doz. Dr. David Meyer Institut für Wirtschaftsinformatik Fachhochschule Technikum Wien Höchstädtplatz 5, 1200 Wien T: +43 1 333 40 77-394 F: +43 1 333 40 77-99 394 E: david.me...@technikum-wien.at I: www.technikum-wien.at __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] probabilities in svm output in e1071 package
Dear Changbin, that looks odd indeed - can you cast your example in a reproducible one so I can track this down (or at least send me the data offline?) Thanks David Changbin Du wrote: svm.fit<-svm(as.factor(out) ~ ., data=all_h, method="C-classification", kernel="radial", cost=bestc, gamma=bestg, cross=10) # model fitting svm.pred<-predict(svm.fit, hh, decision.values = TRUE, probability = TRUE) # find the probability, but can not find. attr(svm.pred, "probabilities") > attr(svm.pred, "probabilities") 1 0 10 0 20 0 30 0 50 0 60 0 70 0 80 0 90 0 Hi, Dear R community, IN my data, the out variable is the target variable (0, and 1), hh is the new data set does not contain the out variable. I trained the model svm.fit in training data. And want to predict the out in the new data set hh. WHy the probabilities are both 0 in 1 and 0 class? -- Sincerely, Changbin -- Changbin Du DOE Joint Genome Institute Bldg 400 Rm 457 2800 Mitchell Dr Walnut Creet, CA 94598 Phone: 925-927-2856 -- Priv.-Doz. Dr. David Meyer Department of Information Systems and Operations WU Wirtschaftsuniversität Wien Vienna University of Economics and Business Augasse 2-6, 1090 Vienna, Austria Tel: +43-1-313-36-4393 Fax: +43-1-313-36-90-4393 HP: http://ec.wu.ac.at/~meyer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works
Peter, Ryszard, I just put a new version on CRAN (1.0-6) which fixes the problem occuring with operators and mixed classes, so, e.g., > gset(1,2) & set() {} now works. I also made sure that X == X is always TRUE, and fixed the all.equal-bug: > gset(1, 0.5 - 0.3) == gset(1, 0.3 - 0.1) [1] FALSE > all.equal(gset(1, 0.5 - 0.3), gset(1, 0.3 - 0.1)) [1] TRUE Best David Czerminski, Ryszard wrote: Hi Peter, This looks like another one: "gset_is_equal(X,X)" and "X == X" evaluate to FALSE ? uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) s {"a" [0.0811552], "b" [0.3552998], "c" [0.996772]} gset_is_equal(s, s) [1] FALSE s == s [1] FALSE class(s) [1] "gset" "cset" Best regards, Ryszard -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 2:03 PM To: Czerminski, Ryszard Cc: R-help@r-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works Ryszard, You've made me take a closer look and now I do think that you've found a bug. After a quick look at the package vignette, I see that the authors have indeed overloaded "&" and so it should work for your example. The problem seems to be the order of the class attribute which is used to call the relevant 'Ops' function: class(A) #[1] "gset" "cset" class(B) #[1] "gset" "cset" class(E <- A - A) #[1] "set" "gset" "cset" If you re-order the class vector, function Ops.gset will be called to handle A and E: class(E) <- class(E)[c(2,3,1)] A & E #{} I've cc'd David Meyer. -Peter Ehlers On 2010-03-31 10:11, Czerminski, Ryszard wrote: It seems that "A& B" works the same way as "gset_intersection(A,B)" as long as A and B are not empty... see below: fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A B A& B gset_intersection(A,B) E<- A - A A& E gset_intersection(A,E) fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A {"a" [0.2], "b" [0.2], "c" [0.9]} B {"a" [0.211], "b" [0.222], "c" [0.999]} A& B {"c" [0.85]} gset_intersection(A,B) {"c" [0.85]} E<- A - A A& E Error in A& E : operations are possible only for numeric or logical types In addition: Warning message: Incompatible methods ("Ops.gset", "Ops.set") for "&" gset_intersection(A,E) {} -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 11:43 AM To: Czerminski, Ryszard Cc: R-help@r-project.org Subject: Re: [R] library sets: A& EMPTY does not work; gset_intersection(A,EMPTY) works On 2010-03-31 9:30, Peter Ehlers wrote: Unless I'm missing something, I don't see any method in pkg:sets for intersection other than gset_intersection. Whoops, a bit quick on the draw. There are of course also set_intersection and cset_intersection, but not AFAICS any method for `&`. -Peter Ehlers So you're using the base R function `&` whose help page tells you that its arguments should be vectors. Yours aren't. -Peter Ehlers On 2010-03-31 8:50, Czerminski, Ryszard wrote: When using generalized sets from "sets" library A& EMPTY does not work, but gset_i
Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works
Apparently memberships values are identical, tags of set members are identical (letters), but "q == q" still generates FALSE... The equality method for gsets performs some computations which might yield these results in case of numeric problems. As I wrote, I will think about using all.equal by default to avoid these confusions (and in particular to make sure that x == x gives always TRUE). David Best regards, Ryszard p <- runif(length(letters)) q <- gset(letters, p) summary(p == p) # gives all TRUE values, but q == q # gives FALSE summary(p == gset_memberships(q)) # and this gives all TRUE values p <- runif(length(letters)) q <- gset(letters, p) summary(p == p) # gives all TRUE values, but ModeTRUE logical 26 q == q # gives FALSE [1] FALSE summary(p == gset_memberships(q)) # and this gives all TRUE values ModeTRUE logical 26 -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: David Meyer [mailto:david.me...@wu.ac.at] Sent: Wednesday, April 07, 2010 8:25 AM To: Czerminski, Ryszard Cc: Peter Ehlers; R-help@R-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works This is rather by chance due to numeric instabilities, I think: It looks like something else is going on in addition to potential problem with numerical instabilities: p <- runif(length(letters)) q <- gset(letters, p) all.equal(p,p) all.equal(q,q) q == q p <- runif(length(letters)) q <- gset(letters, p) all.equal(p,p) [1] TRUE all.equal(q,q) [1] "target and current have different memberships" q == q [1] FALSE On my system: > p <- runif(length(letters)) > q <- gset(letters, p) > all.equal(p,p) [1] TRUE > all.equal(q,q) [1] TRUE > q == q [1] TRUE This is the same problem, since the all.equal-method for gsets does not use all.equal internally (which *is* a bug, of course!). Will be fixed ASAP ... Thanks David -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: David Meyer [mailto:david.me...@wu.ac.at] Sent: Tuesday, April 06, 2010 6:03 PM To: Czerminski, Ryszard Cc: Peter Ehlers; R-help@R-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works This is rather by chance due to numeric instabilities, I think: > uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) > s {"a" [0.7533966], "b" [0.968067], "c" [0.2494876]} > s == s [1] TRUE > gset_is_equal(s,s) [1] TRUE But using all.equal instead of `==` for the memberships might by a good idea, I will have a look at it. Thanks David Czerminski, Ryszard wrote: Hi Peter, This looks like another one: "gset_is_equal(X,X)" and "X == X" evaluate to FALSE ? uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) s {"a" [0.0811552], "b" [0.3552998], "c" [0.996772]} gset_is_equal(s, s) [1] FALSE s == s [1] FALSE class(s) [1] "gset" "cset" Best regards, Ryszard -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 2:03 PM To: Czerminski, Ryszard Cc: R-help@r-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works Ryszard, You've made me take a closer look and now I do think that you've found a bug. After a quick look at the package vignette, I see that the authors have indeed overl
Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works
This is rather by chance due to numeric instabilities, I think: It looks like something else is going on in addition to potential problem with numerical instabilities: p <- runif(length(letters)) q <- gset(letters, p) all.equal(p,p) all.equal(q,q) q == q p <- runif(length(letters)) q <- gset(letters, p) all.equal(p,p) [1] TRUE all.equal(q,q) [1] "target and current have different memberships" q == q [1] FALSE On my system: > p <- runif(length(letters)) > q <- gset(letters, p) > all.equal(p,p) [1] TRUE > all.equal(q,q) [1] TRUE > q == q [1] TRUE This is the same problem, since the all.equal-method for gsets does not use all.equal internally (which *is* a bug, of course!). Will be fixed ASAP ... Thanks David -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: David Meyer [mailto:david.me...@wu.ac.at] Sent: Tuesday, April 06, 2010 6:03 PM To: Czerminski, Ryszard Cc: Peter Ehlers; R-help@R-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works This is rather by chance due to numeric instabilities, I think: > uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) > s {"a" [0.7533966], "b" [0.968067], "c" [0.2494876]} > s == s [1] TRUE > gset_is_equal(s,s) [1] TRUE But using all.equal instead of `==` for the memberships might by a good idea, I will have a look at it. Thanks David Czerminski, Ryszard wrote: Hi Peter, This looks like another one: "gset_is_equal(X,X)" and "X == X" evaluate to FALSE ? uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) s {"a" [0.0811552], "b" [0.3552998], "c" [0.996772]} gset_is_equal(s, s) [1] FALSE s == s [1] FALSE class(s) [1] "gset" "cset" Best regards, Ryszard -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 2:03 PM To: Czerminski, Ryszard Cc: R-help@r-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works Ryszard, You've made me take a closer look and now I do think that you've found a bug. After a quick look at the package vignette, I see that the authors have indeed overloaded "&" and so it should work for your example. The problem seems to be the order of the class attribute which is used to call the relevant 'Ops' function: class(A) #[1] "gset" "cset" class(B) #[1] "gset" "cset" class(E <- A - A) #[1] "set" "gset" "cset" If you re-order the class vector, function Ops.gset will be called to handle A and E: class(E) <- class(E)[c(2,3,1)] A & E #{} I've cc'd David Meyer. -Peter Ehlers On 2010-03-31 10:11, Czerminski, Ryszard wrote: It seems that "A& B" works the same way as "gset_intersection(A,B)" as long as A and B are not empty... see below: fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A B A& B gset_intersection(A,B) E<- A - A A& E gset_intersection(A,E) fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A {"a" [0.2], "b" [0.2], "c" [0.9]} B {"a" [0.211], "b" [0.222], "c" [0.999]} A& B {"c" [0.85]} gset_intersection(A,B) {"c" [0.85]} E<- A - A A& E
Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works
This is rather by chance due to numeric instabilities, I think: > uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) > s {"a" [0.7533966], "b" [0.968067], "c" [0.2494876]} > s == s [1] TRUE > gset_is_equal(s,s) [1] TRUE But using all.equal instead of `==` for the memberships might by a good idea, I will have a look at it. Thanks David Czerminski, Ryszard wrote: Hi Peter, This looks like another one: "gset_is_equal(X,X)" and "X == X" evaluate to FALSE ? uv <- c('a', 'b', 'c'); s <- gset(uv, runif(length(uv))) s {"a" [0.0811552], "b" [0.3552998], "c" [0.996772]} gset_is_equal(s, s) [1] FALSE s == s [1] FALSE class(s) [1] "gset" "cset" Best regards, Ryszard -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 2:03 PM To: Czerminski, Ryszard Cc: R-help@r-project.org; David Meyer Subject: Re: [R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works Ryszard, You've made me take a closer look and now I do think that you've found a bug. After a quick look at the package vignette, I see that the authors have indeed overloaded "&" and so it should work for your example. The problem seems to be the order of the class attribute which is used to call the relevant 'Ops' function: class(A) #[1] "gset" "cset" class(B) #[1] "gset" "cset" class(E <- A - A) #[1] "set" "gset" "cset" If you re-order the class vector, function Ops.gset will be called to handle A and E: class(E) <- class(E)[c(2,3,1)] A & E #{} I've cc'd David Meyer. -Peter Ehlers On 2010-03-31 10:11, Czerminski, Ryszard wrote: It seems that "A& B" works the same way as "gset_intersection(A,B)" as long as A and B are not empty... see below: fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A B A& B gset_intersection(A,B) E<- A - A A& E gset_intersection(A,E) fuzzy_logic("Yager", p=2) support<- universe<- c('a','b','c','d') A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0), universe=universe) B<- gset(support=support, memberships=c(0.211, 0.222, 0.999, 0), universe=universe) A {"a" [0.2], "b" [0.2], "c" [0.9]} B {"a" [0.211], "b" [0.222], "c" [0.999]} A& B {"c" [0.85]} gset_intersection(A,B) {"c" [0.85]} E<- A - A A& E Error in A& E : operations are possible only for numeric or logical types In addition: Warning message: Incompatible methods ("Ops.gset", "Ops.set") for "&" gset_intersection(A,E) {} -- Confidentiality Notice: This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful. -Original Message- From: Peter Ehlers [mailto:ehl...@ucalgary.ca] Sent: Wednesday, March 31, 2010 11:43 AM To: Czerminski, Ryszard Cc: R-help@r-project.org Subject: Re: [R] library sets: A& EMPTY does not work; gset_intersection(A,EMPTY) works On 2010-03-31 9:30, Peter Ehlers wrote: Unless I'm missing something, I don't see any method in pkg:sets for intersection other than gset_intersection. Whoops, a bit quick on the draw. There are of course also set_intersection and cset_intersection, but not AFAICS any method for `&`. -Peter Ehlers So you're using the base R function `&` whose help page tells you that its arguments should be vectors. Yours aren't. -Peter Ehlers On 2010-03-31 8:50, Czerminski, Ryszard wrote: When using generalized sets from "sets" library A&
Re: [R] nu-SVM crashes in e1071
For the records: this was a bug in e1071 (which is already fixed & new version on CRAN). Best David Steve Lianoglou wrote: Hi, On Wed, Mar 3, 2010 at 4:08 AM, Häring, Tim (LWF) wrote: (...) While you're sending your bug report to David, perhaps you can try the SVM from kernlab. It relies on code from libsvm, too, but ... you never know. It can't hurt to try. Hi Steve, thanks for that hint. I tried ksvm()-function bet get an error message: model <- ksvm(soil_unit~., train, type="nu-svc") Using automatic sigma estimation (sigest) for RBF or laplace kernel Error in votematrix[i, ret < 0] <- votematrix[i, ret < 0] + 1 : NAs are not allowed in subscripted assignments But there are no NAs in my dataset. I checked it with summary(is.na(train)) All the same, it seems there might be something funky with your data? Not sure how to help debug further. If you like you send an *.rda file of your soil_unit data offline and I can try, but otherwise I guess you're on your own? What if you remove some of the columns of your matrix? Will this eventually work? -steve -- Priv.-Doz. Dr. David Meyer Department of Information Systems and Operations WU Wirtschaftsuniversität Wien Vienna University of Economics and Business Augasse 2-6, 1090 Vienna, Austria Tel: +43-1-313-36-4393 Fax: +43-1-313-36-90-4393 HP: http://ec.wu.ac.at/~meyer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiclass SVM (e1071 package): number of estimated models
Dear John, there *are* indeed 3 classifiers trained, as you can see from predict(model, iris, decision.values = TRUE) However, the coefficients are stored in a compressed format -- see svminternals.txt in the /doc subdirectory. Best David - I run multiclass SVM for iris data, which contains 3 classes (manual page 52). Based on manual, the implementation uses one-against-one approach: k*(k-1)/2 binary classifiers trained. However, I am getting only two models instead of three (only two columns of support vectors and coefficients). What do I miss? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to get the signed distance in SVM?
Dear Qing, look at the file "svminternals.txt" in the /doc subdirectory of the installed e1071 package (or inst/doc in the source package), that should help. David > > In the svm() function in the package e1071, is there anyway to get the > signed distance of a sample point to the separating hyperplane in the > feature space? Namely, if the separating hyperplane is given by f(x) = > h(x)^T * w - rho, is there any way to get f(x)? > > Also, in the returned values of the function svm(), what does "$coefs" > mean? It is said to be the "corresponding coefficients times the > training labels", but I don't know what is that "corresponding > coefficients" denoting? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write.matrix.csr(e1071) bug
Peter: Yes, this is a bug. The line if ([EMAIL PROTECTED] <= nrow(x)) should actually read if (([EMAIL PROTECTED] <= length([EMAIL PROTECTED])) && ([EMAIL PROTECTED] < [EMAIL PROTECTED] + 1])) --> fixed upstream. Thanks David Hello, The write.matrix.csr() function of the e1071 package contains a bug. Try the following: library(e1071) m <- 1 - diag(10) sm <- as.matrix.csr(m) write.matrix.csr(sm) The resulting file (out.dat) contains only the two lines below: 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 1:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 This is obviously wrong as the matrix m has 90 non-zero entries. The function is implemented as write.matrix.csr <- function (x, file="out.dat", y=NULL) { on.exit(sink()) if(!require("methods")) stop("Could not load package 'methods'.") if (!is.null(y) & (length(y) != nrow(x))) stop(paste("Length of y (=", length(y), ") does not match number of rows of x (=", nrow(x), ")!", sep="")) sink(file) for (i in 1:nrow(x)) { if (!is.null(y)) cat (y[i],"") if ([EMAIL PROTECTED] <= nrow(x)) for (j in [EMAIL PROTECTED]:([EMAIL PROTECTED] - 1)) cat([EMAIL PROTECTED], ":", [EMAIL PROTECTED], " ", sep="") cat("\n") } } The bug is caused by the line if ([EMAIL PROTECTED] <= nrow(x)) that is completely meaningless. In the above example nrow(x) is 10 and [EMAIL PROTECTED] is the vector 1 10 19 28 37 46 55 64 73 82 91 Entries of [EMAIL PROTECTED] has nothing to do with the number of rows in the matrix. To fix the bug this line must be removed. Best regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] adjusting textsize and spacing in mosaic (vcd package)
Richard, > How do I change the size of the text on the legend scale? This should work with `fontsize', but doesn't which is a bug (fixed in the next release). > Also, is there a way to change all the font sizes at once? Not yet, but this is a good suggestion. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extract naiveBayes details
Stephan: the Naive Bayes model consists of several tables, one for each (categorical) predictor. Using m = naiveBayes( ... ) m$tables you will get (as the help page says): tables: A list of tables, one for each predictor variable. For each categorical variable a table giving, for each attribute level, the conditional probabilities given the target class. Best David I just like to know how to extract details from the naiveBayes model (package e1071). I mean, for each possible value the model defines how much it influences the outcome. I want to sort those probabilities and show the values with the highest impact. How could I do that? PS: I tried using []'s to get to the model's internals, however, all I get is a "list" not a "matrix" I could work with. What am I doing wrong? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot error
Pedros: if you have more than two explanatory variables, the plot.svm() function plots a slice out of the input space, i.e., you have to specify the two variables that are plot on the x and y axis. The example on the help page tells you how: plot(model, data= dados[,-1], formula=dados[,2]~dados[,3]) should work, choosing all other coordinates except the 2nd and 3rd to be 0 (default). Best David -- > I'm trying to plot an svm model and I'm the following error: > > >> > > plot(model, data= dados[,-1], formula=formula(dados[,2]~dados[, > > 3]),svSymbol = 1, dataSymbol = 2, symbolPalette = rainbow(4),color. > > palette = terrain.colors) > > Error in terms.default(x) : no terms component > > > > Anyone knows how to solve this??? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems in cross validation of SVM in pakage "e1071"
Dear Nan Qiao, the accuracies are in percent (so times 100). Best David Hi: I am a newer in using R for data mining, and find the "e1071" pakage an excellent tool in doing data mining work! what frustrated me recently is that when I using the function "svm" and using the "cross=10" parameters, I got all the "accuracies" of the model greater than 1. Isn't that the accuracy should be smaller than 1? so I wander how, the accuracy of the cross validation is calculated, and what's the meaning of the accuracy? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] upgrade: relations
Dear useRs, a new version of the 'relations' package has appeared on CRAN. New features include: o support for fuzzy relations added o support for sets moved to separate 'sets' package o new SD fitters for the S ("symmetric") and M ("matches") families o fitters for Cook-Seiford method and Euclidean consensus added o fitters can now use a sparse constraint matrix representation o relations are now subsettable o relation_choice() for choosing "winner" objects based on an ensemble of relations between these o new summary method for relations which computes all implemented predicates Best, David and Kurt. ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] New package: sets
Dear useRs, The new 'sets' package made it to CRAN, supporting: o data structures for sets, fuzzy sets, multisets, and fuzzy multisets o the use of (most) R objects as elements o standard set operations (union, intersection, complement, Cartesian product, power set, ...) o support for several fuzzy logic systems An introductory vignette is also available. David and Kurt. ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fontsize in mosaic plot lables
Herry, mosaic() by default uses the labeling_border() workhorse, which gives you the choice of modifying either gp_labels or gp_varnames. So just replacing gp_text by gp_labels shoud do the trick. Best David -- Hi List, I am trying unsucessfully to modify the fontsize of lables in mosaic: require(vcd) mosaic(Titanic, pop=FALSE, labeling_args=list(rot_labels=c(bottom=90,top=90), set_varnames = c(Sex = "Gender"), gp_text=gpar(fontsize=20))) #can't get it to resize text tab <- ifelse(Titanic < 6, NA, Titanic) # it works for labeling_cells labeling_cells(text = tab, margin = 0,gp_text=gpar(fontsize=20))(Titanic) What am I doing wrong? Thanx Herry -- Dr. David Meyer Department of Information Systems and Operations Vienna University of Economics and Business Administration Augasse 2-6, A-1090 Wien, Austria, Europe Tel: +43-1-313 36 4393 Fax: +43-1-313 36 90 4393 HP: http://wi.wu-wien.ac.at/~meyer/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.