コード例 #1
0
ファイル: mtgcompare.py プロジェクト: gkoehl/lpy
def getpropforsubtree(mtg,root,initialmtg,initialroot,matched,rebuildclasses = 'WZ'):
     nbelements1 = len(list(algo.descendants(mtg,root)))
     nbelements2 = len(list(algo.descendants(initialmtg,initialroot)))
     nbmatched = len(matched)
     return 2*nbmatched/float(nbelements1+nbelements2)
     nbtotelem = nbelements1+nbelements2-nbmatched
     print root,nbmatched,nbelements1,nbelements2,nbmatched/float(nbtotelem)
     return nbmatched/float(nbtotelem)
コード例 #2
0
def getpropforsubtree(mtg,
                      root,
                      initialmtg,
                      initialroot,
                      matched,
                      rebuildclasses='WZ'):
    nbelements1 = len(list(algo.descendants(mtg, root)))
    nbelements2 = len(list(algo.descendants(initialmtg, initialroot)))
    nbmatched = len(matched)
    return 2 * nbmatched / float(nbelements1 + nbelements2)
    nbtotelem = nbelements1 + nbelements2 - nbmatched
    print root, nbmatched, nbelements1, nbelements2, nbmatched / float(
        nbtotelem)
    return nbmatched / float(nbtotelem)
コード例 #3
0
def mtg2treegraph(mtg, scale=1, root=None):
    """ Return conversion of mtg into a TreeGraph structure of tree_matching.
    And corespondence map betwee, id of mtg and id of tree graph """
    tree = TreeGraph()

    if root is None:
        # take first root of mtg at the given scale
        root = mtg.components_at_scale_iter(mtg.root, scale=scale).next()

    if mtg.scale(root) != scale:
        root = mtg.components_at_scale_iter(root, scale=scale).next()

    tree.addNode(0, -1)
    idmap = {root: 0}
    id = 1

    for n in descendants(mtg, root):
        if n == root:
            continue
        fid = mtg.parent(n)
        if fid:
            fid = idmap[fid]
        else:
            fid = -1
        tree.addNode(id, fid)
        idmap[n] = id
        id += 1

    return tree, idmap
コード例 #4
0
def mtg2treegraph(mtg,scale = 1, root = None):
    """ Return conversion of mtg into a TreeGraph structure of tree_matching.
    And corespondence map betwee, id of mtg and id of tree graph """
    tree = TreeGraph()
    
    if root is None: 
        # take first root of mtg at the given scale
        root = mtg.components_at_scale_iter(mtg.root,scale=scale).next()
    
    if mtg.scale(root) != scale:
        root = mtg.components_at_scale_iter(root,scale=scale).next() 
    
    tree.addNode(0,-1)
    idmap = { root : 0 }
    id = 1
    
    for n in descendants(mtg,root):
        if n == root: continue
        fid = mtg.parent(n)
        if fid : fid = idmap[fid]
        else: fid = -1
        tree.addNode(id,fid)
        idmap[n] = id
        id += 1
    
    return tree, idmap
コード例 #5
0
ファイル: aml.py プロジェクト: BeGIMATH/mtg
def Descendants(v,
                EdgeType='*',
                RestrictedTo='NoRestriction',
                ContainedIn=None):
    """
    Set of vertices in the branching system borne by a vertex.

    This function returns the set of descendants of its argument as an array of vertices.
    The array thus consists of all the vertices, at the same scale as `v`,
    that belong to the branching system starting at `v`.
    The order of the vertices in the array is not significant.

    .. note:: The argument always belongs to the set of its descendants.

    :Usage:

    .. code-block:: python

        Descendants(v)

    :Parameters:

        - v (int) : vertex of the active MTG

    :Optional Parameters:

        - RestrictedTo (str): cf. `Father`
        - ContainedIn (int): cf. `Father`
        - EdgeType (str): cf. `Father`

    :Returns:

        list of int.


    :Examples:

    .. code-block:: python

        >>> v
        78
        >>> Sons(v) # set of sons of v
        [78,99,101]
        >>> Descendants(v) # set of descendants of v
        [78,99,101,121,133,135,156,171,190]

    .. image:: ../user/mtg_descendants.png

    .. seealso:: :func:`MTG`, :func:`Ancestors`.
    """
    global _g
    return list(
        algo.descendants(_g,
                         v,
                         RestrictedTo=RestrictedTo,
                         ContainedIn=ContainedIn))
コード例 #6
0
ファイル: aml.py プロジェクト: imane-aanna/mtg-1
def Descendants(v, EdgeType='*', RestrictedTo='NoRestriction', ContainedIn=None):
    """
    Set of vertices in the branching system borne by a vertex.

    This function returns the set of descendants of its argument as an array of vertices.
    The array thus consists of all the vertices, at the same scale as `v`,
    that belong to the branching system starting at `v`.
    The order of the vertices in the array is not significant.

    .. note:: The argument always belongs to the set of its descendants.

    :Usage:

    .. code-block:: python

        Descendants(v)

    :Parameters:

        - v (int) : vertex of the active MTG

    :Optional Parameters:

        - RestrictedTo (str): cf. `Father`
        - ContainedIn (int): cf. `Father`
        - EdgeType (str): cf. `Father`

    :Returns:

        list of int.


    :Examples:

    .. code-block:: python

        >>> v
        78
        >>> Sons(v) # set of sons of v
        [78,99,101]
        >>> Descendants(v) # set of descendants of v
        [78,99,101,121,133,135,156,171,190]

    .. image:: ../user/mtg_descendants.png

    .. seealso:: :func:`MTG`, :func:`Ancestors`.
    """
    global _g
    return list(algo.descendants(_g, v,
                                 RestrictedTo=RestrictedTo,
                                 ContainedIn=ContainedIn))