Skip to content
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

RandomHypergraph #510

Closed
daneelsan opened this issue Nov 2, 2020 · 2 comments · Fixed by #511
Closed

RandomHypergraph #510

daneelsan opened this issue Nov 2, 2020 · 2 comments · Fixed by #511
Assignees
Labels
feature New functionality, or change in existing functionality wolfram language Requires Wolfram Language implementation

Comments

@daneelsan
Copy link
Collaborator

The problem

Implement the RandomHypergraph function.

Possible solution

A possible implementation and API is found in the WFR:

RandomHypergraph[{n_Integer, {e_Integer, a_Integer}}] := 
 RandomInteger[{1, n}, {e, a}]

RandomHypergraph[{n_Integer, sig : {{_Integer, _Integer} ..}}] := 
 Catenate[RandomInteger[{1, n}, #] & /@ sig]

image

In[]:= RandomHypergraph[{10, {5, 2}}]
Out[]= {{5, 4}, {7, 8}, {7, 6}, {7, 1}, {4, 9}}
In[]:= RandomHypergraph[{10, {{5, 2}, {4, 3}}}]
Out[]= {{1, 2}, {2, 9}, {6, 1}, {3, 3}, {10, 10}, {1, 8, 8}, {5, 7, 9}, {5, 
  7, 6}, {5, 3, 3}}
@daneelsan daneelsan added feature New functionality, or change in existing functionality wolfram language Requires Wolfram Language implementation labels Nov 2, 2020
@daneelsan daneelsan self-assigned this Nov 2, 2020
@maxitg
Copy link
Owner

maxitg commented Nov 2, 2020

I think another useful API would be just specifying the total number of hyperedge parts (essentially, the "complexity").

E.g., for {{1, 2, 3}, {3, 4}, {4, 5, 6}}, this number will be 8.

This way, one can generate any possible hypergraph by varying just one parameter. This will be even more useful for enumeration.

@maxitg
Copy link
Owner

maxitg commented Nov 4, 2020

It might also be useful to generate connected hypergraphs (maybe with an option).

daneelsan added a commit that referenced this issue Nov 9, 2020
## Changes
* Close #510.
* Implements `RandomHypergraph` function.

## Comments
* Missing option `"Connected" -> True` to specifically generate random connected hypergraphs.

## Examples

```wl
In[] := SeedRandom[2]; RandomHypergraph[8]
Out[] = {{2, 3}, {8}, {1, 6}, {7, 7}, {1}}

In[] := RandomHypergraph[8, 10]
Out[] = {{3, 7, 7}, {1, 7}, {10, 2, 6}}

In[] := RandomHypergraph[{5, 2}]
Out[] = {{5, 1}, {10, 7}, {9, 3}, {3, 2}, {4, 6}}

In[] := RandomHypergraph[{{5, 2}, {4, 3}}, 2]
Out[] = {{1, 1}, {1, 1}, {2, 2}, {1, 1}, {1, 2}, {1, 2, 2}, {1, 1, 2}, {1, 2, 2}, {2, 1, 1}}
```

```wl
In[]:= SeedRandom[111];
Grid[Partition[
  Table[Labeled[WolframModelPlot@#, # -> i] &[
    RandomHypergraph[i]], {i, 1, 12}], 3, 3, 1], Frame -> All]
```
![image](https://user-images.githubusercontent.com/40190339/98330685-e886ca00-1fc8-11eb-92ab-1aca157be21c.png)

## Documentation

![image](https://user-images.githubusercontent.com/40190339/98401650-05a4b280-2034-11eb-9ae3-fd2b14f17c46.png)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/maxitg/setreplace/511)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality, or change in existing functionality wolfram language Requires Wolfram Language implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants