New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binomial Random Uniform Hypergraph #21917
Comments
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Author: Peleg Michaeli |
Changed keywords from hypergraph, random to hypergraph, random, days79 |
comment:6
Here are some comments:
and the one with
|
comment:7
Hello, I do not understand what you are doing with the Vincent |
comment:8
This is very inefficient if p is small
You need to use another approach... The cardinality of your "edge space" is binomial(n,k). What you want to do is basically pick a binomial random variable B(binomial(n,k), p) and then pick that number of sets. This can be done as follows
Hence you just need to generate a random number distributed with binomial distribution. |
comment:9
And for generating binomial distribution there is at least
|
comment:10
Replying to @videlec:
This is probably right. I do want to get |
comment:11
sage: n = 10000
sage: p = 1/n
sage: k = 17
sage: sample(Subsets(range(n), k), binomial(n, p))
Traceback (most recent call last):
File "<ipython-input-57-6d20b3bde428>", line 1, in <module>
sample(Subsets(range(n), k), binomial(n, p))
File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/misc/prandom.py", line 178, in sample
return _pyrand().sample(population, k)
File "/usr/lib/sagemath/local/lib/python/random.py", line 321, in sample
n = len(population)
OverflowError: Python int too large to convert to C long I am also quite worried about the fact that (this was tested in Sage 7.3... until I'll build 7.5beta3 properly) |
comment:12
I think the maximum number of edges in the complete uniform hypergraph that this can handle via the proposed method is roughly |
comment:13
Replying to @pelegm:
I confirm the behavior on the latest beta (7.5.beta4). I don't think the conversion to float by numpy matters. On the other hand, as we discussed in Jerusalem it would actually be simpler to have two methods:
|
comment:14
I'm also in favor of having GNM and GNP like methods. In above example, you use Obviously, the main limitation for the maximum size of a random uniform hypergraph is not what David. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:16
Rebased to |
comment:17
OK, so this is my plan for the uniform model: if m < 0:
raise ValueError("Number of edges must be nonnegative.")
from sage.combinat.subset import Subsets
all_edges = Subsets(n, k)
max_points = len(all_edges)
if m > max_points:
raise ValueError("Number of edges may not exceed {}".format(
max_points))
from sage.misc.prandom import sample
try:
edges = sample(all_edges, m)
except OverflowError:
from sys import maxint
from sage.functions.other import binomial
if binomial(n, k) > maxint:
raise OverflowError("binomial(n, k) may not exceed {}".format(
maxint))
raise
from sage.combinat.designs.incidence_structures import IncidenceStructure
return IncidenceStructure(edges) Now, for the binomial model, which function do you think I should use?
|
comment:18
You have only 1 call, so this should be sufficient
|
comment:19
Replying to @dcoudert:
This will not yield the current distribution. |
comment:20
Replying to @pelegm:
I would actually regroup and simplify the errors (and please in the error message start with lower case and no ponctuation at the end) from sage.combinat.subset import Subsets
from sage.misc.prandom import sample
all_edges = Subsets(n, k)
try:
edges = sample(all_edges, m)
except OverflowError:
raise OverflowError("binomial({},{}) too large to be treated".format(n,k))
except ValueError:
raise ValueError("number of edges m must between 0 and binomial({},{})".format(n,k))
from sage.combinat.designs.incidence_structures import IncidenceStructure
return IncidenceStructure(edges) I don't think that the overflow in
|
comment:21
Great, thanks. In the meanwhile I implement the binomial random hypergraph using NumPy's |
comment:22
Replying to @pelegm:
I am good with it! |
comment:23
Replying to @videlec:
The problem by this implementation is that it creates a hypergraph without the isolated vertices. This is easy to fix, I'm on it. |
Changed keywords from hypergraph, random, days79 to hypergraph, random, days79, days94 |
New commits:
|
Changed branch from u/pelegm/randombinomialhypergraph to u/pelegm/21917 |
comment:26
I avoided using seed since randomness is currently using numpy's, and working with two random states seems wrong. Wasn't sure what other tests I should add. |
comment:28
in method, The What if |
comment:30
Replying to @dcoudert:
Thanks, will fix.
Indeed, for large inputs there's some weird issue in numpy I can't really understand at the moment:
Ok.
Will do. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:33
Shouldn't we put an empty line after Once done (or not done if not necessary), you can set this ticket to positive review for me. |
Reviewer: David Coudert |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:35
Thanks! |
Changed branch from u/pelegm/21917 to |
I have implemented binomial random hypergraph. This is my first time writing code in sage, and I would appreciate any feedback.
Component: graph theory
Keywords: hypergraph, random, days79, days94
Author: Peleg Michaeli
Branch/Commit:
5a7b76a
Reviewer: David Coudert
Issue created by migration from https://trac.sagemath.org/ticket/21917
The text was updated successfully, but these errors were encountered: