Beispiel #1
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)
Beispiel #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)
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
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
Beispiel #5
0
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))
Beispiel #6
0
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))