This is a Directed Acyclic Graph Tutorial

This is a sample for

Importing nedded dependencies

At first we import all needed dependencies

In [2]:
%matplotlib inline

import numpy as np
import random
import networkx as nx
import matplotlib.pyplot as plt
from nxpd import draw
from nxpd import nxpdParams
import copy

nxpdParams['show'] = 'ipynb'

Generating DAG

This section generates the DAG

In [3]:
def generateDAG(nodeNo, edgeProb):
    adj = np.zeros((nodeNo, nodeNo))
    deps = dict()
    nodeLables = list(range(nodeNo))
    addedLabels = list()
    for i in range(nodeNo):
        lIdx = random.randrange(len(nodeLables))
        lable = nodeLables[lIdx]
        deps[str(addedLabels[i])] = set()
        for j in range(i):
            rnd = random.random()
            if  rnd < edgeProb and i != j:
                G.add_edge(str(addedLabels[j]), str(addedLabels[i]))
                adj[i,j]= 1
    return (adj, G, deps)

Generate and Draw the DAG

In this section we just generate and draw DAG

In [5]:
nodeCount = 10
dependencyProbability= 0.7
dag, G, deps = generateDAG(nodeCount,dependencyProbability)

It is easy to generate and draw a DAG in jupyter notebook