Skip to content

Commit

Permalink
create data generators
Browse files Browse the repository at this point in the history
  • Loading branch information
bda82 committed Oct 23, 2023
1 parent 7bcd081 commit e4be33f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
39 changes: 39 additions & 0 deletions stable_gnn/visualization/data_generation/graph_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import random

from stable_gnn.visualization.exceptions.exceptions_classes import ParamsValidationException


class GraphGenerator:

def __init__(self, vertex_num: int, edge_num: int):
self.vertex_num = vertex_num
self.edge_num = edge_num

self._validate()

def __call__(self):
vertex_list = list(range(self.vertex_num))
current_edge_num, edge_set = 0, set()

while current_edge_num < self.edge_num:
v = random.choice(vertex_list)
w = random.choice(vertex_list)

if v > w:
v, w = w, v

if v == w or (v, w) in edge_set:
continue

edge_set.add((v, w))

current_edge_num += 1

return list(edge_set)

def _validate(self):
vertex_num_gt_1 = self.vertex_num > 1
numbers_are_proportional = self.edge_num < self.vertex_num * (self.vertex_num - 1) // 2

if not vertex_num_gt_1 or not numbers_are_proportional:
raise ParamsValidationException
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __init__(self,
self.method = generation_method
self.probability_k_list = probability_k_list

self._validate()

def __generate_uniform(self, edge_degree_list: list):
return [c_log_function(self.vertex_num, k) / (2 ** self.vertex_num - 1) for k in edge_degree_list]

Expand Down
7 changes: 7 additions & 0 deletions stable_gnn/visualization/examples/generate_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from stable_gnn.visualization.data_generation.graph_generator import GraphGenerator


generator = GraphGenerator(vertex_num=4,
edge_num=5)
data = generator()
print(data)

0 comments on commit e4be33f

Please sign in to comment.