Metadata-Version: 2.4
Name: netdecom
Version: 0.0.5.6
Summary: Dimensionality Reduction and Decomposition of Undirected Graph Models and Bayesian Networks
Author: Hugh
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: summary


# netdecom Documentation

## Overview
netdecom is a Python package for advanced graph analysis, providing algorithms for minimal collapsible set extraction and recursive decomposition for both undirected graphs (UGs) and directed acyclic graphs (DAGs). It combines a compiled core extension with igraph and networkx utilities.

## Installation

```pycon
>>> pip install netdecom
```

## Core Functionalities

### 1. Minimal collapsible set Identification in Undirected Graphs
Finds the minimal collapsible set containing a given node set R:

```pycon
>>> import netdecom as nd
>>> import igraph as ig
>>> G = ig.Graph([(0, 1), (1, 2), (2, 3)])
>>> nd.get_minimal_collapsible(G, [1, 3])
```

### 2. Atom Decomposition
Decomposes graphs into atoms using MCS ordering:

```pycon
>>> nd.decompose_atoms(G)
```

### 3. Minimal collapsible set Identification in Directed Acyclic Graphs
Finds the minimal collapsible set containing a given node set R:

```pycon
>>> import igraph as ig
>>> G = ig.Graph([(0, 1), (1, 2), (2, 3)], directed=True)
>>> nd.dag_get_minimal_collapsible(G, [1, 3])  # Close Minimal D-Separator Absorbing Algorithm
>>> nd.dag_get_ancestors(G, [1, 3])
```

### 4. Random Graph Generation

```pycon
>>> ug = nd.generator_connected_ug(n,p,class_type="ig")  # generates a random connected graph with n nodes and edge probability p; returns an igraph graph by default or a NetworkX graph if class_type="nx".
>>> dag = nd.generate_connected_dag(n, p, max_parents=3)  # Generate a connected Directed Acyclic Graph (DAG) with n nodes, edge probability p, and maximum 3 parents per node.
>>> dag = nd.random_connected_dag(n, p)  # Generate a random Directed Acyclic Graph (DAG) with n nodes and edge probability p.
```

### 5. Load Example Graphs

#### `get_example(file_name, class_type="ig")`
Reads the specified example file from the library and returns the corresponding undirected graph object (either `NetworkX` or `igraph`):

#### Parameters:
- `file_name` (str): The name of the example file to be read. The following example files are available:
- `class_type` (str): Graph backend type. Use `"ig"` for `igraph.Graph` (default) or `"nx"` for `networkx.Graph`.

| File Name                                     | Nodes | Edges   | Connected Components | Largest Component Size |
|-----------------------------------------------|-------|---------|----------------------|------------------------|
| Animal-Network.txt                            | 445   | 1332    | 22                   | 117                    |
| bio-CE-GT.txt                                 | 924   | 3239    | 13                   | 878                    |
| as20000102.txt                                | 6474  | 12572   | 1                    | 6474                   |
| DD6.txt                      | 4152           | 10320 | 1                              | 4152                   |
| CA-HepTh.txt                                  | 9875  | 25973   | 427                  | 8638                   |
| com-youtube.ungraph.txt      | 1134890        | 2987624| 1                              | 1134890                  |



#### Returns:
- Returns `igraph.Graph` when `class_type="ig"` (default), or `networkx.Graph` when `class_type="nx"`.

#### Example:

```pycon
>>> G = nd.get_example("Animal-Network.txt", class_type="nx")  # Reads the example file and returns a NetworkX graph.
>>> G = nd.get_example("Animal-Network.txt", class_type="ig")  # Reads the example file and returns an igraph graph.
```

## Notes
- `get_minimal_collapsible`, `decompose_atoms`, `dag_get_minimal_collapsible`, and `dag_get_ancestors` are provided by the compiled extension module (`netdecom.decom_h`) and are intended to work with igraph graph objects.
- `generator_connected_ug` can return either `igraph.Graph` or `networkx.Graph` based on `class_type`.
- `generate_connected_dag` and `random_connected_dag` return `networkx.DiGraph` objects.
