r"""Add hyperedges to the hypergraph. If the ``group_name`` is not specified, the hyperedges will be added to the default ``main`` hyperedge group. Args: ``num_v`` (``int``): The number of vertices in the hypergraph. ``e_list_v2e`` (``Union[List[int], List[List[int]]
(
self,
e_list_v2e: Union[List[int], List[List[int]]],
e_list_e2v: Union[List[int], List[List[int]]],
w_list_v2e: Optional[Union[List[float], List[List[float]]]] = None,
w_list_e2v: Optional[Union[List[float], List[List[float]]]] = None,
e_weight: Optional[Union[float, List[float]]] = None,
merge_op: str = "mean",
group_name: str = "main",
)
| 308 | |
| 309 | # some structure modification functions |
| 310 | def add_hyperedges( |
| 311 | self, |
| 312 | e_list_v2e: Union[List[int], List[List[int]]], |
| 313 | e_list_e2v: Union[List[int], List[List[int]]], |
| 314 | w_list_v2e: Optional[Union[List[float], List[List[float]]]] = None, |
| 315 | w_list_e2v: Optional[Union[List[float], List[List[float]]]] = None, |
| 316 | e_weight: Optional[Union[float, List[float]]] = None, |
| 317 | merge_op: str = "mean", |
| 318 | group_name: str = "main", |
| 319 | ): |
| 320 | r"""Add hyperedges to the hypergraph. If the ``group_name`` is not specified, the hyperedges will be added to the default ``main`` hyperedge group. |
| 321 | |
| 322 | Args: |
| 323 | ``num_v`` (``int``): The number of vertices in the hypergraph. |
| 324 | ``e_list_v2e`` (``Union[List[int], List[List[int]]]``): A list of hyperedges describes how the vertices point to the hyperedges. |
| 325 | ``e_list_e2v`` (``Union[List[int], List[List[int]]]``): A list of hyperedges describes how the hyperedges point to the vertices. |
| 326 | ``w_list_v2e`` (``Union[List[float], List[List[float]]]``, optional): The weights are attached to the connections from vertices to hyperedges, which has the same shape |
| 327 | as ``e_list_v2e``. If set to ``None``, the value ``1`` is used for all connections. Defaults to ``None``. |
| 328 | ``w_list_e2v`` (``Union[List[float], List[List[float]]]``, optional): The weights are attached to the connections from the hyperedges to the vertices, which has the |
| 329 | same shape to ``e_list_e2v``. If set to ``None``, the value ``1`` is used for all connections. Defaults to ``None``. |
| 330 | ``e_weight`` (``Union[float, List[float]]``, optional): A list of weights for hyperedges. If set to ``None``, the value ``1`` is used for all hyperedges. Defaults to ``None``. |
| 331 | ``merge_op`` (``str``): The merge operation for the conflicting hyperedges. The possible values are ``mean``, ``sum``, ``max``, and ``min``. Defaults to ``mean``. |
| 332 | ``group_name`` (``str``, optional): The target hyperedge group to add these hyperedges. Defaults to the ``main`` hyperedge group. |
| 333 | """ |
| 334 | e_list_v2e, w_list_v2e = self._format_e_list_and_w_on_them( |
| 335 | e_list_v2e, w_list_v2e |
| 336 | ) |
| 337 | e_list_e2v, w_list_e2v = self._format_e_list_and_w_on_them( |
| 338 | e_list_e2v, w_list_e2v |
| 339 | ) |
| 340 | if e_weight is None: |
| 341 | e_weight = [1.0] * len(e_list_v2e) |
| 342 | assert len(e_list_v2e) == len( |
| 343 | e_weight |
| 344 | ), "The number of hyperedges and the number of weights are not equal." |
| 345 | assert len(e_list_v2e) == len( |
| 346 | e_list_e2v |
| 347 | ), "Hyperedges of 'v2e' and 'e2v' must have the same size." |
| 348 | for _idx in range(len(e_list_v2e)): |
| 349 | self._add_hyperedge( |
| 350 | self._hyperedge_code(e_list_v2e[_idx], e_list_e2v[_idx]), |
| 351 | { |
| 352 | "w_v2e": w_list_v2e[_idx], |
| 353 | "w_e2v": w_list_e2v[_idx], |
| 354 | "w_e": e_weight[_idx], |
| 355 | }, |
| 356 | merge_op, |
| 357 | group_name, |
| 358 | ) |
| 359 | self._clear_cache(group_name) |
| 360 | |
| 361 | def _add_hyperedge( |
| 362 | self, |