Giter Club home page Giter Club logo

set6's People

Contributors

raphaels1 avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bcjaeger

set6's Issues

Algebra of sets as S3 or R6

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)

Understanding products and powers

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?

subsets of intervals

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?

Active Bindings or Public Methods

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

Set operation names and masking

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)

wrappers or dispatch for algebra of sets

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

Consider adding `add` and `remove` set methods

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,...)

FuzzySet operators error

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

Should `SetInterval` be an abstract class?

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

Consider change of U+03B5 in `ConditionalSet` to U+2208

Reasons for:

  • There is a dedicated unicode symbol so it makes sense to do so

Reasons against:

  • U+2208 (element of) cannot be printed in roxygen but U+03B5 (epsilon) can be, therefore changing this would make notation in ConditionalSet inconsistent with documentation

Unless anyone knows how to add packages to latex conversion for roxygen?

Unable to reproduce example in JOSS paper

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`typed`set property

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

JOSS review questions

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.

Change R6::R6 and R6::R6Class to R6 and R6Class

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.

powerset/complement/power as method or function

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.

Naming inconsistency in comparison methods

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

Fix inheritance of SpecialSets

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.

See openjournals/joss-reviews#2598

list or ... for `liesInSet` methods

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)

Sets only check atomic uniqueness

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 SetIntervals which all have an equals method.

Optimize performance of base operations

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.

Add simplify method for wrappers

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)

Fix Set$new() bottleneck

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.

Add UniversalSet

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.