xoopr / set6 Goto Github PK
View Code? Open in Web Editor NEWR6 object-oriented interface for mathematical sets.
Home Page: https://xoopR.github.io/set6/
License: Other
R6 object-oriented interface for mathematical sets.
Home Page: https://xoopR.github.io/set6/
License: Other
From SpecialSets -> Interval to SpecialSets -> Set; then just inherit each method as required. Alternatively could remove the SpecialSet class altogether and instead just have listSpecialSets
and manually add to this, also family
tag in roxygen. Then special intervals can inherit from Interval
or otherwise from Set
, this is probably the cleanest way.
As there are no setters, all getters can either be public methods or active bindings that don't set anything,
e.g.
Set$new(1,2,3)$elements()
Or
Set$new(1,2,3)$elements
The latter seems to imply that it is settable when it isn't
There is ambiguity in these so strictly it may not be a bug but then the documentation needs to make this clear. The current union and intersection methods inherit from Set
. However more standard operators are as follows.
Union:
m_U(x) = max(m_A(x), m_B(x))
Intersection:
m_I(x) = min(m_A(x), m_B(x))
For fuzzy sets A, B, with respective membership functions m_A, m_B
Copied from email to Franz
Quick follow up question about product sets, it seems to me that if you take the product of a product then you result in a set containing tuples of tuples and sets, so by example:
{1, 2} * {1,2} = {(1,1), (1,2), (2,1), (2,2)}
{(1,1), (1,2), (2,1), (2,2)} * {1,2} = {((1,1),1), ((1,1),2), ((1,2),1), ((1,2),2),….,}
However this seems counterintuitive to me as this then means that (1, 1, 1) is not in {1, 2}^3 but ((1, 1), 1) is, which are not the same!
Have I missed a property of sets/tuples? Or just overlooking something in the Cartesian product?
May also work better as dispatch. $simplify
would detect if the SetWrapper
can instead be represented as a Set
of finite elements, and if so converts to this. Some sensible initial checks would be to check cardinality.
A first iteration can be easily implemented by just calling the wrapper again but with the simplify
option. e.g. for a ExponentSet
if(self$countability = "countably finite")
setpower(self$wrappedSet, self$power, simplify = TRUE)
This is for openjournals/joss-reviews#2598.
Sorry to open a non-specific issue, but that seemed to make the most sense in this case (these individual questions didn't seem to deserve their own issues).
Is there a plan to implement $isSubset
for union sets? Borrowing from one of the examples:
a <- Set$new(1, 2, 3)
b <- Interval$new(1, Inf)
c <- b - a
c$print()
#> (1,2) ∪ (2,3) ∪ (3,+∞]
c$isSubset(Set$new(1))
#> isSubset currently not implemented for this wrapper.
Also, some small typos in the paper. It has:
> c$print()
(1,2) U (2,3) U (3,+Inf]
But it the output is now:
(1,2) ∪ (2,3) ∪ (3,+∞]
It looks like the union symbols and infinity symbol are different from the current code compared to what's in the paper.
Update: I just noticed that the output of other code examples has similar inconsistencies -- the output when I run it has special mathematical symbols, but the output in the paper does not.
It is unclear how to treat subsets of intervals. Intervals are ordered sets, and therefore the following should hold
Set$new(1,2,3) < Integers$new()
Set$new(2,1,3) !< Integers$new()
However, as Interval
inherits from Sets
and not Tuples
, this is incorrect. Moreover by doing this we then can't exploit results for unions and complements.
I am currently leaning towards keeping them how they are, i.e. programmed as inheriting from Set
but acknowledging in the documentation that this isn't strictly mathematically true.
@fkiraly?
By example for a set S
:
Option 1:
S$liesInSet(Set$new(1,2), Set$new(2,3), all = TRUE))
Option 2:
S$liesInSet(list(Set$new(1,2), Set$new(2,3)), TRUE))
Option 1 is slightly more user friendly and mitigates against annoyingly problems with R6 objects incorrectly behaving like lists. But distr6
uses option 2 and I think this is because we found potential problems in the first option (although I can't remember what these were)
Currently set operator names copy the names of base, i.e. union, intersect, setdiff
(although setequal
-> equal
). Whilst the user will get a message saying these are masked on loading of set6
this is not actually true as I have used S3 dispatch to call the base
functions if the objects are not R6 classes, i.e. in pseudo-code
union = function(x, y){
if(!inherit(x, "R6"))
base::union(x, y)
else
UseMethod("union")
}
Despite this, is it still better to re-name operations to something like union -> setunion
(although setsetdiff
may look strange)
This is a high priority so we can finish abstraction of set6 from distr6.
x = sample(1000)
y = sample(1000)
sx = Set$new(x)
sy = Set$new(y)
microbenchmark::microbenchmark(
setdiff(x, y),
sx - sy,
unit = "s"
)
Gives a mean time in seconds of:
setdiff(x,y) = 4.681405e-05
sx - sy = 1.639163e-02
A considerable difference. The additional bloat is due to a lot of checks that sort through the correct dispatch methods and use tricks for other more complicated set types. Some overhead is unavoidable but perhaps the quickest fix is to add a conditional at the start of each set operation that tests if both objects are sets or tuples, and if true, then calls the base functions. Note that this overhead is required for more complicated classes.
Soft sets - general framework for deal with uncertanities https://en.wikipedia.org/wiki/Soft_set particular cases of soft sets - Zadeh's fuzzy and Pawlak's rough sets. It wil be nice to have implementation of soft sets in R.
Some references:
http://www.hindawi.com/journals/afs/2009/586507.html
https://www.sciencedirect.com/science/article/pii/S0898122199000565
https://core.ac.uk/download/pdf/82179651.pdf
On construction of a set, all R atomics (integer, character, etc.) are checked for uniqueness and duplicates are deleted. However this is not done for R6 classes, which would all require their own unique
method. This may be useful to check for duplicated SetInterval
s which all have an equals
method.
These would mutate the class and would look something like
$add = function(x) {
if(x %nin% self$elements)
private$.elements = c(private$.elements, x)
}
$remove = function(x) {
if(x %in% self$elements)
private$.elements = private$.elements[private$.elements %nin% x]
}
subject to object specific properties (ordering, multiset,...)
Need to add:
contains
isSubset
The cardinality of UnionSet is currently calculated as
|A| + |B|
for two sets A,B. It should be
|A| + |B| - |A and B|
This is a frustration that isn't really required but seems an R6 side effect. By removing the colons and importing the functions in .ZZZ
this will clear the note which is causing not ok
Version: 0.1.0
Check: dependencies in R code
Result: NOTE
Namespace in Imports field not imported from: ‘R6’
All declared Imports should be used.
Original decision was to use S3 dispatch, which allows returning of objects inheriting from any Sets object, which is very useful. However we could treat algebra of sets as wrappers, similar to distr6, so we store wrapped sets, which makes comparisons and containedness checks easy. See ProductSet
for an example of the wrapper variant and union
for S3
Currently powerset
and complement
are defined as methods and power
is a function. However, this seems inconsistent. There is an argument to define all of these as functions as whilst each could return an object inheriting from Set
, they could also return a SetWrapper
.
On the other hand, powerset
and complement
only require knowledge of the object they are acting on, whilst power
requires an additional argument (not a formal separation of function/method) so we could keep these how they are.
To each of Set, Tuple, FuzzySet, FuzzyTuple
add an argument called class
, if supplied (non-NULL) then the elements in the set must adhere to the given class. Otherwise anything possible. This will form part of validation checks in #36
I am reviewing https://github.com/openjournals/joss-reviews/ #2598 and I am unable to reproduce the first example in the paper
> library(set6)
-----------------------------
set6 v0.1.8
Get started: ?set6
Changelog: set6News()
-----------------------------
> a <- Set$new(1,2,3)
> a
{1, 2, 3}
> a$contains(1)
[1] TRUE
> a$contains(pi)
[1] FALSE
> a$contains(1, pi, "a")
[1] TRUE
> a$contains(1, "a")
Error in if (all) { : argument is not interpretable as logical
Have I misunderstood the example? (My R programming is a bit rusty so my apologies if I misunderstood)
If it matters this is on Ubuntu 20.04 with
Package: r-base-core
Version: 4.0.2-1.2004.0
Add short tutorials to website
Reasons for:
Reasons against:
ConditionalSet
inconsistent with documentationUnless anyone knows how to add packages to latex conversion for roxygen?
Reasons against doing this:
Union of a set
and interval
Reasons for doing this:
It can be argued that an interval
is an infinite set
and thus the union of both is itself a set
Add the SpecialSet UniversalSet
which contains everything. Therefore:
V = UniversalSet$new()
V$contains(x) == TRUE, \forall x
V$isSubset(s) == TRUE, \forall `Set`s s
V$equals(s) == FALSE, if s != V
V$equals(s) == TRUE, if s == V
I think the symbol V
should be used to avoid confusion with U
or \cup
.
lower
= upper
= NaN
Properties: not empty, not singleton, open, cardinality is...unclear.
Algebra of sets, for any set s
, empty 0
, constant n
, and universal V
:
s - V = 0
s %-% V = 0
s + V = V
s & V = s
P(V) = V
V^n = V
s * V = ProductSet(s, V)
There is a significant bottleneck in the constructor for Set
. It occurs in lines 67-73 where there is a lapply
to get the class of each element.
It also makes sense to remove any mention of the class
field in the Set
constructor as this really isn't a requirement.
Should algebra of sets be implemented via S3 dispatch, which seems more natural for creating a new set from two more or as an R6 method.
x <- Set$new(1,2,3)
y <- Set$new(3,4,5)
Then either
x$union(y)
or
union(x, y)
The latter seems more natural. But what about something like
x$complement()
or
complement(x)
e.g. we have equals
to compare if two sets are identical but isSubset
to test if one is a subset of the other and liesInSetInterval
to test if a value is contained in a SetInterval
The R convention seems to be to prefix with is
when testing the property of a given element, e.g.is.numeric, is.logical
but not to have is
when comparing two values, e.g. identical, unique, duplicated
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.