<jupyter_start><jupyter_text>This is a Directed Acyclic Graph TutorialThis is a sample for http://blog.abyz.ir  Importing nedded dependenciesAt first we import all needed dependencies<jupyter_code>%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'<jupyter_output><empty_output><jupyter_text>Generating DAGThis section generates the DAG<jupyter_code>def generateDAG(nodeNo, edgeProb):
    adj = np.zeros((nodeNo, nodeNo))
    G=nx.DiGraph()
    deps = dict()
    nodeLables = list(range(nodeNo))
    addedLabels = list()
    
    for i in range(nodeNo):
        lIdx = random.randrange(len(nodeLables))
        lable = nodeLables[lIdx]
        addedLabels.append(lable)
        nodeLables.remove(lable)
        
        G.add_node(str(addedLabels[i]))
        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]))
                deps[str(addedLabels[i])].add(str(addedLabels[j]))
                adj[i,j]= 1
    return (adj, G, deps)<jupyter_output><empty_output><jupyter_text>Generate and Draw the DAGIn this section we just generate and draw DAG<jupyter_code>nodeCount = 10
dependencyProbability= 0.7
dag, G, deps = generateDAG(nodeCount,dependencyProbability)
draw(G)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10326449033977349, 'fraction_numerical': 0.0033311125916055963, 'mean_word_length': 3.6791277258566977, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '276906', 'license': 'MIT', 'n_tokens_mistral': 515, 'n_tokens_neox': 503, 'n_words': 119, 'path': 'DagTutorial.ipynb', 'repo_name': 'yazdan/myNotebooks', 'size': '1501'}