[R] library sets: A & EMPTY does not work; gset_intersection(A,EMPTY) works

Czerminski, Ryszard Ryszard.Czerminski at astrazeneca.com
Tue Apr 6 19:37:51 CEST 2010


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:ehlers at ucalgary.ca] 
Sent: Wednesday, March 31, 2010 2:03 PM
To: Czerminski, Ryszard
Cc: R-help at 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.899995]}
>> gset_intersection(A,B)
> {"c" [0.899995]}
>> 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:ehlers at ucalgary.ca]
> Sent: Wednesday, March 31, 2010 11:43 AM
> To: Czerminski, Ryszard
> Cc: R-help at 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_intersection(A,EMPTY) works: example
>>> code below
>>>
>>> Is it a bug?
>>>
>>> Best regards,
>>> Ryszard
>>>
>>> library(sets)
>>> support<- universe<- c('a','b','c','d')
>>> A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0),
>>> universe=universe)
>>> class(A)
>>> A
>>> E<- A - A # create empty set
>>> I<- gset_intersection(A, E) #<<<  this WORKS
>>> class(I); I
>>> I<- A&  E #<<<  this DOES NOT WORK
>>>
>>> # ---
>>>
>>>> support<- universe<- c('a','b','c','d')
>>>> A<- gset(support=support, memberships=c(0.2, 0.2, 0.9, 0),
>>> universe=universe)
>>>> class(A)
>>> [1] "gset" "cset"
>>>> A
>>> {"a" [0.2], "b" [0.2], "c" [0.9]}
>>>> E<- A - A
>>>> I<- gset_intersection(A, E) #<<<  this WORKS
>>>> class(I); I
>>> [1] "set" "gset" "cset"
>>> {}
>>>> I<- A&  E #<<<  this DOES NOT WORK
>>> Error in A&  E :
>>> operations are possible only for numeric or logical types
>>> In addition: Warning message:
>>> Incompatible methods ("Ops.gset", "Ops.set") for "&"
>>>
>>>
>>>
> ------------------------------------------------------------------------
> --
>>>
>>> Confidentiality Notice: This message is private and may
> ...{{dropped:8}}
>>>
>>> ______________________________________________
>>> R-help at 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.
>>>
>>>
>>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list