コード例 #1
0
def calculate_flux(mm, topic_labels, A=[8], B=[2, 13]):
    #A=[8],B=[2,13],
    # Calculate the flux between two states camp arrival and camp liquidiation / camp transfer )

    tpt = msm.tpt(mm, A, B)

    nCut = 1
    (bestpaths, bestpathfluxes) = tpt.pathways(fraction=0.7)
    cumflux = 0

    # Print the best path between the two states

    print("Path flux\t\t%path\t%of total\tpath")

    topic_sequences = {}
    for i in range(len(bestpaths)):
        cumflux += bestpathfluxes[i]
        flux = 100.0 * bestpathfluxes[i] / tpt.total_flux
        if flux > 0:
            #print(bestpathfluxes[i],'\t','%3.1f'%(100.0*bestpathfluxes[i]/tpt.total_flux),'%\t','%3.1f'%(100.0*cumflux/tpt.total_flux),'%\t\t',bestpaths[i])

            topic_sequence = []
            for element in bestpaths[i]:
                #print (topic_labels[element])
                topic_sequence.append(topic_labels[element])
            topic_sequence = '-'.join(topic_sequence)
            topic_sequences[
                topic_sequence] = 100.0 * bestpathfluxes[i] / tpt.total_flux

    return topic_sequences
        if i == 12:
            break

    # Print the eigenvalues of states
    '''for element in mm.eigenvalues().argsort()[::-1]:
        print (topic_list[element])
    '''

    # Calculate the flux between two states (topic_2, selection and topic_8_14 camp liquidiation / camp transfer )

    A = [8]
    B = [2, 13]
    tpt = msm.tpt(mm, A, B)

    nCut = 1
    (bestpaths, bestpathfluxes) = tpt.pathways(fraction=0.5)
    cumflux = 0

    # Print the best path between the two states

    print("Path flux\t\t%path\t%of total\tpath")

    for i in range(len(bestpaths)):
        cumflux += bestpathfluxes[i]

        print(bestpathfluxes[i], '\t',
              '%3.1f' % (100.0 * bestpathfluxes[i] / tpt.total_flux), '%\t',
              '%3.1f' % (100.0 * cumflux / tpt.total_flux), '%\t\t',
              bestpaths[i])

        topic_sequence = []