Example #1
0
def MM_dimension(DAG, k, out):


    
    DAG_TC = tr.trans_comp(DAG) #Generates the transitive completion of the DAG
    number_nodes = DAG_TC.number_of_nodes() #counts the number of nodes
    
    if k == 2:
        number_chains = DAG_TC.number_of_edges() #the number of two chains in a DAG is the same as the number of edges in its transitive completion
        
    if k==3:
        number_chains = len(three_chain(DAG_TC)) #uses the 'three chain' function to create the list of 3 chains in the DAG
    
    ratio = (float(number_chains))/((float(number_nodes)**2)) #calculates S_{k}/N^{2}, which can be related to the dimension
    
    dimension_function = open('C:\Users\Jamie\Project\gamma.txt', 'r') #input values of the f(dimension) for a range of dimension values
    
    min_diff = 1000
    d_closest = 0
    
    for line in dimension_function:
        values = line.split()
        d = values[0]
        f_d = values[1]
        diff = abs(f_d - ratio)
        if diff < min_diff:
            min_diff = diff
            d_closest = d
            
    out.write('\n' + 'The dimension is %f' %d_closest)
Example #2
0
def MM_dimension(DAG, k=2):
    
    DAG_TC = tr.trans_comp(DAG) #Generates the transitive completion of the DAG
    #DAG_TC = DAG #here, as a box DAG = the transitive completion of a box DAG
    number_nodes = DAG_TC.number_of_nodes() #counts the number of nodes
    
    if k == 2:
        number_chains = DAG_TC.number_of_edges() #the number of two chains in a DAG is the same as the number of edges in its transitive completion
        
    if k == 3:
        chains = three_chain(DAG_TC)
        number_chains = len(chains)
    if k == 4:
        chains = four_chain(three_chain(DAG_TC), DAG_TC)
        number_chains = len(chains)
    if k == 5:
        chains = five_chain(four_chain(three_chain(DAG_TC), DAG_TC), DAG_TC)
        number_chains = len(chains)
    ratio = float(number_chains)/((float(number_nodes)**k)) #calculates S_{k}/N^{k}, which can be related to the dimension
    #ratio = log(number_chains) - k*log(number_nodes)
    
    dimension_data = './f_of_d_%d.txt' %k #Finds the f(d) values for the appropriate value of the chain length
    
    data = open(dimension_data, 'r')
    min_diff = 1000
    d_closest = 0
    
    for line in data:
        values = line.split()
        d = float(values[0])
        f_d = float(values[1])
        diff = abs(f_d - ratio)
        if diff < min_diff:
            min_diff = diff
            d_closest = d
            
    return d_closest #returns a single float value, indicating the dimension of the DAG